- First, clone this repository
- After accessing the properly project directory, run
npm install
- It will install test and build dependencies
- If gulp is not installed globally, run
npm i -g gulp
- NPM packages was installed just for testing and build purpose
- To run tests, run
gulp test
- To build the app, run
gulp build
- Mandatory to run the app at first time
- To run a small http server to preview the app, run
gulp app
Game coding
-
Game (all properties are private - can't be change after its creation)
- getName():
string
- getDescription():
string
- getOptions():
GameOptionCollection
- getPreferences():
GamePreference[]
(future)
- getName():
-
GameOption (all properties are private - can't be change after its creation)
- getName():
string
- getWins():
GameOption[]
(options which lose from this one) - getLoses():
GameOption[]
(options which win this one)
- getName():
-
GameOptionCollection (to ensure that the options won't be changed after the game starts)
- options:
GameOption[]
(private) - add:
GameOption
- get:
GameOption[]
(a copy)
- options:
-
GameFactory
- constructor(validator:
GameValidator
) - create(settings:
json
):Game
- constructor(validator:
-
GameMatchFactory
- constructor(validator:
GameMatchValidator
) - create(game:
Game
, playerOptions:PlayerOption[]
):GameMatch
- constructor(validator:
-
GameMatchValidator
- validate(match:
GameMatch
):boolean
- validate(match:
-
GameValidator
- validate(settings:
json
):boolean
- validate(settings:
-
GameMatch (a match with many players)
- constructor(game:
Game
, playerOptions:PlayerOption[]
) - result():
MatchResult[]
- constructor(game:
-
GameDuel (a match with only two players)
- constructor(game:
Game
, playerOne:PlayerOption
, playerTwo:PlayerOption
) - result():
MatchResult
- constructor(game:
-
MachinePlayer
- constructor(game:
Game
) - play():
PlayerOption
- constructor(game:
-
PlayerOption
- name:
string
- choice:
GameOption
- name:
-
MatchResult
- hasWinner():
boolean
- getWinner():
string
- getloser():
string
- toString():
string
(pre checked message for winner or draw)
- hasWinner():
-
Settings Structure
{ "name": "Test", "description": "Test Description", "options": [{ "name": "name1", "wins": ["name2"], "loses": ["name3"] }, { "name": "name2", "wins": ["name3"], "loses": ["name1"] }, { "name": "name3", "wins": ["name1"], "loses": ["name2"] }], //preferences: { machinePlayerNames: ['bot1', 'bot2', 'bot3'] } }
let settings = require('settings');
let game = new GameFactory().create(settings);
let p1 = new MachinePlayer(game).play();
let p2 = new MachinePlayer(game).play();
let result = new GameDuel(game).between(p1).and(p2);
console.log(result);
Web application to run the Game