Computer Science 120
Introduction to Programming

Fall 2011, Siena College

Project 5: Concentration (also known as Memory)
Due Date: Monday, December 12 at 11:59PM

Overview

Implement the game of Concentration as shown below:

Project 5 Demo

Documentation and Compilation [20 points]

All your code must include descriptive comments include JavaDoc style comments for all classes and methods. Specifically, be sure to do the following:

[3 points] Every class should have a top banner style comment that describes the details of the class and in addition

[3 points] Every field (class instance variable) should have a descriptive comment

[3 points] Every method (especially constructors) should have a banner style comment that describes the details of the method and in addition

[3 points] Complex code, such as loops and if statements should have descriptive comments.

[8 points] Compilation - If you have made a reasonable attempt and your code complies. A reasonable attempt implies that you have tried to implement at least 40 points worth of functionality below.

Basic Functionality (60 points - to Earn a "B")

Requirements:

Your program should output a grid with at least 20 cards with 10 different "values."

The "value" of the card should be hidden.

1. When a first card is clicked, the value should be shown.

2. When a second card is clicked, the program should do the following:

a. If the second clicked card's value matches the first card's value, both the first and second card should remain shown for the rest of the game. Then, repeat steps 1 and 2 shown above.

b. If the first and second card's values do NOT match, record a mismatch, the first card should be hidden, the second card should become the first card and steps 1 and 2 shown above should be repeated.

3. The game ends when all the cards are matched, i.e., the values are all shown.

4. The game should print the total number of mismatches counted in step 2b.

Advanced Functionality (to Earn an "A" or even higher)

Timed Game [8 points]

Your program should output the duration (in seconds) that it took the player to match all the cards.

Hint: Look at the documentation for System.nanoTime() or Google "How to calculate the running time of my java program"

Best Score [12 points]

Your program should calculate the game score. The game score is the time (in seconds) plus the number of mismatches. For example, if you completed the game in 88.4 seconds with 32 mismatches, your score would be 120.4 (88.4 + 32). The lower the score the better you did. When your program first starts (begin method), you should read the current best score from a file and display it on the canvas. You can initially put the value 9999 in the file. If the user beats the best score, i.e., achieves a lower value, then you should write the new best score to the file.

Hint: To read from a file, we used a File object and a Scanner object. To write to a file, we use a FileWriter and the BufferedWriter's write method.

Images [15 points]

Your program should use images instead of numeric digits (Text) on the cards.

Use these images: Images.zip

The images have heights of 150 and widths of 100. The file names are sequential p0.jpg to p11.jpg, which makes it easier get each imagine using a loop.

Hint: Instead of using a Text object for the "face" of the card, you can use the Objectdraw's VisibleImage object and the WindowController method called getImage to pass an image into each card instead of a String or numeric value.

ActiveObject [20 points]

You can earn up to 20 points if your Card class extends ActiveObject and the showing and hiding of the cards is animated. This bonus is not recommended unless you are very comfortable with programming and need a challenge.

Hint: The card can be animated by changing the height or width so card appears to be flipping. An example will be shown in class. The run method should implement an infinie loop that can be paused and unpaused. When you show or hide the card, the animation can be unpaused,which shows the flip. After the flip completes, the run method will pause itself to get ready for the next show or hide method call.