Public Class frmGame 'student version 'Images: the array index is the number of the PictureBox; the Image is the associated image. 'For example: Images(1) is the Image stored in PictureBox 1. Dim Images(numBoxes) As Image 'ImageNums: the array index is the number of the PictureBox; the stored integer is the number of the 'associated image. For example: ImageNums(5) stores the number of the image (from Form 3) stored in 'PictureBox 5. On Form3, the images are numbered 1 to 18. Dim ImageNums(numBoxes) As Integer 'ImagesUsed: the array index is the number of the image in Form 3; the stored integer is the number 'of times that the image has been used in populating the game board with images. For example, 'if ImagesUsed(3) = 1, that 'means that image 3 from Form3 has so far been used once in a PictureBox on the game board. All entries 'of ImagesUsed will eventually, after the game board is set up, be 2. (Each image is used twice 'on the game board.) This array is used when images from Form3 are being assigned to PictureBoxes 'on Form1. Dim ImagesUsed(numImages) As Integer Dim numRows As Integer 'the number of rows of PictureBoxes Dim numCols As Integer 'the number of columns of PictureBoxes Dim spacing As Integer 'controls the spacing between PictureBoxes Dim numClicks As Integer = 0 'the number of times a player has clicked on the game board in a turn Dim player1Score As Integer 'player 1's score Dim player2Score As Integer 'player 2's score Dim pbNum As Integer 'the number of a PictureBox Dim pbNum1 As Integer 'the number of the PictureBox that the player clicked on in his first turn Dim pbNum2 As Integer 'number of PictureBox in second click Dim pb1 As PictureBox 'PictureBox Dim pb2 As PictureBox 'PictureBox Private Sub frmGame_Load(sender As Object, e As EventArgs) Handles Me.Load 'This method is complete. Call setUpGame() End Sub Public Sub setUpGame() Dim randNum As Integer 'used to randomly assign Images from Form3 to the game board Dim foundIt As Boolean = False 'also used in assigning Images to the game board 'TO DO: This is part of the extra-credit option that allows the player to choose the size 'of a game. Set up an IF statement based on the value of 'numBoxes'. For each option '(12, 24 or 36 boxes), assign values to 'numRows', 'numCols' and 'spacing'. 'Feel free to change these: Me.Height = 800 Me.Width = 1200 'TO DO: Initialize variables and labels 'set 'player1Score' and 'player2Score' to 0 'set 'lblTurn' to notify the player who will go first that it is her turn 'set lblPlayer1Score' and 'lblPlayer2Score' to give the player's name and his current score 'TO DO: Set up the PictureBoxes that the players will click on 'Set up a loop, with index 'boxNum', that will run 'numBoxes' times 'Each time the loop runs, another PictureBox will be set up 'These lines are inside the loop: Dim p As New PictureBox p.SizeMode = PictureBoxSizeMode.Zoom Me.Controls.Add(p) 'TO DO: It is necessary to randomly assign the images on Form3 to the PictureBoxes on Form1 'You don't want to play the same game over and over! 'We set up a loop. Inside the loop, we want to pick a random image to assign to the new PictureBox p 'Here's one way to do it: '- set up a (inner) while loop that runs as long as a boolean 'foundIt' is false '- generate a random integer 'randNum' between 1 and 18. The functions CInt() ' and Math.Floor() might be useful here. '- check if 'ImagesUsed(randNum)' is 0 or 1. If so, this 'randNum' is OK. If it is 0 ' or 1, that means that the image has been used 0 or 1 time so far, so it is OK to ' use it again. Each image is, of course, copied twice to the game board. '- if this 'randNum' is OK: ' - copy 'Picture(randNum)' to 'p.Image'. ' - increment 'ImagesUsed(randNum)' to record the fact that image number 'randNum' was copied. ' - assign 'randNum' to 'ImageNums(boxNum)'. 'ImageNums' records, for a given ' PictureBox, the number of the image from Form3 that was copied to it. ' - set 'foundIt' to true, to stop the loop '- if, on the other hand, ImagesUsed(randNum) is already 2 (meaning that the image numbered ' 'randNum' on ' Form3 has already been copied twice to PictureBoxes on the game board), do nothing. ' The loop will then run again, a new random number will be generated, and the program ' will try again to copy a random image from Form3 to Form1. '- end the IF statement and the inner loop '- Note: This is the not the most efficient way of doing this. But it is easier to ' understand and code than the alternative. 'TO DO: VB controls have a Tag property which can be set however a programmer would like 'assign the number of the current PictureBox to the Tag property of PictureBox p 'TO DO: assign p.Image to position 'boxNum' in the 'Images' array. This records, 'for PictureBox 'boxNum', the image from Form3 that is assigned to it. 'TO DO: to start the game, each PictureBox needs to have the 'door' image from Form3 'displayed. Assign this image to 'p.Image'. If the image is named 'door', you can access 'the image as Form3.door.Image. 'These 2 lines of code position the new PictureBox on the form. This code is complete. p.Left = ((boxNum - 1) Mod numCols) * spacing + 30 p.Top = ((boxNum - 1) \ numCols) * spacing + 30 'This optional code causes shorter images to be 100 pixels high. If p.Height < 100 Then p.Height = 100 End If 'This code states that the 'event handler' for control 'p' is 'PictureBox_Click', which 'is below. In other words, when the player clicks on 'p', 'PictureBox_Click' will run. 'This code is complete. AddHandler p.Click, AddressOf PictureBox_Click 'TO DO: end the outer loop End Sub Private Sub PictureBox_Click(ByVal sender As Object, ByVal e As System.EventArgs) 'This function runs when a PictureBox is clicked on. 'TO DO: the variable 'numClicks' keeps track of how many times a player has clicked ' in his current turn. Increment 'numClicks'. 'TO DO: check if the player has clicked 2X in his turn. If so: '- set 'pb2' equal to 'sender'. (Note 'sender' in the first line of PictureBox_Click.) ' This stores the clicked-on PictureBox in 'pb2'. '- display the correct image in the clicked-on PictureBox. You may find that the Tag ' property of the PictureBox, the 'Images' array and the integer 'pbNum2' helpful here. '- Call pb2.Refresh(). This can help the image to display correctly. '- reset 'numClicks' to 0. 'TO DO: still inside the IF statement that you started above, check if there is a match 'on the game board. The 'ImageNums' array may be helpful here. 'TO DO: increment the player's score 'TO DO: check if the game is over. If it is, call 'gameEnd()'. 'TO DO: this is part of the extra-credit option in which the player can choose whether 'or not a player who gets a match retains her turn. If the boolean 'stillYourTurnAfterAMatch' 'is true, take no action. 'However, if it is false, update the variable 'player' 'TO DO: add an Else that goes with the earlier IF statement that checked whether 'or not there is a match on the game board. So the section below will run if 'it isn't a match. 'this line will cause a pause or delay of length 'delay' before the images disappear 'and the door reappears. It is complete. Threading.Thread.Sleep(delay) 'TO DO: update the variable 'player' 'TO DO: copy the 'door' image from Form3 to both of the 'exposed' PictureBoxes 'TO DO: put an End If, which ends the code that deals with whether or not the 2 'images on the board match 'TO DO: update lblTurn, lblPlayer1Score and lblPlayer2Score 'TO DO: add an Else, which matches the IF statement above that checked whether the 'player had clicked 2X in this turn. Inside the Else you'll deal with 'the situation in which the player has clicked once so far. Your goal here is to get 'the correct image to display in the PictureBox. The code is similar to what you did 'above to get the image to display correctly, when the player had clicked twice. 'TO DO: add an End If End Sub Private Sub gameEnd() 'This procedure runs when the game is complete. 'TO DO: see who won, or if it was a tie. 'Update 'lblStuff' with congratulations to the winning player, or announce a tie. End Sub End Class