Skip to content

Instantly share code, notes, and snippets.

@tigarcia
Created December 14, 2016 01:07
Show Gist options
  • Select an option

  • Save tigarcia/17ff24b3737021d743eccc7f5cad7be0 to your computer and use it in GitHub Desktop.

Select an option

Save tigarcia/17ff24b3737021d743eccc7f5cad7be0 to your computer and use it in GitHub Desktop.
OOP Tetris Outline

Tetris

The goal of the application is to create a javascript version of tetris that uses object oriented programming to solve the problem.

Requirements

As a user, I should be able to:

  • Start the game
  • get a random falling shape every x seconds
  • rotate the shape
  • move the shape left, right, down
  • pause the game
  • see the next shape that will fall
  • clear complete lines from the board (no spaces across a row)
  • keep track of the number of lines cleared
  • recognize when the player has lost the game (ran out of space)

Related Functionality

  • General game play
    • Start the game
    • pause the game
    • random falling shape
  • Shape
    • rotate
    • move left, right down
  • Grid
    • Positioning on the board
    • ran out of space

Tetris OOP Classes

  • Grid - The 2d grid of squares that a tetris shape moves through. Can check for lines that should be cleared and clears lines. Can also check for a collision given a tetromino
    • Has: linesToClear, addToGrid(tetromino), checkCollisions(tetromino), clear, hasLost
    • Responsible for drawing itself and any squares that have collided
  • Point - 2D point that saves x and y
  • Shape - Composed of an array of points and a color for the squares
    • Responsible for finding all points that are on the bottom of the shape
  • Tetromino - The tetris game piece. Composed of a shape. Has a factory that randomly generates a tetromino.
    • Has: move, rotate
    • Responsible for drawing itself on the screen before it becomes part of the grid
  • Tetris - Handles starting the game, pausing the game, handling key presses for moving the falling tetromino. Keeps track of next shape
    • Has: checkCollisions, newFallingTetromino, play, pause
    • Responsible for calling draw on grid and falling shape
@elvisisvan

Copy link
Copy Markdown

Great outline👌🏻 thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment