14HW2Tetris (1)

# 14HW2Tetris (1) - CS108 Stanford Winter 2012 Handout#14...

This preview shows pages 1–4. Sign up to view the full content.

CS108, Stanford Handout #14 Winter 2012 Young HW2 Tetris Assignment by Nick Parlante For HW2 you will build up a set of classes for Tetris. This assignment emphasizes the basic Divide and Conquer strength of OOP design -- using encapsulation to divide a big scary problem into several slightly less scary and independently testable problems. Tetris is a large project, so the modular OOP design matters. This assignment is due at Midnight ending the evening of Monday January 30 th . Do not underestimate the difficulty of this assignment – it is much, much longer than HW1 was. For reasons that will become clear later, there is a theme of efficiency in this design. We are not just writing classes that implement Tetris. We are writing classes that implement Tetris quickly . For us old-timers who grew up before the popularization of Doom and Quake, Tetris is one of the coolest things around. Try playing it for 27 hours and see if you don't agree. If you play Tetris enough, you may begin to have Tetris dreams (http://www.sciam.com/article.cfm? articleID=0001F172-55DA-1C75- 9B81809EC588EF21, or just type "tetris dreams" into Google). Part A -- Piece There are seven pieces in standard Tetris.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 The Stick (also known as "the long skinny one") The L and its mirror L2 The S and its mirror S2 The Square The Pyramid Each standard piece is composed of four blocks. The two "L" and "S" pieces are mirror images of each other, but we'll just think of them as similar but distinct pieces. A chemist might say that they where "isomers" or more accurately "enantiomers" (note: I only looked that word up in an effort to make the handout more impressive.). A piece can be rotated 90 degrees counter-clockwise to yield another piece. Enough rotations get you back to the original piece — for example rotating an S twice brings you back to the original state. Essentially, each tetris piece belongs to a family of between one and four distinct rotations. The square has one, the S's have two, and the L's have four. For example, here are the four rotations (going counter-clockwise) of the L: Our abstraction will be that a piece object represents a single Tetris piece in a single rotation, so the above diagram shows four different piece objects.
3 Body A piece is defined by the coordinates of the blocks that make up the "body" of the piece. Each Piece has its own little coordinate system with its (0,0) origin in the lower left hand corner and with the piece positioned as low and as left as possible within the coordinate system. So, the square tetris piece has the body coordinates: (0,0) <= the lower left-hand block (0,1) <= the upper left-hand block (1,0) <= the lower right-hand block (1,1) <= the upper right-hand block In rare cases, a piece will not even have a block at (0, 0). For example, this rotation of the S… has the body: {(0,1),(0,2),(1,0),(1,1)} A piece is completely defined by its body -- all its other qualities, such as its height and width, can be computed from the body. We will measure the "width" and "height" of a piece by the rightmost and topmost blocks in its body. The

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 17

14HW2Tetris (1) - CS108 Stanford Winter 2012 Handout#14...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online