A classic Battleship game built with C# and Windows Forms (.NET 6). Play against an AI opponent on a 10×10 grid, placing your fleet strategically and hunting down enemy ships.
The game follows standard Battleship rules. Both the player and the AI start with identical fleets placed on separate 10×10 ocean grids. Players take turns firing at each other's grids until one side's entire fleet is sunk.
| Ship | Size | Count |
|---|---|---|
| Battleship | 4 cells | 1 |
| Submarine | 3 cells | 2 |
| Corvette | 2 cells | 3 |
| Lance | 1 cell | 4 |
Total: 10 ships
-
Place your ships — Select a ship from the panel on the right, then click a cell on your grid (left board) to place it. Use the rotation button (
↕/↔) to toggle between vertical and horizontal orientation. Hovering over the grid previews ship placement. -
Start the game — Once all 10 ships are placed, click the Shield button to confirm. An animated spinner randomly determines who goes first.
-
Take your turn — Click cells on the enemy grid (right board) to fire. A hit shows a flame icon; a miss shows a splash icon. A message appears when you sink a ship.
-
AI turn — The AI fires automatically after each of your moves. It uses a hunt/target strategy: random shots when hunting, then focused adjacent attacks after a hit.
-
Win condition — Sink all of the AI's ships to win. If the AI sinks all of yours, it wins. A dialog prompts to play again.
A debug button reveals the AI's ship positions on the enemy grid (color-coded by size) and shows a data grid with exact coordinates. Useful for testing.
- Windows 10 or later
- .NET 6 Desktop Runtime
- Clone the repository:
git clone https://github.com/your-username/BattleShip.git - Open
BattleShip2.0.slnin Visual Studio 2022 or later. - Build and run (
F5).
No external dependencies — all assets are embedded in the project.
BattleShip/
├── Form1.cs # Main game logic (ship placement, AI, turn management)
├── Form1.Designer.cs # WinForms UI layout
├── Program.cs # Entry point
├── BattleShip2.0.csproj # Project file (.NET 6 WinForms)
├── Properties/
│ └── Resources.* # Embedded image resources
└── Resources/ # Game assets (ships, hit/miss icons, backgrounds)
See LICENSE.txt.