Skip to content

MrYuto/connectfour.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published