Multiplayer Battleship Game

Overview

A full-stack multiplayer Battleship game where players create lobbies, place ships, and take turns firing through a live web interface backed by a REST API. It is interesting because the system enforces all game rules server-side — turn order, ship placement validation, hit/miss tracking, and win detection — so the client stays thin and the game state is always authoritative. I architected the backend service layer and data model so that game state transitions are explicit and testable, with a dedicated test API that accepts a password header to enable controlled grading flows without touching production data.

My Contributions

  • Designed the overall backend architecture: service layer, database schema, and Docker Compose setup
  • Built the Checkpoint B backend — game state management, turn enforcement, and win detection
  • Implemented the test endpoint suite (protected by header-based auth) for repeatable grading flows
  • Set up the PostgreSQL schema with SQLAlchemy models for players, games, ships, and moves
  • Configured Docker Compose to orchestrate the API and database with auto-table creation on startup

Phase 1 — Backend API

The first phase established the REST API and database layer. Built with FastAPI and PostgreSQL, it exposes endpoints for player management, game creation, ship placement, firing, and move history. All game rules are enforced in a dedicated service layer (game_service.py) that handles state transitions independently of the route handlers.

Phase 2 — Frontend

The second phase added a Vanilla JS frontend that connects to the Phase 1 API. Players navigate from a server config screen through a lobby to a live game board, which splits the view into your board (showing incoming hits) and a target board (your shots on the opponent). Board state is polled from the API and the UI updates automatically as turns progress.

Tech Stack

  • Python 3.11
  • FastAPI
  • PostgreSQL 15
  • SQLAlchemy
  • Pydantic
  • Vanilla JS
  • Docker Compose