SWEN221 Assignment 2-Complex class hierarchy Solved

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

Rate this product

This assignment will expose you to a more complex class hierarchy. A key challenge will be in understanding the flow of control through the program, particularly as there is extensive use of polymorphism. This assignment will also test your debugging skills, and you should strive to be methodical in how you approach debugging.

Tetris

This assignment concerns the classic game of “Tetris”, originally developed by the Russian programmer Alexey Pajitnov. The tetris pieces (called Tetromino’s) are controlled using the keyboard (in this case, the arrow and space keys). As is usual in the game, the pieces are subject to “gravity” meaning that they slowly descend downwards. Pieces can be made to descend more quickly using either the down arrow key or much more quickly using the space key. Likewise, pieces move left or right, and rotate clockwise using the up arrow key. The code includes a graphical user interface so you can play it:

In Tetris, there are seven tetrominoes:

                                           “Z”          “S”            “T”           “J”           “L”         “O”          “I”

Each tetromino has an axis of rotation illustrated above using a circle and an orientation (i.e. North, East, South, West). The tetromino above are illustrated in their North orientation. Finally, for more information on the game of Tetris, refer to https://en.wikipedia.org/wiki/Tetris.

Getting started

To get started, download the tetris.jar file from the lecture schedule on the course website. As usual, you can run the program from the command-line as follows:

java -jar tetris.jar

A simple GUI should appear on your screen, and you should be able to play the game. Remember, however, that at this stage the game contains a number of bugs and missing features. For example, pieces move in the opposite direction from what you are expecting!

Understanding the Code

Each piece is implemented as a separate class which extends the abstract class Tetromino. When you import the tetris.jar file, you should find the following Java packages:

  • The swen221/tetris/gui/ package contains the graphical user interface and the main method. You do not need to understand the inner workings of this in order to complete the assignment. NOTE: you do not need to modify any code in this package.
  • The swen221/tetris/logic/ package contains the class Game encoding the logic of a game of Tetris, and the class Board representing the current state of the board.
  • The swen221/tetris/tetromino/ package contains the interface Tetromino and the concrete implementations for all tetromino.
  • The swen221/tetris/moves/ package contains a class for each of the different kinds of move that can be made in the game. These contain code related to structuring a move, and ensuring it is valid.
  • The swen221/tetris/tests/ packages contains many jUnit tests to check your implementation of the game. NOTE: To make the automatic marking possible, you can not modify the files already present in this folder, but you may add your tests in a separate file (e.g. java).

Part 1 — Simple Moves

The first objective is to make sure the game correctly recognises all of the simple moves that a piece can make. Specifically, this part concerns mostly minor problems in the tetromino implementations (e.g. J Tetromino) and the RotationMove and TranslatioMove classes. At this stage more complex moves, such as for remove lines and ending the game, can be ignored. A suite of tests for this part is provided in swen221/tetris/tests/Part1Tests.java. You can run these tests individually, or all together. You are advised to write additional tests to ensure the system is working correctly.

Part 2 — Landings

The second objective is to implement the mechanism for landing pieces. In particular, this includes the “drop move” where a piece descends immediately from its current place. When a piece is landed, the next turn continues. A suite of tests is provided in swen221/tetris/tests/Part2Tests.java.

Part 3 — Invalid Moves

The third objective is to make sure the game correctly recognises when a move is invalid. For example, a piece cannot be moved off the side of the board. Likewise, a piece cannot be dropped below the bottom of the board, or into the middle of another piece. The following illustrates such a situation, where one piece is landed in the middle of two others:

(1)                                                              (2)

A suite of tests for this part is provided in swen221/tetris/tests/Part3Tests.java. You can run these tests individually, or all together. You are advised to write additional tests to ensure the system is working correctly.

Part 4 — Line Removal

The final objective is to correctly handle line removal rows when a tetromino has been “landed”. The following illustrates the a tetromino being landed and a number of full rows being removed:

(1)                                                               (2)                                                               (3)

Here, we see that three full rows are removed when the I tetromino is landed. A suite of tests for this part is provided in swen221/tetris/tests/Part4Tests.java

  • SwenA2-g94qwt.zip