var numClicks = 0; // the number of times the player has clicked var currentImage; // the current image or window: image1 through image16 (or image0 through image15) var list = []; // this array has 16 numbers. Each position in 'list' corresponds to 1 of the 16 windows. The number // stored in each position indicates which of the 8 images displays in that window. For example, if list[0] is 4, // it indicates that window 1 will display fractal4.jpg when clicked on. (The fractal images I used are named // fractal1.jpg to fractal8.jpg.) var click1, click2; // these store the number of the window that the user clicked on, on their 1st and 2nd clicks var player; // name of current player var player1; // name of player 1 var player2; // name of player 2 var player1Score = 0; // score of player 1 var player2Score = 0; // score of player 2 // setUpPlayers() randomly chooses which player will go first. // It shows the green button next to that player. // TO DO: // - use randomNumber(0, 1) to generate a random integer. // - if the result is 0: // - set player1 to start the game // - hide the button next to player2 // - show the button next to player1 // - if the result is 1: // - do the opposite function setUpPlayers() { } // This onEvent runs when the 'Start Game' button is clicked on screen1. It puts the players' names into player1 and // player2. It sets the screen to screen2 and calls setUpScreen2(). // TO DO: // - use 'getText()' to store player 1's name from screen1 in 'player1' // - same for player 2 // - call setScreen() to show screen2 // - call setUpScreen2() onEvent("btnStart", "click", function( ) { }); // setUpScreen2() declares several variables and initializes 'list' to be empty. // It displays the players' names and initial 0 scores. It calls randomizeImages() [extra-credit]. // It calls setUpPlayers(). // Inside a loop that runs 16 times, it positions the 16 windows on the screen, sets their size // and assigns 'window.jpg' to each window. So here I use code to do these tasks, but they can also // be done manually by positioning and resizing each window in Design mode, and assigning the 'window' image // to each window. // TO DO: // - use 'setText()' to have player 1's name and score display on screen2. Same for player 2. // - call randomizeImages() // - call setUpPlayers() // - if you choose to set up the 16 windows on screen2 by using code: // - set up a loop that runs 16 times // - generate the name of a window, like this: currentImage = "image" + k; // - use modular division, dividing by 4, to help figure out the window's x position // - use 'setProperty()' to set the window's x position // - use division, dividing by 4, to help figure out the window's y position // - use 'setProperty()' to set the window's y position // - if you need to round a number 'quot' down to the nearest integer, you can do it like this: // - quot = Math.round(quot - 0.5); // - use 'setProperty()' to use the window image initially // - use 'setProperty()' to set the width and height of the window function setUpScreen2() { var k; // loop index var mod; // stores the result of modular division var quot; // stores the result of division var xSet = 75; // used to position the windows horizontally var ySet = 90; // used to position the windows vertically list = []; // clears the array 'list' } // updateImage() accepts as a parameter the number of the window that the player clicked on. It only continues if that // window is currently displaying a window (not a fractal image). If so, it accesses 'list' to see which fractal // displays in that window. It generates the name of the fractal image and uses 'setProperty()' to display the image in the window. // TO DO: // - get the name of the current window: currentImage = "image" + num; // - use an if statement and 'getProperty()' to see if the window is currently displaying the window // - if it is, continue. Pull the number of the fractal image ('imgNum') that should display in the window // - from 'list'. // - create the name of the fractal image: "fractal" + imgNum + ".jpg" // - use 'setProperty()' to display the fractal image in the window function updateImage(num) { } // check() accepts as a parmeter the number of the window // that the player clicked on. It increments 'numClicks'. // It assigns 'num' to either 'click1' or 'click2'. // If the player has now clicked twice, it checks if the // player has a match. It does this by seeing if list[click1] // is the same as list[click2]. If so, it increments the // current player's score, and updates the score display. // It then checks if the game is over. // If it is over, it sets the screen to "screen3" and also // figures out who won the game or if it was a tie. // It displays a congratulatory message on screen3. // If, on the other hand, the 2 images were not a match, // the function calls pause() to pause the game for a few // seconds. It also uses 'setProperty()' to restore the // 'window' image to both windows that were clicked on. // Still in the section for when the player has clicked 2X, // check() sets 'numClicks' to 0, switches the player to the // other player, and updates the score. // If this was the player's first click, check() does nothing // more. // TO DO: // - increment 'numClicks' // - generate the name of the window that the user just clicked on // - if 'numClicks' is 1, assign 'num' to 'click1' // - if 'numClicks' is 2, assign 'num' to 'click2' // - if numClicks == 2: // - check if the images match by seeing if list[click1] equals list[click2] // - if so, if player1 is the current player: // - increment player 1's score // - if player2 is the current player: // - increment player 2's score // - update the player's scores on screen2 // - in an if statement, check if the game is over // - if it is, figure out who won and assign the player's name to 'winner' // - if it is a tie, display that // - in either case, update 'lblSummary' on screen3 accordingly // - display screen3 // - if the 2 images do not match: // - call pause() to pause the game // - use 'setProperty()' to return both windows to display the 'window' instead of the fractal image // - set 'numClicks' to 0 // - switch the other player to be the current player // - update the green button to be 'on' for the now-current player // - if numClicks == 1: // - do nothing further function check(num) { var winner; } // These 16 onEvents cause updateImage() and check() // to be called when 1 of the 16 windows is clicked on. // These onEvents are complete. onEvent("image1", "click", function() { updateImage(1); check(1); }); onEvent("image2", "click", function() { updateImage(2); check(2); }); onEvent("image3", "click", function() { updateImage(3); check(3); }); onEvent("image4", "click", function() { updateImage(4); check(4); }); onEvent("image5", "click", function() { updateImage(5); check(5); }); onEvent("image6", "click", function() { updateImage(6); check(6); }); onEvent("image7", "click", function() { updateImage(7); check(7); }); onEvent("image8", "click", function() { updateImage(8); check(8); }); onEvent("image9", "click", function() { updateImage(9); check(9); }); onEvent("image10", "click", function() { updateImage(10); check(10); }); onEvent("image11", "click", function() { updateImage(11); check(11); }); onEvent("image12", "click", function() { updateImage(12); check(12); }); onEvent("image13", "click", function() { updateImage(13); check(13); }); onEvent("image14", "click", function() { updateImage(14); check(14); }); onEvent("image15", "click", function() { updateImage(15); check(15); }); onEvent("image16", "click", function() { updateImage(16); check(16); }); // pause() uses a for loop that runs many times to cause a // pause in the game. // TO DO: // - run a for loop many times to create a pause in the game // - do nothing inside the loop function pause() { } // this onEvent runs when the Play Again button on screen3 is clicked. // It sets the players' scores to 0, sets the screen to // screen2 and calls setUpScreen2(). // TO DO: // - set the players' scores to 0 // - set the screen to screen2 // - call setUpScreen2() onEvent("btnPlayAgain", "click", function() { }); // randomizeImages() is for the extra-credit option. It randomizes the 16 numbers stored in 'list' // so that every game is different. // TO DO: - set loop index 'num' to 1 - set up a loop that runs as long as the loop index 'num' < 17 - use randomNumber(a, b) to generate 'number' with a <= number <= b - set up an inner loop that runs once for each number stored in 'list' - write an if statement that checks whether a number in 'list' == 'number' - if so, increment the counter 'count' - if count < 2: - use 'appendItem(list, number)' to add 'number' to 'list' - increment 'num' function randomizeImages() { }