Class: Game

Game

new Game(players, board)

The Game class
Parameters:
Name Type Description
players Player | Array A list of players
board Board The game board
Source:

Extends

Methods

(abstract) executeMove(player) → {void}

Execute the proposed move made by the player
Parameters:
Name Type Description
player Player the current player
Source:
Returns:
Type
void

getCurrentPlayer() → {Player}

Returns the current player
Source:
Returns:
Type
Player

hasValidMove() → {boolean}

A proposed move exists and it is valid
Source:
Returns:
Type
boolean

isDoubles() → {Boolean}

Checks to see if the first two dice are the same value
Source:
Returns:
Type
Boolean

(abstract) isGameOver() → {boolean}

Check the Game State to see if a player has won the game
Source:
Returns:
Type
boolean

(abstract) isValidMove(token, oldTile, newTile) → {boolean}

Determines if it is valid to move the given token to the new tile
Parameters:
Name Type Description
token Token token to place or move
oldTile Tile the previous token location (could be null if token not on board yet)
newTile Tile the new token location
Source:
Returns:
Type
boolean

nextPlayer() → {void}

Switch to the next player Override to provide more logic on determining the next player
Source:
Returns:
Type
void

(abstract) playerDidWin(player) → {boolean}

Evaluates the current state of the game and determines if a player won
Parameters:
Name Type Description
player Player the current player
Source:
Returns:
Type
boolean

randomizeCurrentPlayer()

Set the current player to a random player Used to decide who goes first at the beginning of the game
Source:

rollDice(numberOfDice, sides)

Roll the dice Dice are represented as an array of ints stored in the state
Parameters:
Name Type Description
numberOfDice int The number of dice to roll
sides int How many sides should be on the dice (defaults to 6)
Source:

sendMessage(message) → {void}

Method to broadcast a message out to the other components
Parameters:
Name Type Description
message string Message to send
Inherited From:
Source:
Returns:
Type
void

setMoveType(moveType)

Set the move type for this game
Parameters:
Name Type Description
moveType string The move type. See ttConstants
Source:

setProposedMoveDestination(tile) → {void}

Set the destination for a proposed move
Parameters:
Name Type Description
tile Tile the tile to move to
Source:
Returns:
Type
void

setProposedMoveToken(token) → {void}

Set the token for a proposed move
Parameters:
Name Type Description
token Token the token to move
Source:
Returns:
Type
void

setTurn(turnMap)

Method to set turnMap of the game once it is created This is required!
Parameters:
Name Type Description
turnMap Turn A turn object to be used by the game
Source:

setTurnMap(turnMap)

Set the game's state machine
Parameters:
Name Type Description
turnMap TurnMap the game's state machine
Source:

submitMove(token) → {void}

Sets the last moved token for later reference
Parameters:
Name Type Description
token Token Last moved token
Source:
Returns:
Type
void

subscribe(callback) → {void}

Method to subscribe to messages
Parameters:
Name Type Description
callback func A callback method to pass the message to
Inherited From:
Source:
Returns:
Type
void

tileClicked(tile) → {void}

Event for when a tile is clicked on
Parameters:
Name Type Description
tile Tile the tile that was clicked
Source:
Returns:
Type
void

(abstract) tileClicked(tile)

Callback method from the view when a tile is clicked To be overridden by the subclass
Parameters:
Name Type Description
tile Tile the tile object that was clicked in the view
Source:

tokenClicked(token) → {void}

Event for when a token is clicked on
Parameters:
Name Type Description
token Token the token that was clicked
Source:
Returns:
Type
void

(abstract) tokenClicked()

Callback method from the view when a token is clicked To be overridden by the subclass
Source:

updateState(message)

Method to call from the view to update the game state
Parameters:
Name Type Description
message string A string saying which state to transition to
Source: