Skip to content

Latest commit

 

History

History
62 lines (44 loc) · 973 Bytes

README.md

File metadata and controls

62 lines (44 loc) · 973 Bytes

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:

⚪⚪⚪⚪⚪⚪⚪
⚪⚪⚪⚪⚪⚪⚪
⚪⚪⚪⚪⚪⚪⚪
⚪⚪⚪⚪⚪⚪⚪
⚪⚪⚪⚪⚪⚪⚪
🔵🔴⚪⚪⚪⚪⚪