Skip to content
Julen Somet García
FRENES
← All missions

Software LOG-05 · Jan 2025

Star Wars combat simulation in Java

Turn-based combat game between two squads, designed to apply four design patterns to a concrete case, with a Swing interface and a player-versus-computer mode.

Role
Software architecture project at ISIMA, in a pair with Jocelin Calas
Stack
  • Java 17
  • Swing
  • JUnit 5
  • Maven
Screenshot of Star Wars combat simulation in Java

AThe context

For the software architecture course, we had to apply design patterns to a simulation. Two squads of five soldiers, light side against dark side, fight on an 8 × 8 grid. You can play one side against the computer or watch the computer play both. The computer's soldiers advance, attack, retreat when wounded and then return to the fight.

BWhat I did

  • Abstract Factory: each side provides its family of soldiers, the world asks for “a melee soldier” without knowing whether it gets a Twi'lek or a Zabrak
  • State: the Attack and Flee modes decide by themselves when to switch from one to the other depending on hit points
  • Strategy: melee units charge the nearest enemy, ranged units finish off the weakest enemy in range
  • Observer: the Swing window and the console subscribe to world events, so the model does not depend on the interface
  • Graphical interface and player mode: the world waits for the player's action and validates it like that of any soldier
  • 24 JUnit tests, including 200 complete simulated games to check that no soldier leaves the map or shares a cell

CThe challenge

The delivered version compiled, but several bugs skewed the fights: range was never saved, a distance could be negative, dead soldiers still played. When taking the project back, automatic simulations also revealed a balance problem: when one side played all its soldiers at once, the side that started won 9 games out of 10. Soldiers now play in alternation and the statistics were tuned so that each side wins about one game in two.