Your Task

Applying what you have learned so far, you are asked to write your own 2-dimmensional shape based game. Examples of this could include Pong, Snake, Space invaders, or other simple 2D games of your own creation.

The first part of the assignment is to create an application capable of holding a collection of different shapes, drawing these shapes to the screen, allowing these shapes to be moved by the user, and resized on the screen. The second part asks you to extend this basic set of building blocks to construct a simple game of your own design. This can be inspired by classic arcade games, so long as all the code is your own.

Note, you are not allowed to use additional APIs (application programming interfaces), libraries, or code found online or elsewhere.

Detailed Description of Tasks

Marks will be given for individual stages in the game development. The more aspects of the game you implement the more marks you will gain. The breakdown of marks will be as follows:

  • Your user interface should be run as an application that can hold a grid of filled squares. The grid of squares should be of length 20 and of height 20. Initially the grid should be empty. The application should also display your name and registration number (in the title of the frame for example).
  • Shapes should be encapsulated in their own classes. An abstract class Shape should first be created. This should then be extended to create classes to encapsulate the following types of shape: Squares, Rectangles, Circles, Triangles, Pie shapes (portions of a circle). The shapes should all be stored in a single collection. Each shape should encapsulate methods to allow it to be drawn to the screen at arbitrary positions, rotations, and sizes.
  • Two event handler classes should be created to respond to keyboard events (e.g. pressing the arrow keys) and mouse events (e.g. pressing the mouse buttons).
  • The game should keep a record of scores. This should be done via a text file. A new class should be created to allow new scores to be entered into this text file. Methods should be added to return the top 10 scores of the past 24 hours and the top 10 scores of all time. These scores should be displayed on-screen at the end of a round of your game. Appropriate exception handling should be used (for example for missing files).
  • A short report should describe your solution (see below).
  • Do not simply put all code in a single class. You should apply the object-oriented principles we have studied this term and use appropriate comments throughout your code (see details below).
  • The remainder of the marks are allocated for developing a game using these basic building blocks. Your game should be 2D and use the Shape classes, event handlers, and score tracker developed above. The game can be based on classic arcade games (Pong, Space invaders, Pacman etc.) or of your own design. After the end of a round of your game a score should be allocated (this could be based on some outcome of the game, e.g. in pong you could gain 1 point for winning, or the length of time you survive for). The score should be displayed to players after finishing a game along with their all-time ranking. An interface should be available to allow the top 10 scores in the past 24 hours and the top 10 all-time best scores to be displayed.

Getting Started

To make the task more manageable I provide you with some snippets of code you might want to re-use:

  • I placed some simple code in the course directory (in subdirectory Assignment 2) which will help you getting started with the GUI. There are three programs and after compiling them you should be able to run GameViewTest. This code was copied from Simon Lucas and you might or might not have come across this in last years Java lectures.
  • The program above does not allow you to interact with the system. It simply displays a screen filled with some squares. Here is a little routine that you can include in your code which calls a method (in this case nextMove) in certain intervals (defined by the variable time_interval):
// move currently active block at fixed intervals:
public void startTimer()
{
Timer timer = new Timer();


TimerTask task = new TimerTask()
{
public void run()
{
if (game_going)
{
nextMove();
repaint();
}
}
};
timer.scheduleAtFixedRate(task, 0, time_interval);
}

Commenting the Program

The program should contain brief comments indicating precisely what each method does and what each instance variable is used for. You should not write any comments stating what individual lines of code do; but in places it may be appropriate to state what a block of code does (e.g. received a mouse event).

Any code taken from elsewhere, or based on ideas that are not your own (e.g. from a reference book or website) should be clearly indicated as such both in comments and in your report.

The program should be structured appropriately and laid out neatly with consistent indentation.

In addition to comments in the program you should submit a short report (in PDF or Word format) that describes the structure and functionality of your system. I expect that this will be no more than one or two pages long. Feel free to include any further comments that explain shortcomings or additional features of your solution.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.