An “easy” game to play on a computer is memory. The player(s) are presented with a grid of “tiles” with images. During a players turn they are allowed to turn over two tiles and look at their images. When the images match the players scores a point and may guess to new tiles. When the images don’t match the turn goes to the “next” player.
To play a single player game, one might count the total number of guesses.
For this game we suggest using either a native array, or an array list.
You may ask what the point of this exercise is. Well, we want you to design your memory class in such a way that it supports the following features:
Memory
class with a Visualisation
class that can draw or print as needed.
The tiles may contain different images:
But to make things easy, one might start with just letters, digits, colors or words.
Design your memory in such a way that the datamodel allows for various types of data using generics!
Depending on the size of the board, you must end up with an even number! (Please take your time to think about this.)
Dividing by two tells you how many different “images” (or words, of symbols, or colors) you need.
The second array tells you which tiles are located where on the board. The stored values are the index of the “image” on the tile.
You can create an additional array with numbers 0 through I.
Rather than looking up the tile immediately, you may read a number from this new array. This way you look up a random image for this game, so that different games may use different images.
For each game only the first images are used. Rather than shuffling the actual content, you can shuffle this index array. Allowing all images to be used even when there are only some images needed.
We Very Strongly advise you first use letters and
just print the grid using System.out
.
This way you can ask for input and show the two selected “tiles”.
Later on you may want to use the SaxionApp
to actually show the tiles, and the corresponding images when chosen.
Add the ability to store:
Provide a high score system. After playing, and using only a few guesses, players should be allowed to type in their name. This is then stored to the database. And after (or before) each game you can show the top 5 players, their score, and the date on which they played…
Here is an assignment that uses many of the skills youhave learned over the last year. Have fun!