A terminal-based Battleship game written in TypeScript where you play against the computer! Sink the computer's ships before it sinks yours.
- Random or Manual Ship Placement: You can either randomly place ships on the board or manually position them.
- Customizable Board and Ships: Adjust the board's dimensions and ship sizes to your liking.
- CLI: Easy-to-use command-line interface with options for quick game setup.
Make sure you have Node.js installed.
-
Clone the repository
-
Install dependencies
npm install
-
Build the project:
npm run build
node dist/battleship-cli.js [options]-r, --random: Random placement of the ships (default:true)-m, --manual: Manual placement of the ships (default:false)-h, --height <number>: Board's height (default:10)-w, --width <number>: Board's width (default:10)-s, --ships <numbers...>: Ship sizes (default:[5,4,3,3,2,2,2])--help: display help for command
NOTE: --ships should be specified with spaces, e.g. --ships 5 4 3 2 1
If you run the game without any options, a random 10x10 board is generated with default ships placed randomly.
-
Random game:
node dist/battleship-cli.js
-
Manual Ship Placement:
node dist/battleship-cli.js --manual
After selecting this option, you'll be prompted to choose a direction (horizontal or vertical) and a starting square (e.g.,
B5) for each ship. -
15x15 board:
node dist/battleship-cli.js -h 15 -w 15
-
Generate 1 ship of size 6, 2 ships of size 5, and 4 ships of size 2:
node dist/battleship-cli.js -s 6 5 5 2 2 2 2
During the game, you can input coordinates for your move (e.g., B5, A1) or use one of the following commands:
new: Start a new random game with the default settings.manual: Start a new game with manual ship placement.exitorquit: Quit the game.
- Set width and height of the board
- Manual placement of the ships
- Add difficulty levels
