Game Play feature

Monolithic gameplay page (HTML + embedded JavaScript)
Interactive UX Authenticated UX
/app/game_play.html

This is the core gameplay interface. It allows users to manage turns, record scoring events, track unit states, and ultimately finalise a game.

File structure

ComponentDescription
HTML layout Defines full UI including score panels, event entry, unit lists
Inline CSS Self-contained styling (legacy – not yet extracted)
Inline JavaScript Full gameplay engine and API interaction logic
⚠️ This file predates your split architecture and should eventually be refactored.

Purpose

  • Run a game in real time
  • Track player turns and rounds
  • Record scoring events
  • Maintain unit state (alive / destroyed / below 25%)
  • Apply tournament scoring logic
  • End and finalise games

UI sections

Header

  • Game ID, status, round, player turn
  • Player names and roles

Score panel

  • Live VP totals
  • Raw VP result
  • Tournament result
  • Summary metadata

Turn controls

  • Start round
  • End player turn
  • End game
  • Finalise game

Event entry

  • Scoring player selector
  • Event type selector
  • Dynamic points logic
  • Unit selector (context aware)
  • Notes

Event history

  • Chronological event list
  • Hard delete capability

Units panel

  • Per-side unit lists
  • Visual state indicators

Data flow

  1. Page loads with ?game_id=
  2. Calls /games/play_state.php
  3. Stores response in global state
  4. Renders all UI sections
  5. User actions trigger API calls
  6. State reloads after every mutation

Key JavaScript functions

FunctionPurpose
loadState()Loads full game state
renderHeader()Updates game metadata display
renderTotals()Displays scoring totals
renderUnits()Displays unit states
renderEvents()Displays event list
renderTurnScoreTable()Turn-by-turn scoring

Game state control logic

  • Game cannot end until at least one player turn exists
  • Events cannot be recorded before first round
  • Finalised games are locked
  • End-of-game events are restricted to post-end phase

Scoring rules implemented

  • UNIT_DESTROYED → full points (+General +100, BSB +50)
  • UNIT_RUN_DOWN → destroyed + auto banner (+25)
  • UNIT_BELOW_25% → 50% points (rounded up)
  • OBJECTIVE_CONTROLLED → default 30 per objective
  • End-game events use predefined defaults

Backend dependencies

EndpointPurpose
/games/play_state.phpFull game state
/turns/start.phpStart round
/turns/end.phpEnd player turn
/events/create.phpAdd event
/events/delete.phpDelete event
/games/end.phpEnd game
/games/finalise.phpFinalise game

Technical risks / notes

  • Large monolithic file (high change risk)
  • UI and logic tightly coupled
  • No separation of concerns
  • Harder to test in isolation
Recommendation: refactor to match the pattern used in game_breakdown (HTML + JS split).