Skip to content

Lesson 02 — Give the arena an authoritative model ​

Where this lesson fits: the host draws a frame. Now give the arena a stable representation that gameplay systems can query without relying on pixels.

Time: 2–3 hours

Prerequisites and outcomes ​

Complete lesson 01. By the end, you can explain tile ownership, convert between world and grid coordinates, and apply a result to the arena.

Prepare and run ​

  1. From your learner project's solution folder, follow tutorial chapter 02 steps 1–5. Step 1 copies files and overwrites matching files in your project; replace <course-repo> with your repository path.
  2. Open Source\Systems\ArenaSystem.cs and Tests\Systems\ArenaSystemTests.cs in your project. Run the focused command below from the same solution folder, then use the tutorial's checkpoint.

Code anchors ​

  • last-perimeter/Source/Data/GameConfig.cs
  • last-perimeter/Source/Data/Enums.cs
  • last-perimeter/Source/Systems/ArenaSystem.cs
  • last-perimeter/Tests/Systems/ArenaSystemTests.cs

Concept: coordinate spaces ​

GameConfig defines screen size, HUD reserves, arena margin, and tile size. ArenaSystem owns the grid and the conversions between game-world positions and tile coordinates. Rendering may draw a tile as a rectangle, but simulation asks which state owns that tile.

Guided operations ​

  1. Calculate the arena bounds from the configured screen and HUD reserves.
  2. Follow a world position into TryWorldToGrid; inspect the behavior at the top-left, bottom-right, and just outside the arena.
  3. Inspect the tile-state enum and identify which state means traversable unclaimed interior, permanent claim, and boundary.
  4. Clone the grid and compare it with the authoritative grid. Explain why the clone is useful for a solver.
  5. In ArenaSystemTests.cs, find the claim-application test. Read its fixture and assertions, then run it with the focused command below; compare the asserted tile count and percentage with your prediction.

Run the focused tests from the project directory:

powershell
dotnet test --filter FullyQualifiedName~ArenaSystemTests

Checkpoint ​

The focused tests pass. You can predict the grid coordinate for a point and explain which component should change when a claim is committed.

Common mistakes ​

  • Mixing world-space pixels and grid-space cells in one calculation.
  • Treating a visual fill as the authoritative claim record.
  • Mutating the live grid while exploring a possible claim.

Questions and extension ​

Which coordinate conversion edge cases could cause a trail to leave a one-cell gap? Add a boundary-focused test using the existing test fixture.