This is a simple text-based Battleship game implemented in Python. The player has 4 chances to guess the location of the hidden ship on a 5x5 grid.
- A 5x5 grid is created where each cell is represented by an "O".
- A hidden battleship is placed randomly on the grid.
- The player gets 4 turns to guess the location of the battleship by inputting row and column coordinates.
- After each guess, the game provides feedback:
- If the guess is correct, the player wins.
- If the guess is incorrect, the game continues and the guessed position is marked with an "X".
- If the guess is out of bounds or a position has already been guessed, appropriate feedback is provided.
- After 4 incorrect guesses, the game ends with "Game Over".
board
: A 5x5 grid initialized with "O" representing the ocean.random_row()
andrandom_col()
: Functions that generate random row and column coordinates for the battleship.print_board()
: Function to print the current state of the board in a user-friendly format.- Game loop: The player has 4 turns to guess the ship’s location. The game provides feedback based on the player's guesses.
Turn 1
Guess Row: 2
Guess Col: 3
You missed my battleship!
- Install Python (if not already installed).
- Run the script in the terminal or command prompt using:
python battleship.py
- Input your guesses when prompted.
- Add multiple ships to increase difficulty.
- Implement a larger board with more turns.
- Allow diagonal movement for more complex strategies.
- Add a replay option at the end of the game.
This README provides a clear description of how the game works, the code's structure, and how to run the program.