![]() |
CSE 143 Autumn 2000Homework 4Due:
|
You will be implementing the game Tetris. If you don't know the game check out www.tetris.com. Tetris is a deceptively simple, completely addictive puzzle game. Small pieces fall from the top of the Grid to the bottom. The pieces are comprised of 4 squares arranged into 7 different patterns. Players must rotate the pieces as they fall and fit them together to complete lines. When the player fills an entire line with blocks, that line is removed from the screen. If the player cannot complete lines, the blocks will eventually fill to the top of the screen and the game ends.
The purpose of this assignment is to gain experience with the following new concepts:
This program plays the game of Tetris using graphics and keyboard input. Starter code has been provided and you will add code to it to make a complete game. A tetris piece composed of 4 contiguous squares falls from the top of the grid. The piece can be moved left, right, or down as well as rotate clockwise. When the piece lands on the bottom of the grid or another piece it becomes frozen, that is to say, a part of the grid, and then another piece is created. If an entire row fills up with parts of different pieces, then the entire row is removed and the rows above it are moved down. Play continues until the pieces pile up to the top and a new piece is created on top of already frozen pieces.
The starter code provided for you simply creates a single L-shaped piece that can move downwards. You will be enhancing this code in the Two Parts of the assignment.
Overview: In PART I, you will add the ability for the L-shaped
piece to move LEFT and RIGHT . In addition, you will
modify the game so that it will produce another piece once
the current one has stopped moving .
UpdatePiece
and IsGameOver
should
be examined, as they are the interesting functions of the
Game class.
Piece
needs to be able to move LEFT and RIGHT if the
corresponding keys are pressed. For this assignment LEFT
corresponds to pressing the letter 'j' and RIGHT the letter 'l'
on the keyboard. In addition, the piece should move DOWN if ' '
(space) is pressed (this will move it faster than it normally
falls). In order to handle key clicks, you will need to implement
the function handle_key
. In addition, you will
have to modify some member function of one of the provided classes
in order to get the correct behavior. Reading and understanding the
code will make it clear which class you need to change.
new_piece = new LShape(display,grid);
This part is due Wednesday/Thursday Nov 1st and 2nd.
This finished solution for PART I should work like this: Part I Solution
Overview: In PART II you will complete the game. You will need to add the ability for the piece to rotate. Then you will implement the removal of solid rows from the grid. Then, the biggest part, you will need to create the other 6 pieces.
LShape::Rotate()
function that is in lshape.h A piece should only rotate
if the grid squares that it would occupy are all empty and in addition
are all within the boundaries of the grid (i.e. greater than zero
and less than GRID_WIDTH). The currentPosition
data
member can be used to keep track of how rotated the piece is and
where to move it next.
Grid::CheckRows
. This function should look through the grid and determine if there is
a completely filled in row (a row of all non-EMPTY_SQUAREs). If such
a row is found, it should be removed and all the rows above it should
be moved down. All such rows should be found and removed in one
call to CheckRows
. You may find it useful to define
a couple of private functions to help. See figure. (Note that at this
point, you probably only have the L-shaped piece to work with. The
example below shows what can happen when the other pieces have been
implemented.)
Piece
class. In particular, you will need to figure out how to
initialize the pieces and how to rotate the pieces. This will
be similar to how the L-shaped piece was done, and, in fact, you may find
it helpful to start each new class by copying the code for a previous shape
and modifying it. The same boundary
checking should happen when rotating all of the other pieces.
Lastly, the pieces should be initalized in the
following orientations: The complete game is due Wed/Thurs Nov 15,16.
The complete solution looks like this: Tetris
When you've finished your program, turn in your code using these turning forms:
Print out the receipt that appears, staple it, and hand it in during quiz section.