1.0.0 • Published 5 years ago
triqui v1.0.0
triqui
A Tic Tac Toe written in javascript
O | O | X |
O | X | O |
X | O | X |
Install
npm install triqui
Usage
Start a new game with
import Triqui from "triqui";
let triqui = new Triqui();
game board positions for make moves
y | y | y | |
---|---|---|---|
x | 0 | 1 | 2 |
x | 0 | 1 | 2 |
x | 0 | 1 | 2 |
Make a move giving x, y position in board
triqui.play([x, y])
, the current inital player its selected ramdomlyResult is going to be the current status of the game, can be "draw", "win" and "play"(not ended game)
triqui.play([0, 1]);
/*
* return result
* { status: "play" }
* { status: "draw" }
* { status: "win", winner: "cross"}
**/
triqui.game;
/**
* [null, "circle", null],
* [null, null, null],
* [null, null, null]
**/
triqui.turn; // "cross" or "circle"
triqui.play([5, 5]); // Throws range error
triqui.play([0, 1]); // Throws error invalid move when move is already maked
triqui.isEnd; // boolean
Attributes
name | type | description |
---|---|---|
isEnd | boolean | indicate if the game is end |
game | array | current board of the game |
turn | Player | current player |
result | Result | status after the last move |
Types
- Player -> "circle" | "cross"
- Result
- Status -> "draw" | "win" | "play"
- Winner -> a Player
1.0.0
5 years ago