CS 340 - Software Design

Spring 2006


MP 3 - Tetris

Due: Tuesday February 28, 2006 at 11:59 pm
Turnin will be disabled after 11:59 pm on Sunday 3/5/2006. Programs submitted before 11:59 pm on Thursday 3/2/2006 will receive 10% extra credit. Programs submitted before 11:59 pm on Tuesday 2/28/2006 will received 20% extra credit.

For this project, you are to write a Java application to play Tetris. A discussion of Tetris can be found at http://en.wikipedia.org/wiki/Tetris. Tetris is a real time game that continuously drops pieces (called Tetrominoes) on to a pile. The user is allowed to rotate and move these pieces left and/or right to fill up rows in the pile. When a row is completely filled, that row disappears and all pieces on top of that row fall down. Over time, the tetrominoes fall faster and the game is over when the pile reaches to the top of the playing area.

There are 7 different Tetrominoes. Each one is made up of 4 blocks. The 7 Tetrominoes are referred to as I, T, O, L, J, S and Z. These seven Tetrominoes are shown below:

The playing area is a grid of 20 rows and 10 columns. When a tetromino is dropped, it is added to the playing area at the top most row and will descend until it cannot go any farther down. The descent rate is controlled by a timer. Every time the timer "goes off", the tetromino will move down one row. This will continue until the time when the timer goes off and the tetromino can't go to the next row because it is either at the bottom row or it is on top of another tetromino. At this time, the tetromino will become locked in place and a new tetromino will be dropped. When the timer first places a tetromino on the bottom row or on top of another tetromino, the tetromino may be moved left or right (assuming there is room of it to move) or maybe even be able to rotate. Your program should randomly select the next tetromino from all seven different kinds.

At every 20th tetromino is dropped, the speed of the descent should increase. This means that you should shorten the timer's delay interval. The exact time of the delay interval will be left up to the programmer. You may wish to start with a value between a half second to a second and increase the speed by about a .02th of a second after every 20 tetrominoes.

Your program will need controls to move the tetromino left or right, rotate it left or right, drop the tetromino and pause the game. These controls are to respond to keyboard presses. Examples of key event programs can be found on the Java Example Page. These controls must not need any modifier keys (such as Shift, Control, Alt) to invoke the control. The exact keys used will be left to the programmer. You are also to add buttons that could activate these controls.

A few notes on the movements of the tetromino.

In addition to the playing area and the control buttons, your program is to display the following information

Your program will need a menu that will perform the following operations.

The Playing Area

The exact make up of the playing is up to you to determine. Here are some thoughts that I have.

The playing area could be make of a a grid of 20x10 labels. I have (at least) two images. One image to show an empty position in the grid. The other image to show an occuppied position in the grid. A position may be occupped by the current falling tetromino or was part of a previously fallen tetromino. As the current tetromino falls, moves, rotates, etc., the images contained in the labels in the grid change to reflect the falling, moving, rotating tetromino. Each tetromino will take up 4 different positions in the grid. Here are some program that I was using to mess around with this idea.

That uses these image files. Here are a list of images that could be used for this program.

Another was is similar to the previous idea, but to draw in a JPanel instead of using JLabels and images. This idea doesn't use images, but requires that the programmer keep track of the coordinate positions of pixels on the screen and to draw/redraw the pixels when needed.

Gravity

There are two ways to handle the falling of blocks that are on top of row when it gets cleared. One way is to just move all of the blocks down by the number of rows that were cleared. The other way is to have the blocks fall until they land on top of another block. The Wikipedia page on Tetris talks about both of these options. They call the first "naive gravity" and the second "flood fill". The first one is easier for the programmer, while the second makes the game easier for the player. You may use which ever you wish.

However for 10 pts extra credit, you can implement both forms of gravity and have a menu option that allows the user to switch between the two forms of gravity.

Submission of the Program

Your program is to be submitted electronically via the turnin command on the LINUX machines. The project name for this is mp3. All programs are expected to be written in good programming style.

Turnin your program electronically using the "turnin" command from your CS account as follows:

turnin -c cs340 -p mp3  [your project directory]
where the [your project directory] is the directory name under which you have all your files related to this programming problem. The turnin command will automatically compress the data under your directory, so there is no need to do the compression by yourself.

Notice you can only invoke turnin command on the Linux machines in the lab or after logging into the server machine oscar.cs.uic.edu.

If you want to verify that your project was turned in, look in the turnin directory for a file with your userid. For instance for this project, from your CS account you would type:

turnin -c cs340 -p mp3 -v

Note that you can execute turnin as many times as you would like, up until the program deadline when turnin will be disabled for this project. Each time you execute turnin for a project, you overwrite all of what you had turned in previously for that project. It does not work in an incremental way.

CS 340 - Fall 2005