Simple Game
Simple framework for turn-based games played to points.
Support this project by donating on Gratipay.
Getting Started
Simple Game supports any number of players. Games are played to a number of points, optionally requiring a player to win by at least two points.
API
new Player(options)
Creates a new Player
instance.
options
(Object; optional): The options for initializing the player.- The options are completely arbitrary, to be used as a key/value store for any data you may want to track about the player.
var player = name: "Scott";
Player#addPoint()
Adds a point to the player's score.
player;
Player#addPoints(points)
Adds points to the player's score.
points
(Number): The number of points to add.
player;
Player#removePoint()
Removes a point from the player's score.
player;
Player#removePoints(points)
Removes points from the player's score.
points
(Number): The number of points to remove.
player;
Player#getScore()
Gets the player's score.
var score = player;
Player#getOption()
Gets an option for the player.
var name = player;
Player#setOption(option, value)
Sets an option for the player.
player;
Player#reset()
Resets the player's score to zero.
player;
Player events
score
: Emitted when a player's score changes. The score is passed as data.reset
: Emitted when a player's score is reset.
new Game(options)
Creates a new Game
instance.
options
(Object; optional): The options for initializing the game.maxPoints
(Number; optional; default:15
): The score needed to win the game.winBy2
(Boolean; optional; default:true
): Whether a player needs to win by at least two points.
var dominoes = maxPoints: 100 winBy2: false;
Game#addPlayer(player)
Adds a player to the game.
player
(Player): The player to add to the game.
game;
Game#getPlayers()
Gets the list of players, in turn order.
var players = game;
Game#orderedPlayers()
Gets the list of players, in order by score.
var players = game;
Game#reset()
Resets the game, setting all players' scores to zero.
game;
Game events
end
: Emitted when a player has won the game. The list of players, in order by score, is passed as data.reset
: Emitted when the game is reset.
License
Copyright Scott González. Released under the terms of the MIT license.
Support this project by donating on Gratipay.