Battleship Console Game Overview:
This Java program implements a simplified version of the classic Battleship game. It consists of two players, a human player, and a computer player. Each player places a fleet of ships on a 5x5 grid and takes turns guessing the coordinates of the opponent's ships. The game continues until all ships of one player are discovered.
- Clone the repository.
- Compile and run the
BattleshipConsoleGame.java
file. - Follow the prompts to place your ships and guess the opponent's ships.
Feel free to explore the code and make improvements. Contributions are welcome!
-
Player Classes:
Player
: An abstract class for bothHumanPlayer
andComputerPlayer
.HumanPlayer
: Handles interactive ship placement and guessing by the human player.ComputerPlayer
: Implements random ship placement and basic attacking strategy.
-
Game Flow:
- Players take turns placing ships and guessing opponent ship locations.
- The game continues until all ships of one player are discovered.
- Displays the state of both players' grids after each turn.
-
User Interface:
- Provides a clear console display with instructions and grid representation.
- Users input coordinates for ship placement and guessing opponent ships.
-
Object-Oriented Principles:
- Inheritance:
Player
class is inherited by specific player types. - Polymorphism: Different implementations of
guessTheOpponentsShips
for human and computer players. - Abstraction: Abstract methods in the
Player
class for ship placement and attacking.
- Inheritance:
-
Future Improvements:
- Enhanced computer player strategies for more challenging gameplay.
- Additional features or difficulty levels could be introduced.
The program offers a concise implementation of Battleship, showcasing core object-oriented principles. It serves as a foundation for further enhancements and a basic yet enjoyable gaming experience in the console.