Due Friday, December 10th, 2010 at 11:59:59pm; submissions allowed until Sunday, December 12th without late penalty.
For this assignment, your task will be to write your own game using the Java Swing GUI framework.
However, it would be cruel to ask you to write a game completely from scratch; even experienced Swing programmers start new programs by copying existing code, or by using a tool to automatically generate some code to start with. So, we've provided you with a very simple example game that you can use as a starting point if you like.
Our sample game is a very stripped-down version of Pong, the very first video game that ever was. There is a ball that bounces off the edges of the screen and a rectangular paddle, and you can move the paddle using the arrow keys. It doesn't do anything fancy like allow multiple players or keep score, but even such a simple program already demonstrates a lot of the key concepts you will need to make your own game. You should take a tour of the code provided before beginning to write your own game, though you are not required to use any of this in your own game. You can grab all the files together in SwingGame.zip.
Pong.java: This file contains a class with a simple
mainmethod, the basics needed to get a window up and running, and instructions to put a Reset button and a
PongCourtin the window.
PongCourt.java: This is where the real action happens. The
JPanelon which the current game is displayed. It handles user keypresses, and sets up a
Timerto generate an event every 35 milliseconds so that the screen can be redrawn. It also has a
Paddleand tells them to update themselves before redrawing the screen.
GameObjectis an abstract base class which collects behavior common to the different objects in the game. A
GameObjectis a rectangular object which has a position and a size, can be moved, knows how to draw itself, and knows how to test whether it is touching another
GameObjectwhich looks like a rectangle and can be moved from side to side.
GameObjectwhich looks like a circle and bounces off of the walls.
You now have a choice: you may extend Pong, or create your own game. If you choose to extend Pong, you can earn a maximum of 70% credit, but we have provided a detailed outline of what you need to implement. If you choose to create your own game, the sky is the limit, and we will grade the game in part on its creativity and playability. Note that going through the exercises on extending Pong is an excellent way to start, even if you ultimately choose to morph it into your own game!
For this assignment, we strongly recommend that you make snapshots of your code periodically. Each time you get a new feature working, create a folder with the date and/or a descriptive title in its name (so you can remember which version is which if you have multiple snapshots), and copy all of your files into it. If your next big feature causes huge problems (or if the deadline arrives!), you'll have a way to recover a working version of your game to submit. Otherwise, you may find yourself a half hour before the deadline with a broken game that doesn't compile, and only half a head of hair (having pulled out the rest). As with previous assignments, if it doesn't compile, you get zero credit.
There are a few features Pong is required to have. A very good way to start is to add these features to the simple Pong game. Then, if you wish, you can continue by changing it into your own game. To get 70% credit, you must implement four features: Instructions, Two-player ability, Updating score, and your choice of any one additional feature from the list below (and we suggest that you attempt to implement them in that order).
Pongclass as a model.
You're on your own! (Well, not quite; see below.) Your game will be graded partly on the required features, and partly on creativity and how much fun it is to play! That's right, to grade this assignment we are going to have a big party where we all sit around and play games projected on a giant screen. It's a rough life.
There are still two absolute requirements:
Of course, coming up with a fun, original idea for a game can be hard; here are some suggestions. Feel free to implement any of these suggestions, or use them for inspiration. Of course, you should also feel free to completely ignore them and come up with your own, unique, super-awesome game. If you are wondering if some other combination of features will yield full credit, please post your questions on the BB. Extra credit may be given depending on how many extra features are included. Also, if you choose to make your own game, keep in mind how much work should go into it. Games such as Tic-Tak-Toe or Connect 4 are too easy to yield full credit.
Modifying the simple provided Pong game into a version of the classic game Breakout is a good option. As in Pong, you lose (a life) if the ball touches the edge of the screen behind your paddle. There is also a pattern of rectangular blocks; when the ball hits these blocks, they disappear. You win if you can cause all of the blocks to disappear, so you have to keep bouncing the ball off your paddle.
GameObject.intersectsmethod we have provided to test whether two
GameObjects are touching each other.
PongCourthas an example invocation of this method.
A well-done, bug-free version of Breakout with a score that updates as it changes, both mouse and keyboard control, multiple lives (with a display showing how many are left that updates appropriately), and at least three different colors would be worth full credit (though this is not the only combination of features worth full credit).
GameObjectclass may come in handy here for representing the player's ship, the aliens, and even the bullets!
A well-done, bug-free version of Space Invaders with a kill count and bullet count that update as they change, both mouse- and keyboard- controls, and aliens that look vaguely like aliens (or that look like anything other than rectangles!) would be worth full credit (though this is not the only combination of features worth full credit).
A well-done, bug-free version of Reversi with win counts for each player that update as they change, both mouse and keyboard control, and color graphics would be worth full credit (though this is not the only combination of features worth full credit).
Tetris is another classic game. Tetris is played on a grid; contiguous groups of four blocks drop from the top of the screen, stopping when they hit the bottom of the screen or when they hit the top of a previously dropped block. Any rows of the grid which are entirely filled with blocks at this point disappear; the game ends when a group of blocks can't enter the grid.
A well-done, bug-free version of Tetris with one-move lookahead that pauses when clicked, has a line count that updates as it changes, and has at least three colors would be worth full credit (though this is not the only combination of features worth full credit).
Battle City is another classic game. Here, we are asking you to implement a simple 2 players mode of Battle City. The battle city will consist of only walkable areas and bricks, and each player should try best to protect their own camp as well as to destroy another player's camp. Initially, the walkable areas and bricks should be randomly generated in between the two players' camps, and the camps should be wrapped by one layer of bricks. Please refer to the original Battle City game: Wikipedia. A compilable, well-done, bug-free version of Simplified Battle City for 2 players will earn full credit. Other cool playable features, including adding trees/water/ice into the city, may earn extra credit.
You must submit a single archive called
The archive must contain all your sources; for those of you submitting
projects that use additional libraries, the archive must also contain the
.jar files. If your project needs data to
run—game level information, images, sounds, etc.—the archive
must contain these as well. There must be a public class named
Game with a public
To run your game, we will execute the following command sequence from a terminal on the Moore 100A computers in a directory containing only your submitted archive; you may test there to make sure that you've created your submission correctly.
unzip *.zip javac *.java && java Game # we will add a classpath argument that # includes any bundled .jar files
If your code doesn't compile, that second command will never get to your game... no-compile, no-credit!