You will write a java applet memory game similar to the example above. I have given you a starting program Memory.java where you will have to fill in the missing pieces. The program I have given you has some functionality, make sure you read the comments and understand which pieces you can change and which pieces you should not change.
This is a very hard program and I recommend starting simple and then adding more complicated features.
The game board
Think of the game board as a 2-dimensional array that holds matching pairs of integers. Each integer will display a different shape on the board.
Build an array that holds the values for your game board. Your board must be random. I recommend writing a method to display the values in your array to make sure they are correct (see page 504, or MyArrayTest.java).Example Board:
Start simple. Declare and initialize a 4 x 4 array and put the integers 0-15 in order in your array. (Display your array to make sure it is correct). Now change the numbers 8-15 to 0-7 (think %). Randomizing the numbers is the hard part and there are many different ways to do this but you will probably want to use Math.random().
You have been given code that gets mouse clicks and sets xMouse and yMouse to the location of the mouse click. xMouse and yMouse will range from 0 to 399. You will be using the Graphics class to display your game board. The window is 400 x 400 with (0,0) in the upper left corner. You should think of the board as a visual array with board as the top right corner and each bow is 100 x 100. To determine which square the user has selected you will need to convert the location of xMouse and yMouse to your array indices. There is a very easy way to do this without using if statements or switch statements. You will need to write a method that determines the current index location the user has selectedindex 0: 0 - 99
Once you know which index the user has selected you will need to display a circle (or whatever shape you want) in the correct square on the board. You can determine the location of your shape by multiplying and adding your current index by numbers.
The color of your shape is determined by the integer in your 2D array. Write a method similar to you color method in Lab 7 to set the color of your shape. The integer you will pass in will be board[xIndex][yIndex] (the integer located in the xIndew, yIndex location in the array).
You should start thinking about the game functionality once you have everything else working. There is nothing tricky about the coding; this is just a logic problem. I recommend that you start this section with a piece of paper and pencil and write some pseudocode. Here are some things to think about and consider:
Grading25 points Friday April 15 Recitation
How to hand in the assignment