Updated 2/7 (extended due date, updated discussion of design/implementation)
Due: Friday, February 15th by 11:59 PM
Your task is to write a simple video game. I suggest making the game similar to Space Invaders(TM), although if you want to do a different kind of game, see me to discuss your idea.
The main goal of the assignment is to become proficient programming in Java, and specifically to be able to confidently use object-oriented language features such as classes, inheritance, and polymorphism. A secondary goal is to learn about the Java API (the built-in classes and methods in Java).
Download CS201_Assign1.zip and import it into your Eclipse workspace. (File->Import...->General->Existing Projects into Workspace->Archive File).
The code contained in this project is intended to give you a useful starting point: when you run the main method of the Invaders class (right-click Invaders.java in the Package Explorer and choose Run As->Java Application), you will see a window containing a red triangle, which is the player ship. You can use the left and right arrow keys to move the ship.
The starting code contains a number of classes:
Invaders is the class representing the game's main window, and contains the main method of the program
InvadersPanel is a class representing the rectangular screen region in which the game's graphics are displayed)
InvadersGame is an interface defining the methods which implement the logic of the game
InvadersGameFactory is a class responsible for creating a new InvadersGame object when the game is started
MyInvadersGame is the concrete implementation of InvadersGame, and contains the actual game logic
Sprite represents a single visual object (player ship, enemy ship, missile, etc.) shown on the screen
PlayerShip is a subclass of Sprite representing the player ship
By reading the comments in each class, you should be able to get a sense of how each class works.
Please feel free to modify this code in any way you see fit. If you don't want to base your game on the starting code, that is perfectly fine, too.
Assuming that you choose to implement a Space Invaders style game, the minimum requirements are:
For extra credit, you can implement features such as
In addition to the functional requirements, your program must use classes and objects to represent game objects (the player ship, enemy ships, missiles, etc.) 20% of your grade will be based on how well you use classes, objects, and methods to implement the game.
A good way to determine what classes and methods you need is to use textual analysis. This means brainstorming words and phrases that describe concepts involved in the problem you want to solve. Here are some example terms that you might think of for a Space Invaders game:
check for collision
The noun phrases are candidates to become classes, and verb phrases are candidates to become methods.
Sometimes, multiple classes have common behavior. For example, the player ship, an enemy ship, and a missile are all things that move. Therefore, each class might need to have a method called move. Another common feature of these types of objects are that they will need to be drawn on the screen. So, each class should support a draw method. Finally, all of these types of object have the ability to "take a turn" at regular intervals (every time another frame of the animation needs to be drawn). So, each class should support a takeTurn method.
The fact that each class represents a thing that can move, draw itself, and take a turn suggests that there is something in common among each of these classes. For this reason, we should define a superclass called Sprite, and have classes PlayerShip, EnemyShip, and Missile each inherit from (extend) Sprite. That way, anywhere in the program we need to handle a "thing that can be moved, drawn, and which can take a turn", the code can refer to Sprite objects rather than having to separately handle PlayerShip, EnemyShip, and Missile objects.
The starting code follows the design described above: the PlayerShip class inherits from the Sprite class. (You'll need to add EnemyShip and Missile classes.)
Since the player ship, enemy ships, and missiles are all Sprites, the MyInvadersGame class has a field called spriteList which is an instance of the Java LinkedList class. The LinkedList class works in much the same way as the ArrayList class we discussed in class. The purpose of spriteList is to keep track of all of the Sprite objects that exist in the game. You can see the spriteList being used in the renderScene and updateScene methods in the MyInvadersGame class.
The java.awt.Graphics class defines a number of methods that you can use to draw two-dimensional graphics in a window. You can read about the methods supported by this class by looking in the Java API Documentation. Click on the java.awt package in the upper left frame, and then click on the Graphics class in the lower left frame.
The draw method of the PlayerShip class shows how to use the setColor and fillPolygon methods of the java.awt.Graphics class to draw a solid red triangle.
Note that the origin (0,0) is at the upper-left of the window. X coordinates increase from left to right, and Y coordinates increase from top to bottom.
To submit, first export your project by right-clicking on the name of the project (CS201_Assign1) in the Package Explorer, and then choosing Export->General->Archive File. Save the project as a zip file. Upload the zip file to the Marmoset server as Project 1:
You should have received your Marmoset username and password in an email.