This is an in-console Java implementation of the classic Battleship game, played between the user and CPU. I created this project to practice OOP (object oriented programming) through the use of inheritance and polymorphism. For future updates I hope to implement a drowned ship detection system, and an overall better looking UI.
Ensure Java is installed on your device (install here) and run the following commands:
git clone https://github.com/a4ojha/Battleship
cd Battleship
javac main.java
java main.java
-
Aircraft Carrier (5 squares)
-
Crusier (3 Squares)
-
Destroyer (2 Squares)
-
2 Boats (1 Square)
These ships will be randomly assigned a position on the 10x10 grid that is printed to the console.
In this game, you will be playing against the computer in a game of battleship:
- O = empty spot
- X = alive ship
- ■ = hit ship
- / = misfire
You and the computer will take turns firing shots at each other's grid, without seeing each other's ship placement. With each turn, you will enter the coordinates for where you want to attack, and your opponent will shoot at a random spot on your grid.
The goal is to destroy all 5 of your opponent's ships!
Once either you or the CPU wins, both boards will be displayed to reveal possible leftover ships of your opponent. Good luck and have fun!

