CSSE 120 Final Python Project—Spring 2007-2008
Disclaimer: This is the second time we have assigned Tetris in Python. Some details may
still be vague and subject to change; we'll alert you when they do.
Project Requirements
The final project for the Python part of this course is to implement the game Tetris. Rules for the game are given below.
Your project must satisfy these core requirements:
-
You must design and implement a fully functional Tetris game including:
-
moving and rotating pieces
-
allowing only legal moves
-
detecting when the game is over
-
Your project must use a GUI for game play. (We'll provide lots of it, which you will modify.)
-
You must implement 8 classes, one per piece type plus one for the playing board. You will be required to use an object-oriented design.
-
All team members must
contribute to
and
understand
their project.
Most of the work on your project will be translating the rules provided into a functional design and implementation. If you are having trouble planning or getting started, get help. It is much better (and easier) to get help early and start off with a good plan than to try to hack a poor design into a semi-functional program in the final days before it is due.
Milestones
To make sure that you are on-track to complete your project, you must meet the following milestones. Each milestone will contribute to your overall project grade. Each milestone must be done
before
the specified class session.
-
Session 19 — UML Class Diagram Sketch: A neatly drawn UML class diagram showing the user-defined classes for your program including instance variables and methods. This does not have to be (and likely won't be) your final design, just your initial plan. To get you started on the right track, we're requiring your design to include classes for each of the pieces, like
Tee
(explained below), and a class for the playing board. You should ask yourself, "What instance variables need to go in
Tee? What operations must it support? What instance variables need to go in the playing board? What operations must it support?" as a start. The diagram can be hand-drawn or you may use a program to draw it. We
strongly
suggest that you draw your initial design on a whiteboard. Regardless of the way you choose to draw the diagram,
you must turn in a single plain white 8½ × 11 inch sheet of paper showing your final design.
This format is non-negotiable as we will be photo-copying your design.
-
Session 20 — Text-based version of piece motion.
You must demo this to your instructor before moving on to the GUI-based version. Also, make sure that you commit this version of your code and state clearly in your commit message that the text-based version is done.
Here are the instructions for checking your team project out from SVN:
-
From within Eclipse switch to the SVN Repository Exploring perspective.
-
Click the small Add SVN Repository button in the top edge of the SVN Repository view.
-
Add the repository location with the following URL:
http://svn.cs.rose-hulman.edu/repos/csse120-200830-team
XY
where
X
is your section number and
Y
is your team number as announced by your instructor.
-
Once you have successfully created the repository location, find the Tetris project within the repository. Right-click the project and choose
Check out...
-
Confirm the default options in the dialog.
-
Once the checkout is complete, switch back to the PyDev perspective.
-
Find the module
Tetris.py
within the Tetris project. Each team member should independently add his or her name to the comments at the top of the file. This involves each of you editing the file, so it requires careful use of SVN. Follow the steps below in one sitting. If you are interrupted during this process, repeat the steps:
-
Right-click
Tetris.py
in the Pydev Package Explorer view. Choose
Team→Update. This ensures that you have the most recent changes from your teammates.
-
Edit the comments in the file to add your name.
-
Save the file.
-
Right-click again on
Tetris.py
in the Pydev Package Explorer view. Choose
Team→Commit...
This shares your change with your teammates.
Follow this cycle of update-edit-commit whenever you make changes to your program.
-
Session 21 —
No class, due to Exam 2.
-
Session 22 — Game Finished, including enhancements (below)
Grading
Project grades will be based on both individual and group results. We will grade each project milestone, plus the final project program. Grading will include both the proper functioning of your program and an evaluation of your design, coding style, and documentation (including SVN commit messages). The grade will also depend heavily on what enhancements you add (see below).
Each team member will be required to complete an evaluation survey about his or her own performance and that of each of his or her teammates. We will use these surveys and our own observations to assign individual project grades.
About Tetris
Overview
Tetris is a one-player game in which pieces of various shapes fall from the top of the board, one at a time. The player can rotate the falling piece clockwise, move it left or right as it falls, or cause it to drop, until it stops by hitting a stationary piece. Once it does, then a new piece starts to fall. The goal of the game is to position the pieces so that complete rows (lines) are filled with pieces. This causes the row to disappear, the rest of the pieces above it to fall, and points to be scored. Play continues until there are stationary pieces at the top row of the board. The following picture is taken from
http://www.freetetris.org/.
There is an interesting discussion of the history of Tetris
here.
Rules
Terminology
-
The
playing board
is the whole playing area. It consists of 10 columns and 18 rows of grid
cells,
for a total of 180 cells. In it are an
active piece that is falling and can be moved, and the
landscape
(a group of stationary, de-activated pieces at the bottom of the
board). When the landscape contains a complete row of 10 cells, a
line
is completed, the line is
cleared, and the landscape
above the cleared line
slides
down.
Piece Types
There are 7 different pieces of various shapes. Note that each has the same area (4 cells). Pictured are:
-
MrChunky
(Alright,
square
is confusing,
block
is too vague, and Dr. Clifton likes crazy names. When
you
teach the class,
you
can pick the names. :) )
-
Bar
(looks like a line, but the name
line
is already taken).
-
Ell
(if you turn it upright, it looks like the letter L)
-
Jay
(the letter J)
-
Tee
(the letter T)
-
RightZig
(sitting down, the top is on the right)
-
LeftZag
(complementing the RightZig)
The centroid of each piece is marked with a dot. We use this centroid to mark the position of the piece.
Also,
the pieces rotate around this point (except MrChunky, who dosn't rotate).
Note that each piece above is shown in its default orientation, that is,
the orientation in which it starts
at the top of the playing board.
Initial Game Setup
-
The board has 10 columns and 18 rows.
-
All of the grid cells start empty.
-
One of the 7 pieces is chosen randomly, and is placed on the middle top of the board.
Game Play
In each time step:
-
The player can rotate the active piece clockwise, move it left or right, or cause it to drop instantaneously until it can move no more (unlike the online version above where the falling can be slowed again).
-
One may not be able to do all of these operations. For instance, if a piece is already touching the left wall, the player cannot cause it to move further left. Also, if rotating a piece would cause it to hit another piece or the wall, it is not allowed. Multiple moves are allowed, if the player can do them quickly.
-
If there is empty space below the falling piece, the piece falls (moves down) 1 square.
-
Otherwise, it has hit a stationary piece of the landscape. We then
check to see if one or more lines are completed. If so, we remove
the line and cause the rows above it to drop down. If not, we check to see if the game is over. The game is over when the landscape extends up to the top row.
To get a feel for gameplay, please play the version at
http://www.freetetris.org/
Suggestions
-
Plan first! Use top-down design and object-oriented design. Get help early if you need it!
-
You'll want to follow the
model-view
approach that Zelle uses in section 12.3. We'll provide you with lots of the GUI
during week seven, once you show us you can manipulate the pieces.
Enhancements
Once you are done with the basic version, you will be required to add some
enhancements. You will earn a higher grade for doing more challenging ones, and the more, the better.
Here are some suggestions, to get you thinking.
-
Keep track of how many lines are cleared.
-
Do advanced scorekeeping, such as awarding more points for clearing multiple lines at once.
-
Highlight a row as it is being cleared.
-
Add outlines to the pieces.
-
Add sound effects using the
winsound
Python library.
-
Display the next random piece to fall in an "on-deck" panel at the top of the screen.
-
Be creative: what's cool and challenges you?