nicnacno
A console-based tic-tac-toe game written in Javascript for nodejs.
Run it directly:
$ npm install -g nicnacno
$ nicnacno
Welcome to nic-nac-no...
X player's name? Alice
O player's name? Bob
1 │ 2 │ 3
───┼───┼───
4 │ 5 │ 6
───┼───┼───
7 │ 8 │ 9
Your move, Alice (X):
Or use it like a library:
$ npm install --save nicnacno
// the game manager allows multiple consecutive games// and keeps score between the playersconst GameManager = ; // first player is X, second player is Ovar gameManager = 'Alice' 'Bob'; // moves are 1-9, top left to bottom rightgameManagergame; // XgameManagergamenextMove == 'O'; // truegameManagergame; // OgameManagergamenextMove == 'X'; // truegameManagergame; // XgameManagergame; // OgameManagergame; // false, already occupiedgameManagergame; // truegameManagergame; // XgameManagergame; // OgameManagergame; // X wins, applyMove returns true // check resultsgameManagergameresult == 'X'; // could be undefined, 'X', 'O', or 'draw'gameManagerscoreX == 1;gameManagerscoreO == 0;gameManagerscoredraw == 0; gameManager; // game resets, now O goes firstgameManager // reset to initial state, clearing score and initial player