HW5: Simpsons Game

Assignment

You are going to write a game. You open 2 cards each turn. If two cards have same icon, remove the cards. If the two cards have different icon, turn them over.
 

Program

You should download the following pictures.
Apu Bart
Burns
Homer
Krusty
Lisa
Maggie
Marge
Moe Ned
and down the class file Game.class
place them in the same folder and use
java Game
to run the program
Or
You can go to the computer lab. Open a DOS prompt. Type H:, and then cd H:\class\p20a.1\.
Use java Game to run the program

Screen Shot


1. The program starts. The title is Simpsons Game
image1

2. Click on one button. An image of maggie shows up.

image2

3. Click on another button. An image of Apu shows up.

image3

4. Maggie and Apu are different images. Click on any active buttons. The images disappear(turn over).
The number of attempts is increased by one.

image4

5. Find 2 button with the same images.
image5

6. Click on any active buttons, the images are removed.

image6

7.  remove all the images.

image7

8. Remove all the images by 24 attempts. A new game starts.

image8

9. To help the grader to grade this HW,  plesae print out the image name at DOS prompt.

image9

Hint

1. Use the following code to randomize an array :


   public static void random(Object[] array) {
       for(int i = array.length-1; i >=0; i--) {
       int j = (int)(i*Math.random());
       Object temp = array[j];
       // swap;
       array[j] = array[i];
       array[i] = temp;
    }
   }

2. You can remove icon by  setIcon(null) in JButton class.
3. You can disable a button by setEnabled(false) in JButton class
4. You can change the color of a JButton by using setBackground(Color) method.

What to submit

Call your source code file Game.java. Put this file in your submit folder. Do not place this file inside another folder within your submit folder.

Remark

Solution

Game.java