Browse Games Read the Docs
Log In / Sign Up

War - The classic card game

All Cards - See that all cards are displayed dev-test

Full Screen - Preview a full screen game with animation dev-test

Game specification object

Contains all the information relating to a specific game: Metadata, data structures, methods and presentation.

Predefined fields are prefixed with $ to differentiate them from custom fields, which are signified by placeholder text wrapped in <>.


Hint: hover over the blue text.

$numberOfPlayers: Number= 1..4 (default: 1)
$session:
$schema:
$deck: 'Deck'
<variableId>: (optional) String= either 'Stack', 'Spread', 'Cell', 'Deck', 'Number' or 'Boolean'
...
$onStart: (optional) Function this=session
$onEnd: (optional) Function this=session
$methods:
<methodId>:
$do: Function this=session
$guard: (optional) Function this=session
$trigger: (optional) Function this=session
...
$player:
$schema:
<variableName>: (optional) String= either 'Stack', 'Spread', 'Cell', 'Deck', 'Number' or 'Boolean'
...
$ui:
$cardSize: String= either 'small', 'medium' or 'large' (default: 'medium')
$components: [
$type: String= either 'CardList', 'Button' or 'Html'
$position:
$origin: String= either 'tr', 'tc', 'tl', 'cr', 'cc', 'cl', 'br', 'bc' or 'bl' (default: 'bl')
$x: Number (default: 0)
$y: Number (default: 0)
$onAction: (optional) String - must match some <methodId>
$rotate90: Boolean (default: false)
$content: String (Html)
$src: String - must match some <variableId>
,
...
]

Session context object

A session context object is created for every game session.

Every custom function that is defined in the game specification object will be called at the approriate time with the session context object bound to this (or @ in coffeescript).

Predefined fields are prefixed with $ and are detailed in the adjacent table.

The custom session variables that were defined in the game specification object are also available as fields.

FieldDescription
$playersan array referencing the current participating players. Its values contain the variables defined for each player in the game specification object
$log(str)delegates to console.log
$endGame(status)immediatly ends the game

CardList API

Crds are always part of a basic data structure called CardList.

Its methods are are detailed in the adjacent table.

Sub types

CardList has 4 sub types:

Spread
all cards are accesible given that they are facing up
Stack
only the top card value is accesible given that it is facing up
Cell
contains at most one card
View
this is the type of the CardList returned by one of the following methods: at, last, top, first, bottom, or view.
cards do not actually move when a View is the target of card insertion
MethodsDescription
size()returns the number of cards in the list
at(start,end=start+1)returns a view containing all the cards from start to end indices
last(num=1),
top(num=1)
both return the last num in the list. (same as: at(size()-num,size()))
first(num=1),
bottom(num=1)
both return the first num in the list. (same as: at(0,num))
view()same as at(0,size())
insert(other,position)insert all the cards from other CardList into this at position
insertTo(other,position)insert all the cards from this into other at position
append(other),
appendTo(other)
same as insert and insertTo. The only difference is that position is set to the end of the target list
prepend(other),
prependTo(other)
same as insert and insertTo. The only difference is that position is set to the beginning of the target list
flip(direction)flips all the cards in the list. direction can optionally force the cards to only flip up or down if its value is 'up' or 'down' correspondingly
flipUp(),
flipDown()
correspond to flip('up') and flip('down')
reverse()reverse the order of cards in the list
shuffle()shuffle the cards in the list
rearrange(oldIndices)a generalization of shuffle and reverese. A key and value in oldIndices array signify that the card in index value should be move to index key.
*this function should be rarly used directly