new Game(players, board)
The Game class
Parameters:
Name | Type | Description |
---|---|---|
players |
Player | Array | A list of players |
board |
Board | The game board |
Extends
Methods
(abstract) executeMove(player) → {void}
Execute the proposed move made by the player
Parameters:
Name | Type | Description |
---|---|---|
player |
Player | the current player |
Returns:
- Type
- void
getCurrentPlayer() → {Player}
Returns the current player
Returns:
- Type
- Player
hasValidMove() → {boolean}
A proposed move exists and it is valid
Returns:
- Type
- boolean
isDoubles() → {Boolean}
Checks to see if the first two dice are the same value
Returns:
- Type
- Boolean
(abstract) isGameOver() → {boolean}
Check the Game State to see if a player has won the game
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 |
Returns:
- Type
- boolean
nextPlayer() → {void}
Switch to the next player
Override to provide more logic on determining the next player
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 |
Returns:
- Type
- boolean
randomizeCurrentPlayer()
Set the current player to a random player
Used to decide who goes first at the beginning of the game
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) |
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 |
setProposedMoveDestination(tile) → {void}
Set the destination for a proposed move
Parameters:
Name | Type | Description |
---|---|---|
tile |
Tile | the tile to move to |
Returns:
- Type
- void
setProposedMoveToken(token) → {void}
Set the token for a proposed move
Parameters:
Name | Type | Description |
---|---|---|
token |
Token | the token to move |
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 |
setTurnMap(turnMap)
Set the game's state machine
Parameters:
Name | Type | Description |
---|---|---|
turnMap |
TurnMap | the game's state machine |
submitMove(token) → {void}
Sets the last moved token for later reference
Parameters:
Name | Type | Description |
---|---|---|
token |
Token | Last moved token |
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 |
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 |
tokenClicked(token) → {void}
Event for when a token is clicked on
Parameters:
Name | Type | Description |
---|---|---|
token |
Token | the token that was clicked |
Returns:
- Type
- void
(abstract) tokenClicked()
Callback method from the view when a token is clicked
To be overridden by the subclass
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 |