1.0.0 • Published 5 years ago

triqui v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

triqui

A Tic Tac Toe written in javascript

OOX
OXO
XOX

Install

npm install triqui

Usage

Start a new game with

import Triqui from "triqui";

let triqui = new Triqui();

game board positions for make moves

yyy
x012
x012
x012

Make a move giving x, y position in board triqui.play([x, y]), the current inital player its selected ramdomly

Result 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

nametypedescription
isEndbooleanindicate if the game is end
gamearraycurrent board of the game
turnPlayercurrent player
resultResultstatus after the last move

Types

  • Player -> "circle" | "cross"
  • Result
    • Status -> "draw" | "win" | "play"
    • Winner -> a Player