Skip to content

shashwathuday/BattleShip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation


Battleship Game

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.

How the Game Works

  • 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".

Code Overview

  • board: A 5x5 grid initialized with "O" representing the ocean.
  • random_row() and random_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.

Example

Turn 1
Guess Row: 2
Guess Col: 3
You missed my battleship!

How to Run

  1. Install Python (if not already installed).
  2. Run the script in the terminal or command prompt using:
    python battleship.py
  3. Input your guesses when prompted.

Future Enhancements

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages