Skip to content

git-Abdul/Battleship

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

⚓ Battleship

📖 Overview

Welcome to the Battleship Game! 🛳️ This is a console-based game written in Java. The goal is to sink all of your opponent's ships before they sink yours. Guess the locations of the hidden ships, and may the best player win! 🎯


Banner


🕹️ How to Play

  • The game is played on a 7x12 grid 📊.
  • Each player gets 3 ships 🚢 randomly placed on the grid.
  • Take turns guessing the locations of your opponent’s ships using coordinates.
  • The first player to sink all the ships is the winner! 🏆

🎮 Game Flow:

  1. Ship Placement: Ships are automatically placed on the grid for both players 🗺️.
  2. Turns: Players alternate turns guessing ship locations by entering coordinates (e.g., 5,4) 📍.
  3. Hit/Miss Feedback:
    • A hit is marked with "=" 💥.
    • A miss is marked with "♒︎" 🌊.
  4. Winning: Sink all your opponent's ships to win! 🏁

🎯 Score rush:

🎮 Game Rules

Objective: Be the first player to score 3 points by discovering your opponent's ships 💥 and orbs 💖.

  • Gameplay:
    • Players take turns guessing grid positions by entering row and column numbers.
    • Hit a Ship: Gain 2 points.
    • Hit a Bomb: Lose 1 point.
    • Collect an Orb: Gain 1 point.
  • Miss: Opponent gets 1 point.
  • Winning: The first player to reach 3 points wins the round.

✨ Features

  • Random Ship Placement: Each player’s grid is populated with hidden ships 🛳️ of random lengths.
  • Special Elements:
    • Orbs 💖: Bonus items that give extra points if found.
    • Bombs 💥: Hazardous items that decrease your score.
  • Interactive Grids: The game is played on a 9x14 grid, providing plenty of space for strategic gameplay.
  • Dynamic Scoring: Points are calculated based on the outcomes of the player’s guesses.

🌟 Features

  • 🎲 Random Ship Placement: Ships are randomly positioned horizontally, so no two games are the same!
  • 👨‍🚀 Turn-based Play: Players take turns guessing ship locations.
  • 💥 Hit and Miss Indicators: Successful hits are shown as "=", while misses are marked as "♒︎".
  • 🧹 Clear Terminal: The screen is cleared between each turn to maintain suspense (works on most systems).
  • ✅ Input Validation: Ensures player inputs are valid within the grid dimensions.

🖥️ System Requirements

  • Java 8+ is required to run the game ☕.
  • Works on Windows, macOS, and Linux.

⚙️ Setup Instructions

1. Clone the Repository

First, clone the repository to your local machine:

git clone https://github.com/yourusername/battleship-game-java.git

2. Compile the Code

Navigate to the project directory and compile the source files:

javac Project/Battleship.java

3. Run the Game

Run the game with the following command:

java Project.Battleship

📜 How to Play (Detailed Instructions)

  1. Game Start:

    • Ships are automatically placed for both players 🎲.
  2. Input Format:

    • Enter the row and column in the format row,column (e.g., 5,4) 📝.
    • Rows range from 1 to 7, and columns range from 1 to 12.
  3. Turn-based Gameplay:

    • Players take turns guessing, and the board updates after each guess 🎯.
    • You’ll see hits (=) and misses (♒︎) after each turn.
  4. Winning:

    • The game ends when one player sinks all of their opponent’s ships 💥.

🛠️ Customization Options

1. Grid Size

To change the grid size, modify the array dimensions in the code. The current size is 7x12 🗺️.

2. Number of Ships

You can adjust the number of ships by changing the value in the generateArray() method (default is 3 ships) 🚢.

3. Ship Placement

The current version only supports horizontal ship placements. You can modify the ship generation logic to support vertical or diagonal placements as well 🛠️.


💡 Example Output

=============================================
 ♒︎ ♒︎ ♒︎ ♒︎  1  1  1  1  1 ♒︎ ♒︎ ♒︎
 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎
 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎
 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎
 ♒︎ ♒︎ ♒︎  1  1  1  1  1  1  1  1 ♒︎
 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎  1  1  1  1  1  1
 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎
=============================================
 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎
 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎
 ♒︎ ♒︎ ♒︎ ♒︎  2  2  2  2  2  2  2  2
 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎
 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎  2  2  2
 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎ ♒︎
  2  2  2  2  2  2  2 ♒︎ ♒︎ ♒︎ ♒︎ ♒︎
=============================================

Player 1: Enter row and column number: 1,7
Player 2 found a ship!
Player 2: Enter row and column number: 1,5
No ship found...

ℹ️ Ship numbers are shown for demonstration purposes.


🚀 Future Improvements

  • AI Opponent: Add a single-player mode where you can play against the computer 🤖. Gameplay features: Adding multiple obstacles, home screen etc 🕹️ ...
  • Vertical and Diagonal Ships: Implement vertical and diagonal ship placements 🚢.
  • GUI Version: Use JavaFX or Swing to build a graphical interface 🖼️.
  • Save and Load: Implement save/load functionality so players can pause and resume games 💾.

👩‍💻 Contributing

Feel free to fork this project, add features, or fix bugs! Contributions are welcome 🛠️.


📜 License

This project is licensed under the MIT License. You are free to use, modify, and distribute the game 🔓. MIT License


Have fun and enjoy playing Battleship! 🎮


About

Battleship Game (Java Console Version)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages