1.0.2 • Published 2 years ago

@mr.yuto/connectfour.js v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ConnectFour.js

A simple Connect four game logic

  • Easy to use
  • Object-oriented
  • Multiple players
  • Custom board

Install

npm install @mr.yuto/connectfour.js

OR

yarn add @mr.yuto/connectfour.js

Usage

Creating a game with two players:

const { ConnectFour } = require('@mr.yuto/connectfour.js');

const game = new ConnectFour({ boardWidth: 7, boardHeight: 6 });

//Add players to game before starting
const playerA = game.addPlayer('A', '🔵');
const playerB = game.addPlayer('B', '🔴');

// start the game
game.start();

After starting the game, the player can drop a bead to a specific column (0 to boardWidth - 1):

playerA.dropBead(0);
playerB.dropBead(1);

Print the game board:

const printedBoard = game.print()
console.log(printedBoard);

Console:

⚪⚪⚪⚪⚪⚪⚪
⚪⚪⚪⚪⚪⚪⚪
⚪⚪⚪⚪⚪⚪⚪
⚪⚪⚪⚪⚪⚪⚪
⚪⚪⚪⚪⚪⚪⚪
🔵🔴⚪⚪⚪⚪⚪
1.0.2

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago