Real-time multiplayer space strategy game that runs in the browser. Players join a faction, fit out a fleet, and fight for territory on a shared hex map.
Started in 2019 and still in active development. Game design. Application architecture. Combat engine. Front end. Infrastructure.
The game
Built with Node.js and Express. The server owns the game state and pushes every change to players over Socket.IO: tile ownership, battles, missions, inventory, and chat. MySQL for storage, Pug for the views, and plain JavaScript on the client.
The loop: join a faction, equip ships in the hangar, complete missions for rewards, and attack tiles on the map to claim them for the faction.
Combat
Attacking a tile starts a battle. Matchmaking looks for a human opponent in three widening passes, then falls back to a bot. Both sides ready up, and the server runs the fight.
Each fleet sits on a grid of five columns and three rows, and the row is a trade-off:
- Front row. Fires fastest, and takes 1.5x damage.
- Middle row. 1.25x slower to fire, and takes 1.25x damage.
- Back row. 1.5x slower to fire, and takes normal damage.
The battle ticks every 100ms. On each tick the server counts down cooldowns, picks targets, resolves attacks, and broadcasts the result. Energy weapons wear down shields, projectile weapons damage the hull, and armor reduces what gets through by a percentage.
Ships can be moved mid-battle. A move takes longer the more equipment a ship carries, with defensive slots costing the most, and a ship can't fire while it travels.
Bot players
Bots keep the map contested when few people are online. Each one connects exactly as a browser does, as a Socket.IO client, so it exercises the same code a player does. It works through the same steps: set up a fleet, take missions, read the map, attack, and fight.
Three personalities set the pace. Aggressive bots rest 5 to 15 seconds between battles, moderate ones 15 to 45, and passive ones 30 to 90. In combat they reposition by hull strength: healthy ships move forward, and damaged ships fall back. After five errors in a row a bot cools down for a minute instead of hammering the server.
Tuning without a restart
Balance numbers live in the database, not in the code: battle speed, movement costs, crew ability damage, and the number of bots running. They're edited from the admin panel, and a change applies to the next battle.
Testing
Three levels, from cheapest to most realistic.
- Unit tests. 175 Jest tests that run in about a second, plus 48 integration tests that run against a live server.
- Combat harness. Connects over Socket.IO and fights real battles. One mode equips two of three ships, leaves the third stock, and checks that the equipped ships fire more often and deal more damage.
- Combat watcher. Opens the spectator view in headless Chromium with Playwright, and records the console, the socket traffic in both directions, samples of the DOM, and screenshots. Built for rendering bugs that no unit test can see.