This is a command-line interface (CLI) implementation of the classic Battleship game written in Java.
- Java Development Kit (JDK) 15 or higher
- Git (optional)
- Clone the repository or download the source code.
git clone https://github.com/precompile/battleship-cli.git
- Navigate to the project directory.
cd battleship-cli/src
- Compile the source code.
javac *.java
- Run the program.
java TestBattleship
The computer places its ships by randomly generating the coordinates on the board. The player takes turns to guess the location of the computer's by entering the coordinates of the grid in the format "fire X Y", where X is a letter from A to H and Y is a letter from A to H. The game ends when all of the computer's ships are destroyed. The player can quit the game by typing "quit" or display the help message by typing "help".
The game is played on an 8x8 grid.
- PATROL (2)
- SUBMARINE (3)
- BATTLESHIP (4)
- DESTROYER (5).
Ships cannot be placed diagonally or overlapping. Players cannot fire at the same coordinate twice. The game mentions if the player already shot at the same position. A hit is marked with an "X" on the grid. A miss is marked with an "O" on the grid. The game ends when all of the computer's ships are destroyed.
Contributions are welcome! Please open an issue or pull request if you have any suggestions or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.