Write the game Tetris. In Tetris, shapes with 4 blocks ("tet" = 4) fall into a
well. With the keypad, you can move the falling shape to the left and right.
With the 'a' key, you can rotate the shapes counterclockwise, with the 's' key,
you can rotate the shape clockwise. With the space key, you can put the block
into free-fall, dropping it rapidly into position.
There are seven shapes: a line, a square, a "T", two "L"'s, and two "Z"'s. The
L's and Z's have a "handedness" - that is, a left-handed L cannot be rotated to
superimpose with a right-handed L.
When you have filled a row on the board, you eliminate all the blocks in that
row. All of the blocks above that row shift downwards exactly 1 row. Generally,
if you eliminate n rows, the blocks in the rows above shift downwards
n rows. Your score improves the more rows you simultaneously eliminate.
The score in my game is as follows:
- 1 row = 1 point
- 2 rows = 4 points
- 3 rows = 9 points
- 4 rows = 16 points
Your game should get faster as the user eliminates lines. My program increases the drop
rate once for every ten lines that the user eliminates.
The game ends when the location of a new shape is already occupied by a previously fallen block.
I am providing some source code you may use. This code describes the geometry
of each of the seven blocks in all of their orientations. It also describes the
cells that each shape passes through during a rotation. I call these cells
When the user presses the right arrow key, you cannot move a block to the right
unless that motion is allowed (collision free); so 1) you check to see if you
can move a block to the right, and if so 2) then you move the block to the
Likewise, when the user presses 'a' or 's', you cannot rotate the block unless
that rotation is allowed. This means, checking to see if the cells for each block
in the alternate orientation are unoccupied. But what about the cells that the
shape "passes through" during the rotation? I have encoded the geometry of
those cells through which a block passes in any given rotation in an array of
GridPositions. I call these "forbidden" cells. If you would prefer not to use
forbidden cells in your program, you may leave them out. They do offer a
realistic feel to the game.
Here are some pictures of the shapes:
In addition to providing the source code above, I've also documented the process
I underwent in creating my version of tetris. I will share with you some of the
prototypes I wrote along the way. NOTE: You do not have to write any of these
prototypes if you do not feel like it. You should not turn in a set of
prototypes, only a single program.
Here is an example of how your program should behave and what it could look like:
Click on the applet to start the game.
Current High Score: Bryan, 200
Mail me a screenshot of your high score (disclaimer: you gain nothing by having the high score)
- A: Shapes fall. Keyboard control of shape motion and rotation. Shapes stack. The game-over condition is handled properly. The
shapes rotate properly. Full rows are eliminated. The space bar causes
free-fall. The game gradually speeds-up. The user gets a score for their
- B: Shapes fall. Keyboard control of shape motion and rotation. Shapes stack. The game-over condition is handled properly.
The shapes rotate properly. Row elimination is attempted, but buggy. The space bar causes free-fall.
The game gradually speeds-up.
- C: Shapes fall. Keyboard control of shape motion and rotation. Shapes stack. The game-over condition is handled properly.
The blocks rotate proplerly.
- D: Shapes fall. Keyboard control of shape motion and rotation. Shapes stack.
- F: Minimal display functionality: boundary drawn, some shapes drawn.
Post the applet on your website so that people can come by and play it.
Type the honor pledge at the top of your .java file(s) in a comment block.
Zip 1) your .java file(s), 2) your .class file(s), and 3) a text file with the URL of
your webpage where I can view your program into a single file. Name that file
<your onion>_pr05.zip. That's the name it should have on your computer.
Use blackboard to SEND your .zip file.