Tetris. Informal description Tetris is a 2d computer game. It consists of an Matrix and we have...
-
Upload
jade-manning -
Category
Documents
-
view
214 -
download
0
Transcript of Tetris. Informal description Tetris is a 2d computer game. It consists of an Matrix and we have...
Tetris
Informal description
• Tetris is a 2d computer game. It consists of an Matrix and we have Tiles. One new tile is introduced at a time and enters from the top of the game area. For each ClockTick the whole Tile moves one Unit downwards.
• And the user can control the FallingTile by rotating and shifting.
• A FallingTile becomes inactive when it hits an occupied Cell or the bottom of the Area.
• A row is cleared as soon as all Cells in it are occupied. All the occupied Cells above it moves down one Cell.
• Game over when the pile of blocks hits the ‘ceil’ of the area
Definitions
• Cell = rendered square areao Cell.occupied = x E [0,1]o Cell.color = color codeo Cell.active = x E [false,true]
• Type Matrix = rectangular form which shape is dictated by Rows × Columns
• GameMatrix :: Matrix • Rows= <Row1,Row2,…Rown>• Columns= <Column1, Column 2,… Columnn>• Celli,j = (Rowi, Columnj) • Tile is a Matrix whose number of rows and columns are less
than or equal to the GameMatrix.• Tile = 1..* Cells. For all Cell1, Cell2, that are part of Tile this
holds: Reachable(Cell1,Cell2)
Definitions (ctd)
• Reachable(Celi,j,Cellm,n) = ((|m – i| =1 AND j = n) OR (|j – n| = 1 AND i = m)) OR There exists a Cellk,l such that IF Reachable (Celli,j, Cellk,l) AND Reachable(Cellk,l,Cellm,n) THEN Reachable(Celli,j, Cellm,n)
Definitions (ctd)
• Clock ticks form a series of equally distributed points in time .oSimplyfing assumption: ClockTicks at the
end of equal time intervals.• In that series: for each predecessor t1 of
each Tick t2 (if any) it holds that time of t1 < time of t2
• Clock tick = the base measure of time
Actions
• These actions must be initiated by the User input: o SL = moves a Tile one Cell to the left in the Areao SR = moves a Tile one Cell to the right in the Areao RL = rotates a Tile 90 degrees left o RR = rotates a Tile 90 degrees right
• Invariant: Each ClockTick the Tile moves down one Cell• Invariant: Each action results in an screen update
Rendering on screen
• Every cell is rendered as a square• A rectangle must represent the GameMatrix.
o Size of rectangle should be configurable -- so for instance it can be fullscreen
o Width and height of the GameMatrix are dependent upon each other, because of the constraint that the contained cells must appear as squares.
• The rectangle is populated by cells according to their row/column indexes.
Initial State / New Game
• Initial State: o GameMatrix doesn't have any inactive Cells.o A new Tile is generatedo Program starts to generate Clock Ticks.
End State / Game over
Program stops to generate Clock Ticks.Gives the user an option to start a new game, which brings the program in Initial State, or to exit the program.
New Tile
When a New Tile is generated, the highest Cell of the Tile is on the highest row of the GameMatrix, if the cells to occupy were not occupied before.Otherwise the game is over, which is the EndState.
The Cell positions of the Tile are marked as active within the GameMatrix.
Downward movement
• For each Clock Tick the falling Tile moves one Cell to the Bottom, unless the falling Tile is a StuckTile. In the latter case, a new falling Tile is generated.
• StuckTile is a Tile which has Cells that are on the same level as the lowest level of Area OR
• StuckTile is block which has Tile that are just one level higher than one or more Tile of an other StuckBlock.
Action: Shift left/right
Function MoveRight() For All active cells s in GameMatrix If cell[s.x-1,s.y].occupied = false flag = true else flag = false return For All active cells s Cell(s.x,s.y).active = false Cell(s.x-1,s.y).active = true
MoveLeft is the same, but replace all occurences within the function MoveRight of 'x-1' with 'x+1' excluding quotation marks.
Action: Rotate