In this exercise you will create a simple memory game (http://en.wikipedia.org/wiki/Concentration_(game)).
In the memory game, images are randomly placed face-down in a grid. Each turn, the player chooses two images to peek at. If they choose two of the same image in a row, those images are a match and will be hidden from the game. If the images do not match they will be turned back face down after one second. You win when every image is removed from the game.
- You should be able to play the game with and without using the mouse.
- The game should count how many attempts the user have made and present that when the game is finnished.
- It should be possible to render different sizes of the gameboard. (4x4, 2x2, 2x4)
- Even though a game board is rendered as an matrix (4 x 4) the game logic does not need the images to be placed in an matrix. Instead, let the images be represented by an array where 0 is the first image and 15 is the last image.
- Every image (number) should appear twice in the array [0,0,1,1,2,2,3,3,4,4...]
- There is no need to save the url to the image in the array, but you could if you like to.
- You will need a function that will shuffle the array of images.
Possible solution path
- Decide your overall design approach. Types or only a function?
- Create the array and populate it with image ids
- Shuffle the array
- Make the bricks "turn" when clicked
- Implement game logics
To try out to learn even more
- Do you want to use types for the game or just use a function create game boards?
- Can you solve the assignment by setting only one click-eventlistener per memory game?
- Why not try to use Custom Elements in the exercise?
Extending the game
- Two players and a bigger board? Each player gets a pile of matched pairs. The largest pile in the end wins.
- Add a timer to force the user to win as fast as possible
Images made by Moa Alfredsson Original assignment by Petter Miller 2002