new Game(players)
Creates a new UNO game.
Parameters:
Name | Type | Description |
---|---|---|
players |
Array.<string> | Array of players' name. |
Members
-
discardPile :Array.<Card>
-
Array of cards in the discard pile of the current round.
-
drawPile :Array.<Card>
-
Array of cards in the draw pile of the current round.
-
players :Array.<string>
-
Array of players' name.
-
roundConfig :RoundConfig
-
The configuration of current round in the game.
Methods
-
callUno(playerId)
-
Calls 'UNO' for the specified player after playing their penultimate card to avoids penalties and warns other players.
Parameters:
Name Type Description playerId
number The index of the player who will calls 'UNO'.
-
draw(amountopt, playerId)
-
Draw a specified amount of cards from the draw pile to the specified player.
Returns an array of cards that drawed.Parameters:
Name Type Attributes Default Description amount
number <optional>
1 The amount of the cards to be drawed.
playerId
number The index or the name of the player.
-
endTurn()
-
End current player's turn.
-
getPlayerCards(playerId) → {Array.<Card>}
-
Returns an array of cards that belong to the specified player.
Parameters:
Name Type Description playerId
number The index of the player in the current game.
Returns:
Array.<Card> -
getPlayerCardsByName(playerName) → {Array.<Card>}
-
Returns an array of cards that belong to the specified player.
Parameters:
Name Type Description playerName
string The name of the player.
Returns:
Array.<Card> -
isPlayable(cards) → {Card|Array.<Card>|boolean}
-
Checks if the specified cards is playable.
If the subject is a single card, returns the card if playable.
If the subejct is an array of cards, returns an array of playable cards.
Otherwise returnfalse
. -
newRound(startingPlayer) → {RoundConfig}
-
Initialize a new UNO game round.
Parameters:
Name Type Default Description startingPlayer
number 0 The index of the first player to play in the round.
Returns:
RoundConfig -
play(cardId, coloropt, playerIdopt) → {Card}
-
Play a card; Put the played card into the discard pile.
Automatically trigger end current turn if playing action cards. Returns the played card.Parameters:
Name Type Attributes Default Description cardId
number The index of the card in the player's cards that will be played.
color
string <optional>
null The color for the next turn if the player plays wild card. You can omit this parameter by providing
null
instead.playerId
number <optional>
The index of the player, default to the index of the current player in turn.
Returns:
Card