board.js - addyh/tetris GitHub Wiki
Board Class
- Properties:
Drop timer variables:
* this.lastTime
* this.dropCounter -- The piece will drop when dropCounter reaches dropInterval
* this.dropInterval -- How often a piece should drop (milliseconds)
Keyboard and limit vars:
* this.downFor -- How long they've been holding an arrow key
* this.lowerLimit -- Bottom limit of the board (in px)
* this.rightLimit -- Right limit of the board (px)
Difficulty vars:
* this.difficulty -- Easy, Med., or Hard
* this.diffColor -- green, orange, or red
Score vars:
* this.best -- Current user's best score
* this.score -- Current score
Game state vars:
* this.gridOn -- Show the grid? (always true now)
* this.gameStarted -- Has the game been started?
* this.gameOver -- Is the game over?
* this.matrix -- The entire board (all the stacked pieces)
* .pos - .x, .y -- The location of a block
* .color - .r, .g, .b -- The color of a block
* .value - 1 or 0 -- Is this block used or empty?
- Methods
-
deleteRow(Int row)
- Go through each row, starting at the full one, up to the top
- Moving each row down by one
- By changing its attributes to the one above it
-
checkIfRowsFull()
- Go through each row, each column
- Until we get to a FULL row (all 1 values)
- Call deleteRow() on that row
- Then recursively check for more full rows, until there are no more
-
addPiece(Piece p)
- First, check if the game is over
- If it is, set gameOver = true
- Otherwise, go through every element in the piece (4x4)
- And if its value is 1, save its state to the board.matrix
- Finally, call checkIfRowsFull() to clear any full rows
- First, check if the game is over
-
draw()
- Draw the entire board
- Go through every element of the entire board.matrix (gridHeight) x (gridWidth)
- If the value is 1, draw the box (gridSize) x (gridSize)
-