tetris game using java

profilerajeev4

tetris game

  • 20 days ago
  • 80
files (4)

CSCI_282_TetrisGame_Part_3_manual.pdf

CHAPTER 4

Tetris Game Part 3

Completing the logic of the Tetris game for removing full rows and scoring

Establishing a leader board

Save and Retrieving games from file

FULL GAME FUNCTIONALITY

1. Filled rows scored and disappeared

2. Score tracked on TetrisDisplay.

3. All bricks above scored line drop down to fill blank line

4. Game over detection

5. High score must be tracked, displayed in sorted order and saved to file.

6. Menu system in place with two pull down menus with functioning menuItem

7. Save game to file with a user created name

8. Retrieve game from selected file name.

SECTION 1

Evaluation Criteria for Tetris Game Part 3.

In part 3, you will be evaluated on new aspects of the game. The points you earned points for on Parts 1 and 2 will not be

earned in part 3 even if you did not submit part 2. However, any er- rors not corrected from previous parts will earn you penal- ty points.

In Part 3 you will be finishing up your game such that the game can be saved to and read from a file, full lines will be detected, re- moved and scored. Also a High score leader board must be established. There must also be a functioning menu system.

2

Itemized Part 3 requirements of user interaction

1. The user should be about to save a current game to file to finish later by retrieving it from file. As such the methods saveToFile and retrieveFromFile should be added to the game class.

2. When saving a game to a file name, the user must be able to enter a file name.

3. You must be able to retrieve a game back from file using a GUI Interface to select file (JFileChooser)

4. There must be a menu bar in the window class with two pull down menus.

• One Menu items must have an option to display leader board, and one to delete all high scores to start over.

• The other Menu should deal with the new game, and saving and retrieving games from file.

Itemized Part 3 requirements for game play

1. Full line detection followed by full line disappearing and score increasing must be complete and correct.

2. All rows above disappeared lines should drop one row.

3. Score must be incremented by 100 if just one line disap- pears, 300 for two lines, 600 for three lines and 1200 for four lines.

4. Score must be shown on the Game display.

Itemized Part 3 requirements for Leader Board

1. You must design you own LeaderBoard class that is GUI

2. This leader board must save the highest 10 score display in descending order. Scores must be accompanied by a name

3. Score must be persistent.

4. Functionality must include adding a new high score in proper order and clearing all high scores.

5. This class is called from the Window class menu option.

6. The UML class diagram for your class must be included in your worksheet

The grading criteria are available at the submission site on the Moodle class page. Please read all criteria over carefully. If you have any questions over these criteria, make sure you ask. Not understanding a criteria does not prevent you from loos- ing points if you did it incorrectly.

3

QUESTIONS TO CONSIDER

1. How many rows have to be checked?

2. What happens if more than one full row is detected?

3. What happens if the full rows are not consecutive?

SECTION 2

Detecting full rows Detecting Full rows. I will leave how to score a full row to you. So there are no required methods. I recommend that you use helper functions that looks for full rows. But you have to realize you can have one, two, three or four full rows with one brick placement. The game boards below show various situation for row scoring. The full lines should be detected and scored BEFORE the next brick is spawned.

The images above depict one full row scored.

The images above depict two full rows

4

scored.

The images above depict three full rows scored.

The images above depict four full rows scored.

But you must realize that full rows do not need to be consecu- tive. Full rows can have a row with spaces in between them.

Please note that the only rows that need to be checked are those that involve the position where the latest brick was posi- tioned in the board. Possibly a helper function in the Tetris

brick called getMinimumRow and getMaximumRow would be useful.

I recommend that you use helper methods to accomplish the sub tasks needed to accomplish the detection, removal and scoring of a full row. This improves readability of your code and if you don’t you could have up to 4 to 5 nested loop struc- tures in one method, which can be difficult to debug.

Some suggested methods

• rowHasSpace( int rowNumber) - returns true if there is a space in the row of the board. This is used to determine if the row is full and needs scoring.

• rowHasColor( int rowNumber) - return true if there is color in row of the board. This would be used to detect the end point of shifting rows down.

• copyRow(int rowNumber) - copy row content to the row below. Used to shift a row down when a full row is scored. The method affectively over writes the content of the row below, making the deletion of this row unnecessary, unless of course you want to go for extra credit and make some special effect that shows the bricks imploding or something equally dramatic. :0)

• copyAllRows(int rowNumber) - calls the method copyRow on each row starting with rowNumber and above (located higher in the well, or at a lower row number).

A suggest approach uses the following pseudo code:

5

1 .Determine the range of rows to be checked. 2. currentRow - highest row number in range 2. REPEAT for each row within the range starting with max 3. IF rowHasSpace( int rowNumber) is false 4. call copyAllRows(currentRow) 5. current row is incremented (so that when for loop decrements current, it remains the same 6. min row of range is decremented 7. END IF 8.END REPEAT

But this is just a suggestion. There are other equally valid ap- proaches.

hint: once you have copied the row above the scored row to the position of the row that was scored, you have to recheck that row for fullness, unless that row was not in the range of rows affected by the last play.

Now, this suggested approach is how to get the rows to disap- pear. You also have to work out how to score this process. I would recommend that you count the number of row removed and then figure out the score after going through all rows that need checking.

Once again, I will give you the freedom to use what ever helper methods you want, but you should use helper methods. That is just good programming form. Warning: You will be

penalized if there is more than three nested for loops in any of your methods. I would like to see two or less. I want you to practice good method design by making functions short and concise. I have given you a couple of suggestions.

6

You are required to

7

SECTION 3

Interfaces

1. UML Representation of Interfaces

2. Functionality of Savable Game.

3. Change in TetrisWindow class

  • Tetris Game Part 3
    • Evaluation Criteria for Tetris Game Part 3.
    • Detecting full rows
    • Interfaces