back to the school

docs/002-plain-state-struct.md

   1  # ADR 002: keep the game in one plain object
   2  
   3  Status: accepted
   4  
   5  ## Decision
   6  
   7  `state.ts` defines `Game` as one object type with two paddles, a ball, an accumulator and a serve flag. `init_game` returns a value. `update.ts` receives that value and writes its fields. `draw.ts` receives the same value and reads it.
   8  
   9  ## Reason
  10  
  11  The state is the whole memory of the game. One object type makes that memory visible in one file, so a reader can tell what survives between frames without tracing globals or ownership. Passing it explicitly keeps the four files separate: input produces a snapshot, update changes state, draw reads state, main wires them together.
  12  
  13  ## Consequences
  14  
  15  Adding a field means editing one type and the functions that use it. The compiler shows every caller. A field such as `serving_to_right` can be tested by constructing a `Game` value in isolation, with no window and no keyboard.
  16