Skip to content

Latest commit

 

History

History
264 lines (147 loc) · 12.5 KB

README.md

File metadata and controls

264 lines (147 loc) · 12.5 KB

Tetris Game

Purpose

Simple exercise of creating an architecture of a computer game. Tetris game is an easy use case as it has well defined rules.

In this example the following process is followed:

  • Define rules of the game

    Very important step. This is a definition of WHAT we want to achieve. What kind of product needs to be build.

  • Create requrements

    Also very important step. This is a list of architectural decisions that will define scope of work, limitations and restrictions. Any compromise that has to be made must be expressed here as a requrement. It is a contract between a customer and a provider. Each requirement has a tag and must be referenced in a design and later in source code. If the code does not reference any requirement, its existance should be questioned. This is also an input for validation to define test criteria and make sure the contract has been met.

  • Use Cases

    First step to understand functional requirements. It helps to analyse the product and define interactions between system components. At this step non functional requirements may be captured and the list of requirements have to be updated.

  • Sequence and Collaboration diagrams

    Visualisation of what happens in the system. More non functional requirements may be discovered here.

Table of Content

Game Definition

I want to write a game where different figures fall from the top of the screen to the bottom. One at the time. Player can shift the figures left and right and also can rotate the figure in both directions. If the player does nothing, the figure will advance one step down after some time. Once the figure is at the bottom, it cannot move anymore. Figure stays there. A new figure shows up at the top of the screen. By moving figures, player can control where the figures will be placed at the botom of the screen. Figures are made of blocks. Screen is made of lines, which are made of blocks as well. Once figures fill in a full line with blocks, that line is removed from the screen. Any remaining blocks above that line will drop one line down.

Game last as long as player can make lines to be removed so there is a space for new figures.

Blocks cannot overlap. So, the game is over when it is impossible to place a new figure on the top of the screen.

Requirements

Requirement Description
REQ_SinglePlayer There is a single player
REQ_Cmd Commands are: Translate Left, Translate Right, Translate Down, Rotate Left, Rotate Right.
REQ_NoPendingCommands Commands are not buffered. New command overwrites the previews one if that one has not be executed yet
REQ_LineOfBlocks Single line is made of blocks.
REQ_LineFull Line that has no empty spaces, that is, when is made of blocks, is removed from the screen.
REQ_ScreenSize Screen has fixed dimentions of 10 rows and 8 columns. Screen is made of lines.
REQ_BlocksDrop When line is removed from the screen, all the lines being above the removed line, are moved down. The most top line of the screen becomes empty.
REQ_FiguresType There is 5 defined figures in the game
REQ_MoveLimit Figure must not be placed outside borders of the screen. That is, figure cannot move left when is at the left border. Figure cannot move right when is at the right border. Figure cannot move down when is at the bottom of the screen.
REQ_FigureLifeTime Player looses a control of a figure that cannot advance down (is at the bottom of the screen). New figure is generated at the top of the screen.
REQ_BlocksNotOverlap Single block takes space. Figures are made of blocks. Two blocks cannot take the same space. This implicates that figures cannot overlap. This also implicates that the figures cannot move (translate or rotate) when the new position would overlap with any block of a line.
REQ_OnTimerCommand Translate Down command will be generated after 1 second if player does not input any command in that period.

Defined figures

  • Square

      O
    
  • BigSquare

      OO
      OO
    
  • Bar

      O
      O
      O
    
  • BarT

     OOO
      O
    

Use Cases

State Control

Player and timer trigger state changes. All state control happens in the main loop.

State Control

Time Progress

Requirements: REQ_OnTimerCommand

Timer event moves a figure only down. No rotation or shifting left or right.

Time Progress

Player Generates Input

Requirements: REQ_SinglePlayer

There is a single input. Input represents a player.

Player Generates Input

Class Diagrams

Overal Colaboration

Colaboration Diagram

Game Environment

Game Environment

Commands

Requirements: REQ_Cmd

Commands

Game Figures

Requirements: REQ_FiguresType

Game Figures

Sequence Diagrams

Start Program

Creating a game means to create screen, generate a random figure and start the timer.

Start Seqence Diagram

Restart Game

Restarting a game is to clear the screen and create a figure.

Restart Sequence Diagram

Successful Figure Rotation

Requirements: REQ_NoPendingCommands, REQ_BlocksNotOverlap, REQ_MoveLimit

Figure rotation succeeds when the figure does not overlap any blocks after a rotation. Any new command arriving during that process is dropped.

Figure Rotation Success

Failed Figure Rotation

Requirements: REQ_NoPendingCommands, REQ_BlocksNotOverlap, REQ_MoveLimit

Figure rotation fails when the figure overlaps other blocks after a rotation. Any new command arriving during that process is dropped.

Figure Rotation Failed

Successful Figure Translation

Requirements: REQ_NoPendingCommands, REQ_BlocksNotOverlap, REQ_MoveLimit

Figure translation succeeds when the figure does not overlap any blocks after a translation. Any new command arriving during that process is dropped.

Figure Translation Success

Failed Figure Translation

Requirements: REQ_NoPendingCommands, REQ_BlocksNotOverlap, REQ_MoveLimit

Figure translation fails when the figure overlaps other blocks after a translation. Any new command arriving during that process is dropped.

Figure Translation Failure

Move Down On Timer Tick Event

Requirements: REQ_BlocksNotOverlap, REQ_OnTimerCommand, REQ_MoveLimit

Time advances the figure down after a timeout. It is a regular translation process.

On Timer Move Down

Figure Life Time

Requirements: REQ_BlocksNotOverlap, REQ_MoveLimit, REQ_BlocksDrop

A new figure is created and will live until it cannot move down anymore. If it can move, either user can request the figure to move or timer tick can move it down.

Figure Life Time

Checking Figure Overlap

Requirements: REQ_BlocksNotOverlap, REQ_MoveLimit

A figure cannot move beyond the screen's dimentions and it cannot overlap with blocks already on the screen.

Checking Figure Overlap

Dropping Figure

Requirements: REQ_BlocksNotOverlap, REQ_MoveLimit, REQ_BlocksDrop

This is a use case when a figure cannot move down anymore. Its blocks are taken to fill empty gaps. In a case when a line does not have gaps (line is full), the line will be removed and all lines above are moved down. It is recursive operation from the most bottom line to the most top.

Drop Figure

Game Over

Requirements: REQ_BlocksNotOverlap

Game is over when a new figure cannot be created. This will be a case when checking overlap sequence returns error.

Game Over