A modern, real-time multiplayer implementation of the classic Battleship game built with ASP.NET and SignalR.
- About
- Features
- Technologies
- Architecture
- Getting Started
- Gameplay
- Things Learned
- Used Resources
- License
Battleships is a web-based implementation of the classic Battleship board game featuring real-time online multiplayer functionality. Players can register, create or join game rooms (public or private), and engage in strategic naval warfare while chatting with opponents. The project emphasizes clean architecture, server-authoritative game state, and real-time synchronization using SignalR.
This MVP (Minimum Viable Product) focuses on delivering core gameplay mechanics with proper rule enforcement, real-time communication, and a scalable backend foundation for future enhancements.
- Classic Battleship Rules: 10×10 grid with standard ship set (Carrier, Battleship, Cruiser, Submarine, Destroyer)
- 2-Player Real-Time Matches: Strict turn-based gameplay with server-side validation
- Ship Placement: Manual placement or randomization with reset capability during setup
- Turn Timer: Per-player time limits to keep games moving
- Game State Synchronization: Real-time updates across both players using SignalR
- Win/Loss Detection: Automatic game end when all ships are sunk
- Public Rooms: Join any available public game from the lobby
- Private Rooms: Create code-protected rooms for playing with friends
- Auto-Close: Rooms automatically close when all players leave
- Rejoin Support: Reconnect to active games within a 5-minute window
- Authentication: Username/email/password registration and login
- Guest Access: Anonymous users can join public rooms (limited features)
- Single Active Game: Users can only participate in one game at a time
- Account Persistence: User profiles and game history stored in database
- In-Game Chat: Real-time messaging during all game phases
- Rate Limiting: Protection against spam and abuse
- Authenticated Only: Chat restricted to registered users
- Toxic Behavior Reporting: Built-in reporting mechanism (MVP: reported messages optionally stored)
- Server-Authoritative Game Logic: All rules enforced on the backend
- Turn Validation: Out-of-turn actions rejected
- Ship Placement Validation: Overlap, spacing, and boundary checks
- Private Room Protection: Admin kick functionality for unauthorized access attempts
- Inactivity Timeouts: Automatic removal of inactive players
- Clean Architecture: Separation of concerns with Domain, Application, Infrastructure, and API layers
- CQRS Pattern: Clear separation of commands and queries without mediator frameworks
- Real-Time Communication: SignalR for instant gameplay and chat updates
- Persistent Storage: Entity Framework Core with SQL Server
- Comprehensive Testing: Unit, integration, architecture, and end-to-end tests
- Containerization: Docker support for consistent deployment
- Cloud Deployment: Azure-ready with scalability considerations
- ASP.NET Core - Web API framework using Minimal APIs
- SignalR - Real-time communication framework
- Entity Framework Core - ORM for database access
- SQL Server - Relational database
- FluentValidation - Input validation library
- Scrutor - Assembly scanning and decoration
- Razor Pages - Server-side rendering with C#
- Tailwind CSS - Utility-first CSS framework
- SignalR Client - JavaScript client for real-time updates
- XUnit - Unit testing framework
- TestContainers - Integration testing with containerized dependencies
- Playwright - End-to-end browser testing
- Architecture Tests - Dependency rule enforcement
- Docker - Containerization
- Azure - Cloud hosting platform
- Git - Version control
The project follows Clean Architecture principles with clear separation of concerns
- Server-Authoritative: All game logic and state validation occurs on the server
- CQRS Without MediatR: Explicit command and query handling for clarity
- No Domain Logic in Hubs: API layer handles only routing and validation
- Real-Time First: SignalR used for game state updates and player interactions
- Fail Fast: Invalid inputs and illegal state transitions rejected immediately
- .NET 9.0 SDK
- SQL Server (LocalDB or full instance)
- Docker (optional)
-
Clone the repository
git clone https://github.com/Dejmenek/Battleships.git cd Battleships -
Restore dependencies
dotnet restore
-
Set up the database
dotnet ef database update --project src/Battleships.Infrastructure
-
Run API
dotnet run --project src/Battleships.API
-
Run Web App
dotnet run --project src/Battleships.Web
-
Access the application
- API:
https://localhost:7020 - Web UI:
https://localhost:7247
- API:
docker-compose up# All tests
dotnet test
# Unit tests only
dotnet test tests/Battleships.UnitTests
# Integration tests
dotnet test tests/Battleships.IntegrationTests
# End-to-end tests
dotnet test tests/Battleships.EndTests
# Architecture tests
dotnet test tests/Battleships.ArchitectureTests- Register or Login: Create an account or continue as guest (limited features)
- Join or Create a Room:
- Browse public rooms in the lobby
- Create a private room with a unique code
- Share the code with friends for private matches
- Place Your Ships:
- Manually drag and drop ships onto your board
- Use "Randomize" for automatic placement
- Use "Reset" to clear and start over
- Click "Ready" when satisfied with placement
- Take Turns:
- Wait for your turn
- Click a cell on opponent's board to fire
- Watch for hit, miss, or sunk feedback
- Wait for opponent's turn
- Win the Game: Sink all enemy ships before they sink yours!
- Board: 10×10 grid per player
- Ships: Carrier (5), Battleship (4), Cruiser (3), Submarine (3), Destroyer (2)
- Placement Rules:
- Ships must stay within boundaries
- No overlapping
- Minimum one-cell spacing between ships
- Turn Rules:
- Strict alternating turns
- One shot per turn
- No extra turn on hit
- Win Condition: First player to sink all opponent ships wins
To be documented throughout development...
To be documented throughout development...
This project is licensed under the MIT License - see the LICENSE file for details.