A Java OOP implementation of the classic Naval Battle with a retro Scientific Calculator UI.
Paris 8 University - 2021 Original Development
2026 Refactored for Translation
SeaWar is a tactical battleship simulation developed in 2021. The project was designed with a strong focus on Object-Oriented Programming (OOP) and Heuristic Artificial Intelligence.
The unique visual style is inspired by retro scientific calculators and Minitel interfaces, using ANSI escape codes to render a full-screen GUI directly in the Unix terminal.
The project is architectured around four core classes to ensure a clear separation of concerns:
- SeaWar.java: The main Controller. It manages the global application lifecycle, orchestrates the game loops, processes user inputs (via Regex), and handles the ANSI terminal rendering.
- Player.java: Manages the player's state. It encapsulates the tactical logic, the two primary matrices (Deployment and Attack grids), and the fleet's data structures.
- Bateau.java: The Ship Entity. It defines vessel properties, including size, health points (HP), and spatial coordinate tracking.
- Game.java: The Session Manager. It handles global environment parameters, turn-based rotation logic, and session-specific states.
The CPU doesn't just fire at random. It implements a multi-state decision engine:
- Search Mode : Uses a parity-based scanning pattern to find targets efficiently.
- Hunt Mode : Once a hit is confirmed, the AI uses a recursive Stack-based memory to explore adjacent cells.
- Destruction Mode : Tracks ship orientation and handles "composite targets" (overlapping ships) by prioritizing wounded vessels.
5-cell ship |
after hit |
after align |
Sunken |
- ANSI Rendering : Real-time color updates for Fog of War, Hits, and Sinks.
- Dynamic ASCII Art : Automated rendering of different ship classes based on their health status.
- Terminal Control : Integrated shell script for automatic terminal resizing (100x41).
- Architecture : Model-View-Controller (MVC) pattern.
- Standard Libs : java.util.Scanner, java.util.Stack, java.util.HashMap, java.util.regex.Pattern.
This project is designed to run in a Unix-like terminal (Linux/macOS) to ensure the proper rendering of ANSI colors and terminal resizing.
- Quick Start (via Shell Script)
The project includes a launch script that automatically handles the terminal dimensions (100x41) required for the Scientific Calculator UI.
Grant execution permissions (if needed):
chmod +x launch_SeaWar
Run the game:
./launch_SeaWar
- Manual Build (from Source) If you wish to recompile the project from the src directory:
Compile using the Makefile:
make
Execute manually (Ensure your terminal is large enough):
# Set terminal size manually to 100x41 and run printf '\e[8;41;100t' java SeaWar
ANSI Colors: This game uses ANSI escape codes. For the best experience in an IDE like Eclipse, the ANSI Escape in Console plugin is recommended.




