Class: Game

Game

new Game()

Game
Source:

Members

hasStarted :boolean

Flag that shows if game has started
Type:
  • boolean
Source:

id :number

Unique ID of game
Type:
  • number
Source:

isOver :boolean

Flag that shows if game is over/has finished
Type:
  • boolean
Source:

moveSequence

Sequence number that is incremented each time a piece is moved during the game
Source:

previousState

Previous game state, used for undoing moves
Source:

previousTurnDice

Previous dice state, used for undoing moves
Source:

state :State

Board state
Type:
Source:

turnConfirmed :boolean

Flag that shows if the moves made in current turn have been confirmed by the player.
Type:
  • boolean
Source:

turnDice :Dice

Dice for current turn. Should be null if dice haven't been rolled yet.
Type:
Source:

turnNumber :number

Number (index) of turn
Type:
  • number
Source:

turnPlayer :Player

Show which player's turn it is
Type:
Source:

Methods

(static) createNew(rule) → {Game}

Create new game object with unique ID and initialize it. Game object is not saved in database.
Parameters:
Name Type Description
rule Rule Rule object to use
Source:
Returns:
- A new game object with unique ID
Type
Game

(static) diceWasRolled(game) → {boolean}

Check if dice has been rolled
Parameters:
Name Type Description
game Game Game
Source:
Returns:
- True if dice has been rolled (turnDice is not null)
Type
boolean

(static) hasMoreMoves(game) → {boolean}

Check if there are more moves to make
Parameters:
Name Type Description
game Game Game
Source:
Returns:
- True if there are any moves left to make
Type
boolean

(static) hasMove(game, value) → {boolean}

Check if a specific move value is available in movesLeft
Parameters:
Name Type Description
game Game Game
value number Move value to check for
Source:
Returns:
- True if specified move value is available
Type
boolean

(static) init(game, rule)

Initialize game object
Parameters:
Name Type Description
game Game Game to initialize
rule Rule Rule to use
Source:

(static) isPlayerTurn(game, player) → {boolean}

Check if it is specified player's turn
Parameters:
Name Type Description
game Game Game
player Player Specified player
Source:
Returns:
- True if it is specified player's turn
Type
boolean

(static) isTypeTurn(game, type) → {boolean}

Check if it is specified player's turn, but check by their piece type, and not player object
Parameters:
Name Type Description
game Game Game
type PieceType Player's piece type
Source:
Returns:
- True if it is specified player's turn
Type
boolean

(static) restoreState(game)

Restore game state from last snapshot - if player requested to undoing of moves
Parameters:
Name Type Description
game Game Game
Source:

(static) snapshotState(game)

Store current game state - in case the player wants to undo moves later
Parameters:
Name Type Description
game Game Game
Source: