A simple command-line Battleship game written in Java.
This project uses a 10x10 grid where:
- the player places 5 ships
- the computer places 5 ships
- both sides take turns attacking coordinates
- the game ends when one side loses all ships
- 2D arrays
- nested loops
- user input with
Scanner - random number generation with
Random - conditionals and game-state tracking
The game stores the board in a 2D integer array called map.
Board values:
0= empty water1= player ship2= computer ship3= player ship that was sunk4= computer ship that was sunk5= player miss6= computer miss
Compile:
javac Battleship.javaRun:
java Battleship- extract repeated logic into helper methods
- improve coordinate validation
- separate board rendering from game logic
- create a JavaScript version as a follow-up project