You are on page 1of 6

EE3206 Assignment Two Hyper Snake 2

(Due Dates: see the last page)

Objectives: Learn to read and write data from and to files or steams. Learn the basic concepts of graphics and animations. Learn to model entities in a program with Java class and object. Introduction In this assignment, you are asked to continue the development of your snake game. Some new features are requested for enriching the original gameplay. Therefore, you need to fix the problem, if any found, in the previous demo, so as to move on to the development of the next stage. A new class is included in the JAR library. The new class named AdvGameConsole is an extension of the previous class GameConsole, and provides certain new functions to support the implementations of the requested features. The usage of the new class will be explained in the following sections. Basic Requirements The following functionalities are compulsory and are considered as an evidence of achieving the course learning outcomes. So all students are expected to finish this part. 1. Show Score As shown in Figure 1, the game score is displayed beside the time elapsed. The player gains certain score when the snake eats an apple. The score for each apple is calculated by this equation: Let t be the time in millisecond of an apple appearing on the screen. Score of an apple = floor( 10000 / t ) For example, if the snake takes 2 seconds to eat the apple since it appears, then the score for this apple is equal to 5 and this score will be accumulated to the total score of the player.

2. Save Game and Load Game The player is allowed to save a game or load (restore) a game. To save a game, your program needs to output all the game data such as the snakes coordinates and length, the time, the score etc. All these data will be saved to a file so that the player can restore the game later. You can design whatever file format used by the save. 3. Open Option Menu As shown in Figure 2, the player can open the option menu (press A) and choose to save or load a game (press UP or DOWN to choose and press S to confirm). When the menu is open, the game will be paused until the menu returns. You can freely design your own menu but it must provide the two options for the player to choose. There are a few new constants defined for the input keys:
public static final int KEY_A public static final int KEY_S public static final int KEY_D public static final int KEY_F public static final int KEY_NULL

The first four constants are corresponding to the A, S, D and F keys on the keyboard. The last one, KEY_NULL, will be set to the key buffer when you call the following method:
void clearPressedKey()

This is necessary to determine whether the player consecutively presses the same key more than one time. Therefore, you should clear the key buffer after you read the last pressed key. For example:
AdvGameConsole gc = new AdvGameConsole(); gc.showGameBoard(); ...... int theKey = gc.getPressedKey(); gc.clearPressedKey(); // get the pressed key from buffer // reset the buffer to KEY_NULL

4. Scoreboard As shown in Figure 3, a scoreboard will be displayed at the end of the game. The scoreboard shows the three highest score records. If the current game wins one of the places, the scoreboard needs to highlight the player as illustrated. As in the previous assignment, you will call the gameOver() method to show the end game screen when the game is finished. This game over screen, however, will be replaced by the scoreboard screen in this revision. So you do not need to call the gameOver() method again. Instead, you will need to draw the scoreboard when certain end game condition is encountered. Here are the other three new methods in AdvGameConsole that let you draw colored text, colored rectangle, and any images.
AdvGameConsole drawText(int x, int y, String text, Font font, Color color) AdvGameConsole drawRectangle(int x, int y, int width, int height, Color color) AdvGameConsole drawImage(int x, int y, Image image)

For example:
Image image = new ImageIcon("menu.png").getImage(); gc.drawImage(50, 50, image);

The above statements will load the image file menu.png and draw it on the screen with its upper-left corner set in (50, 50).

Figure 1: The game score is displayed beside the elapsed time.


3

Figure 2: An option menu is shown and the game is paused.

Figure 3: The scoreboard is displayed at the end of the game. Top-Up Requirements This part is more challenging and is designed to distinguish how well students grasp the Java programming concepts. 1. Support Multiple Saves When the player chooses save or load from the option menu, a sub-menu will be displayed to provide three slots for saving or loading. That means the game can have at most three save records.

Figure 4: A nested sub-menu is displayed to provide three slots to save.

2. Compress the Save File with Zip To reduce the file size of the save file, you are requested to compress the output save data by the Zip algorithm. Similarly, you need to decompress the save file when you restore the game. 3. Play Background Music and Sound Effect There are three MIDI files packed in the library for you to use:
public static final InputStream MIDI_BG_FILE; public static final InputStream MIDI_SE_FILE; public static final InputStream MIDI_GO_FILE; // background music // sound effect // game over music

You need to implement the playback of MIDI sounds in these cases: The background music is played throughout the game and looped repeatedly. When the game is over, the background music is stopped, and the game over music is played once. The sound effect will be played when the snake eats an apple.

Implementation Requirements Similar to the first assignment, your program should follow the classic snake game rule described in assignment one. When the main method of your program is executed, the game should start immediately. The game continues until one of the mentioned game over conditions occurs. You do not need to include your proposed features in this version. *Please name your main class SnakeGame.java You are expected to design and implement your game in an object-oriented approach. Therefore, you should follow all kinds of OO conventions, such as naming and style, and should create additional class(es) to model entities living in your game. At most, 30% of your maximum assignment scores can be deducted if your program is not object-oriented. Last, you need to write a one-or-two-page summary to document and briefly explain your class design for the functionalities stated in the Basic Requirements. To make your presentation clear, you should use UML diagrams to illustrate your class design
5

and relationships, if any. Then write short paragraphs to explain them. Submission Requirements (Due Date 1: 9 Nov. 23:59) Upload you document (MS Word format) to blackboard before the due time. (Due Date 2: 21 Nov. 23:59) Upload all you Java classes (*.java) and the resource files (e.g. images) as a single ZIP archive to Blackboard before the due time. Before submission, you should: Make sure your program can be compiled and run in NetBeans. Make sure this is your final submission. You can only submit once! Assessment Basic Requirements (5 marks) Top-Up Requirements (3 marks) Document (2 marks)

A tutorial section will be used for doing demonstration. Your submitted program will be returned to you during the time, and then you will be asked to run and demonstrate the features in your game. You should prepare for the challenges or questions from the graders. Please note that: The grader has no responsibility to debug your program. Any program which cannot be compiled or executed will result to zero mark. Each mistake/defect deducts certain portion of marks from the total, depending on the seriousness. Defects may also be about improper naming, programming styles, code formats, aesthetic and responsiveness. Late submission is permitted only within 24 hours after the deadline. 20% marks will be deducted from the assignment. Submissions after 24 hours will not be accepted. Any suspected plagiarizing work will be sent to Discipline Committee for further investigations.

You might also like