UNPKG

goose-game

Version:

A lightweight npm library to simulate and play the classic Goose Game with customizable rules and boards

84 lines (58 loc) 1.75 kB
# 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: ```bash npm install goose-game ``` ## Dependencies This library depends on: - `dices` (install via `npm install dices`) - A custom `boxes.js` file for board mapping. ## Usage ### Importing the Library ```javascript const gooseGame = require("goose-game"); ``` ### Starting the Game Initialize the game by specifying the number of boxes, players, and a custom board mapping (optional): ```javascript 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 is `mapping`). ### Running a Turn Simulate a turn for all players: ```javascript const updatedPlayers = gooseGame.run(); console.log(updatedPlayers); // Output: Updated player positions ``` ### Checking for a Winner Determine if there is a winner: ```javascript 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: ```javascript 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