# CSE1030

## Lab 6

Tue Oct 29 and Thu Nov 14
Due: Mon Nov 18 before 11:59PM

## Introduction

The purpose of this lab is to partially implement the game Tetris. In this lab you will:

• create three interfaces
• create an abstract base class
• implement some concrete child classes

This lab looks long, but there is actually not that much code that needs to be written. Also note that the drawing of the blocks is performed in a very simplistic manner; a high quality implementation would use a different rendering method.

## Question: Tetris

The game Tetris is a puzzle game where the player can move and spin falling blocks of various shapes. The goal of the game is to stack the blocks without leaving any gaps between the blocks.

If you have never played Tetris before, there is an official Tetris website where you can learn to play.

There are 7 standard blocks (called Tetriminoes). The blocks are all defined on a square grid of size 3-by-3 or 4-by-4. In this lab, you are given a class `BlockGrid` that helps you describe the shape of a block. `BlockGrid` lets you get, set, and clear the individual grid positions. You specify the grid position using a pair of zero-based integer indices (the row index and the column index). The figure below shows the indices for each grid location on a 3-by-3 `BlockGrid`:

The shape of each block can be represented using a `BlockGrid` object. The figure below shows the `BlockGrid` for the S-block; the white grid locations have the value `false` and the green grid locations have the value `true`.

The player is able to spin a block into any of 4 possible orientations. The figures below show the 4 possible orientations for the I-block, J-block, and S-block. Column A show the blocks in their starting orientation. Column B shows the blocks after they have been spun once to the right. Column C shows the blocks after they have been spun again to the right. Column D shows the blocks after they have been spun again to the right. Spinning the blocks once more returns the blocks to Column A. If the player spins the blocks to the left starting from Column A, then the orientations are given by Column D, then Column C, then Column B, returning to Column A.

The Tetris playing field is typically a grid with 20 rows and 10 columns. The location of a block on the field is given by the coordinates of the top-left corner of its grid. The image below shows a J-block with position `(6, 14)` on the playing field.

For this lab you will implement three blocks: `IBlock`, `JBlock`, and `SBlock`. All Tetris blocks have three essential features: (1) they can be drawn on the playing field; (2) they can be moved; (3) they can be spun. There are elements of the game that can be drawn, but not moved or spun (such as the border of the playing field). Some versions of Tetris have drawable elements that can be moved but not spun (such as the climber in the Field Climber mode of Wii Tetris Party Deluxe). To implement these features, you will create three interfaces: `Drawable`, `Movable`, and `Spinnable`. Finally, there is information needed for every type of block such as the location of the block on the playing field, the color of the block, and the shape of the block; this information can be managed by an abstract base class `Block` that all blocks will extend. The relationships between the interfaces and classes are shown in the following UML diagram:

The APIs for all of the classes and interfaces associated with this lab can be found here:

Pay attention to the package names! All of your classes must be in the package `cse1030.games.tetris`

You are provided with a partial implementation of `Block`, a Jar file containig the complete implementations of `BlockGrid`, `IPoint2D`, and `SimpleDrawing4`, and a test program:

The test program drops random blocks from the top of the playing field. You can move and spin the blocks (but not fast drop or stack the blocks) using the keyboard. The controls for the tester are as follows:

• J: move left
• L: move right
• I: spin left
• K: spin right
• S: stop/start the block falling
• Q: quit

You can see what the tester should do by running the following program in the CSE Prism lab:

```java -jar /cse/dept/www/course/classpath/1030/TetrisTest.jar
```

```submit 1030 L6 Drawable.java Movable.java Spinnable.java Block.java IBlock.java JBlock.java SBlock.java