1.0.1 • Published 6 months ago
goose-game v1.0.1
Goose Game Library
A simple npm package to simulate and play the classic Goose Game. Customize the board and rules as you like!
Installation
Install the package using npm:
npm install goose-game
Dependencies
This library depends on:
dices
(install vianpm install dices
)- A custom
boxes.js
file for board mapping.
Usage
Importing the Library
const gooseGame = require("goose-game");
Starting the Game
Initialize the game by specifying the number of boxes, players, and a custom board mapping (optional):
const players = gooseGame.start(
70,
["Mario", "Carlo", "Giovanni", "Dario"],
mapping
);
console.log(players);
// Output: List of players with their initial positions
inputBoxes
: Number of boxes on the board (default is 70).inputPlayers
: Array of player names (default is["Mario", "Carlo", "Giovanni", "Dario"]
).inputMapping
: Custom mapping of special boxes (default ismapping
).
Running a Turn
Simulate a turn for all players:
const updatedPlayers = gooseGame.run();
console.log(updatedPlayers);
// Output: Updated player positions
Checking for a Winner
Determine if there is a winner:
const winner = gooseGame.somebodyWon();
if (winner) {
console.log(`${winner} has won the game!`);
} else {
console.log("No winner yet. Keep playing!");
}
Example boxes.js
Your boxes.js
file should export a mapping
object that defines special box effects:
exports.mapping = {
5: +3, // Move forward 3 spaces when landing on box 5
10: -2, // Move back 2 spaces when landing on box 10
20: +5, // Move forward 5 spaces when landing on box 20
};
License
MIT