Microsoft Word - Document4
Assignment Instructions
All code must be written in processing software, free software download on processing.org
Write code for the flip tile game; here is how the game is played :
Basically there are 2 images...
1. To begin with, one of the 2 images are randomly displayed in each cell of the grid.
2. The user clicks on a cell to toggle between the 2 images.
3. Game comes to an end when all the cells in the grid show the same image.
Watch the video to recall how the game is played. (It has been loaded inside hw7 folder in the
ox).
You will need a 2D a
ay board that stores either a 1 or 2 to let us know what image is being
cu
ently shown in a cell.
Inside setup :
1. Randomly populate board with either 1 or 2.
2. Do the visual representation of what is inside board (1 means show your first image on
that tile in the canvas & 2 means show your second image on that tile in the canvas )
Inside mousePressed:
1. Find clickedRow & clickedCol - both of that put together gives the user selected tile.
2. Check what is being cu
ently displayed in the user selected tile (check the content
of board at location determined by step 1).
3. Refer to activity_alternate_images inside BOX in the
folder 11_09_29_images_intro_finish_ascending activity_toggle_image inside BOX
folder 11_09_30_image_intro_descending puzzle for step 4 - first understand what has
een done there; then try applying that concept here.
4. If it is showing image1(ie. board has a 1 in that position) then
a. change the board content at that position to 2
. write code to reflect this change visually by showing image2 in that cell on the
canvas
5. else
means that tile is showing image2.
a. change the board content at that position to 1
. write code to reflect this change visually by showing image1 in that cell on the
canvas
6. If game is over,
a. close the game
Game over condition :
1. Find how many tiles display image1 - giving 2 ways to do this.
a. Maintain a variable that keeps count of # of image1 being displayed. (involves a
couple of steps in mousePressed - I have not included that.)
. OR Count the number of 1 occurs inside the 2D a
ay board (involves searching
in the 2D a
ay board )
2. If the number determined in step 1 is same as number of tiles in the whole canvas (ie. all
tiles are showing image1) OR that count is 0 (ie. all tiles are showing image2) then
a. game has come to an end.
3. else
a. game needs to continue.
Lavf XXXXXXXXXX