Battleship
A Commandline game based on the popular board game written in Node.js
GamePlay Demo
Deployment
The game is currently published as Command Line Interface (CLI) Utility as an npm package and can be run directly by typing below on the command line (node < v10 & npm < v6 is required to be installed)
npx @letsandeepio/battleship
Technical Details
The app is built using Node.js. Individual components are implemented using classes, an efficient algorithm is used to check if the ship is placeable on the board or not. Also, the app makes use of the following NPM packages for a great UX experience:
-
figlet
for the retro game font at the beginning of the game -
chalk
for colourful fonts -
prompts
for interactive user input
The app is linted using eslint
and uses jest
for comprehensive mock game-play testing (current test coverage is 88%).
Salient Features
- Interactive user input allowing to select from the list of options
- Improved validation of user input without using loops and faster feedback to the user of invalid input.
- Allow players to have names.
- Print gameboard at every round.
- Let the user know if they already hit a spot before.
- Print victory message with a final view of the battlefield with the location of ships (boards of both player's)
Gameplay Features
- Two Player game
- Two boards (one for each player)
- 1 Ship (length of 3) - can be placed vertical or horizontally (fully extensible to allow for more ships of various sizes)
- Ask the location for placement of Ship for each player.
- Fire a single shot per turn (Hit, Miss, or if the ship has been Sunk (3 hits) then register a “you sunk enemy battleship”)
- game ends when one player sunk other player's ship
Installation
See the above “deployment” for running the game without needing to install it. In order to install a local version follow the below commands at the command line:
git clone git@github.com:letsandeepio/battleship.git
cd battleship
npm install
Finally, run the the below from the root folder of the project to run the game:
./bin/battleship
Note: If you get permission error, please use following command to grant the relevant permissions: chmod +x bin/battleship
Testing
- to start Jest in watch mode type
npm test
- to collect test coverage type
npm test:coverage
Copyright
MIT License 2020, Sandeep Kumar Chopra