Jump to content

Puzzle Game with Images Help


paulmo

Recommended Posts

I'll attach a working script to this post.

 

In this program, tiles[] is an array with four numbers. The numbers are reordered when the user clicks on the image elements. The game logic is in the move() function, the presentation is in the display() function.

 

I copied the specifications of your current program, in your current program it's always tile 3 that gets moved when a user clicks on the puzzle so I kept it that way.

test.html

Link to comment
Share on other sites

  • Replies 61
  • Created
  • Last Reply

Top Posters In This Topic

Ignolme, thank you, this is great! It works with different sets of images in array. I willl study your functions, especially move and display. The annotations help. And cool Tails art.

Edited by paulmo
Link to comment
Share on other sites

How to delay the complete round (show complete puzzle for a couple seconds) before loading new round? Thanks.
// If the round is complete, load the next round                if(is_equal(tiles, solution)) {                    currentRound++;                    if(currentRound < images.length) {                        // Load the next round                       // alert("Next round!");                        selectRound(currentRound);
Link to comment
Share on other sites

Sorry I missed that setTimeout takes a function. Here is complete is_equal function, I'm trying is_equal as function in setTimeout:
if(is_equal(tiles, solution)) {                                        currentRound++;                                                      if(currentRound < images.length) {                        // Load the next round                       // alert("Next round!");                        selectRound(currentRound);                    } else {                        // The game has ended                        alert("Game over.");                    }                }            }//setTimeout                window.setTimeout(is_equal, 2000);
Edited by paulmo
Link to comment
Share on other sites

The error is because is_equal takes 2 parameters and you're not passing any parameters when you call it with setTimeout.I believe you're trying to do this:

if(is_equal(tiles, solution)) {                                        currentRound++;                                                      if(currentRound < images.length) {                        // Load the next round                       // alert("Next round!");                        setTimeout(function() { selectRound(currentRound); }, 2000);                    } else {                        // The game has ended                        alert("Game over.");                    }                }            }
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...