UNO
Uno game implemented in JavaScript
Installation
$ npm install uno-engine
Usage
Import
JavaScript
const Game = ;
TypeScript
;
New Game
; // maximum 10 players with unique names; // you can add your own rules (see https://github.com/danguilherme/uno/tree/v0.1.0-alpha/src/house-rules); // initialize the game
After starting a new game, the first card will be randomly chosen, hands of 7 dealt, and a player will be randomly chosen to go first.
Player Properties
; // player whose turn it is; // array of `Card` objects; // get player by name; // get the exact card in the player's hand
Card Properties
; ; // current card in-play; // get the index of the card color: 0 to 3 // (WILD and WILD DRAW FOUR will not have this property set)Colors; // get the name of the color: RED, BLUE, GREEN, or YELLOW // Card value; // get the index of the card value: 0 to 14Values; // get the name of the card: // 0-9, SKIP, REVERSE, DRAW_TWO, WILD, or WILD_DRAW_TWO // Get card from value/color strings;;; // Set WILD or WD4 color; // get args from player input; // get exact WILD/WD4 in player's handcard.color = Colors; // set color of WILD/WD4 in hand // Get Card from args function;
Game Loop
try catch e game.draw; // draw a card for the current player try catch e // Yelling UNO!game.uno; // game.currentPlayer is yelling UNO!game.uno"Player 1"; // Other than current player yells UNO // - If the yelling player is the current player, // and they have 2 or less cards, he is just marked as "yelled" // - If the yelling player has more than 2 cards, // the game searches for someone with 1 card that did not yell "UNO!", // and make him draw 2 cards. If there's no one, // the yelling player draws instead.
Game Events
game.on'beforedraw',; game.on'draw',; game.on'beforepass',; game.on'beforecardplay',; game.on'cardplay',; game.on'nextplayer',
Game Rules
Check all the official game rules.