CSCI 111 LAB 7
previously CSCI 15a

Lab Times: See course home page

TA: See course home page

Worth:30 points


Guessing Game

Problem:

Write a program to create the classic hidden squares guessing game. Game play is pretty simple, a 4*4 grid is displayed in a single color. A user clicks on a square with the mouse and the square flips over changes color ) and then clicks on another square. If the two squares are the same color then both stay turned over, otherwise they turn back over ( change back to default color).

Requirements:

To complete this problem you will need to use at least one loop ( either a while or a for loop ) and a number of "if" statements or "switch" statements. The game should have a button that resets the board to a new random state. This button will be labeled "new game". The game should use at least 8 color pairs ( ie two squares of the same color ). You should not use either white or black colors. The board should be drawn in black with white lines dividing the grid up into squares. For full credit, an Object Model and fully documented source must be turned in along with the Applet.

Hints:

Think abstractly, use numbers to represent the colors in the game and a switch statement to help draw them out.

This problem is very easy to solve using two double (2-D) arrays. Double arrays create a simple data structure that can represent a 4 by 4 grid.

In addition, use one array to keep track of which squares are what color and one array to keep track of which squares are turned over.

Example run and output of the above program

$java ExampleSquare

 0 1 0 5
 5 6 5 1
 4 6 0 3
 6 6 0 4
 
 

Here is a graphical example of values being set in an array. Source is here.
Another 2D one and its code.
Parts of this might be interesting to you for this lab.


Lab Submission

Here is a help page for this lab
Submission: