1.1.0 • Published 4 years ago
a-js-tictactoe v1.1.0
tictactoe-game
Documentations
Classic gamemode | ClassicAI gamemode
Installation
npm install a-js-tictactoe
Usages
// Import the Classic gamemode from the module.
const { Classic } = require('a-js-tictactoe');
const game = new Classic();
// Define who will be my player x and o.
const playerX = 'Nicolas';
const playerO = 'Louise';
// start the game
game.start();
while(game.status == 'IN_PROGRESS') {
// add a cross (for playerX) on the case 0,0 (a1)
game.add('x', 0, 0);
// add a o (for playerO) one the case 1,2 (c2)
game.add('o', 1, 2);
// print the board
console.log(game.board);
// Continue...
}
if(game.status == 'X_WIN') {
console.log(playerX + 'won!');
} else if(game.status == 'O_WIN') {
console.log(playerO + 'won!');
} else if(game.status == 'TIE') {
console.log('TIE! Try again.')
}
The board looks like this: | / |a |b |c | |--- |------- |------- |------- | |1 | (0;0) | (0;1) | (0;2) | |2 | (1;0) | (1;1) | (1;2) | |3 | (2;0) | (2;1) | (2;2) |
Coordinates are in format (row;column)!
Properties
Game constructor :
new Classic(
symboles = {
x: Symbole, // The mark for player x.
o: Symbole, // The mark for player o.
space: Symbole, // The mark for blank space.
}
)
Symbole
is the character which will be displayed on the board. By default x: 'X', o: 'O' and space: ''.
Gamemodes
This module allows you to play different Tic Tac Toe games.
- Classic gamemode: a 3*3 board and two players.
- ClassicAI gamemode: a 3*3 board, 1 player and the computer (a little bit hard).
Contributors
MIT License