Skip to content

Chapter 00: Overview - the Game, Its Requirements and Its Services ​

This is the opening chapter. You write no code in it. Instead, you learn what you will build, what "done" means for it, and the three words the whole course runs on: requirement, service and operation.

The chapter ends with two paper exercises and a short list of tools to install before Chapter 01: The Project and the Host.

Time: [TODO Simon: time estimate for chapter 00]

In this chapter, you will:

  • Learn the one-sentence game loop and the history behind it.
  • Name the three kinds of space in any frame: safe, temporary danger and permanent claim.
  • Read the requirement catalogue and follow one requirement from its row to its test.
  • See the service map of the finished game and where each chapter fits on it.
  • Learn the rhythm every later chapter follows: contract card, stub, test, operation, explanation.
  • Install the tools you need for Chapter 01.

Requirements in this chapter ​

No requirements are built here. The chapter introduces the requirement catalogue and shows four rows as worked examples: ARN-04, TRL-04, FUS-04 and CAP-04.

Why territory capture is good to learn from ​

A territory-capture game is small enough to finish in a course. It is also deep enough to force real design decisions. To build one, you must solve each of these problems:

  • Continuous movement along a constrained path.
  • Drawing a line through open space.
  • Deciding which region a closed line captures.
  • Enemies that put pressure on the player.
  • Feedback through score, a heads-up display (HUD) and sound.

Together they mark the difference between "something moves" and "a real game system works".

History ​

The idea comes from Qix, an arcade game released by Taito in 1981.[^qix] Most arcade hits of that time were about shooting. Qix was about claiming territory under pressure.

The player steered a small marker that was safe on the edge of the field. To make progress, the marker left the edge and drew a line into the open. The line had to reconnect to the edge before something caught it.

Two threats made that risky. One was the Qix itself, a bundle of lines that roamed the open field. The other was a spark that chased along the unfinished line whenever the player stopped moving. Claiming enough of the field cleared the level.

That loop still works because it keeps four pulls in tension: caution, greed, planning and speed. You build a game on the same loop. It is called Last Perimeter, and it has its own code, visuals and sound. Where the classic game stops, Last Perimeter adds levels, powerups, menus, upgrades between levels and a daily challenge.

The one-sentence game loop ​

Hold the whole game in one sentence. The player moves safely along the wall, leaves it to draw a risky trail and reconnects. The game then solves which region is captured and rebuilds the wall around the new claim. Then the loop starts again.

Every later chapter builds one part of that sentence:

  1. Moving safely along the wall is built in Chapters 04 and 06.
  2. Drawing the trail is built in Chapter 07, and the fuse that chases it in Chapter 08.
  3. Solving the capture and rebuilding the wall is built in Chapter 09.

The three kinds of space ​

Every frame of the game contains exactly three kinds of space. The architecture of the course follows from keeping them apart. Figure 00-1 shows all three in one frame.

Figure 00-1: The three kinds of space in one frame: safe wall path, temporary trail and permanent claim
Figure 00-1: The three kinds of space in one frame: safe wall path, temporary trail and permanent claim
Kind of spaceWhat the player feelsWhat the code stores
Safe space"I cannot be hurt here."The wall path, derived from the tile grid.
Temporary danger"I am exposed until I reconnect."The trail, while its state is InProgress.
Permanent claim"That part of the arena is mine now."Tiles marked ClaimedByPlayer.

Two enums hold this data, and you meet both in Chapter 03. TileState says who owns each tile of the arena grid: Unclaimed, ClaimedByPlayer or Boundary. TrailState says where a trail is in its life: InProgress, Completed or Cancelled.

The match between what the player feels and what the code stores is direct. You should expect the same discipline everywhere in the course.

Requirements, services and operations ​

The course is built on three words. Each one has a fixed meaning, and each one connects to the next.

  • A requirement says what must be true for the player. It has an ID, such as FUS-04, and an acceptance check with real numbers.
  • A service is a class that owns one kind of truth about the game. The fuse service owns the fuse timer and the burn distance. It has no window and no graphics device, so nothing about drawing can leak into its rules.
  • An operation is a public method of a service. It changes the truth the service owns. It also keeps a contract: what it takes, what it gives back, what it promises and what it refuses.

A test proves that an operation keeps its contract. The requirement catalogue lists every requirement of the finished game. Each row names the requirement, its acceptance check, the operation that meets it, the test that proves it and the chapter that builds it.

Here is one requirement followed from row to test. FUS-04 reads: "Moving pauses the fuse. Stopping again resumes it from where it was." Its acceptance check says the burn distance holds while the player moves. The operation that meets it is FuseSystem.Update. The test that proves it is FusePausesWhenPlayerMoves_AndResumesOnStop. You build all four links in Chapter 08. Figure 00-2 shows the chain.

Figure 00-2: The chain from a requirement to its test, shown for FUS-04

Three more rows show how the catalogue reads. Do not memorise them. Notice that each one names a single operation and a single test.

IDRequirementOperationTestChapter
ARN-04A position inside the arena maps to exactly one tile. A position outside maps to none.ArenaSystem.TryWorldToGridTryWorldToGrid_MapsPositionsInsideBounds_AndRejectsOutside03
TRL-04The player cannot reverse along their own trail.TrailSystem.CanAdvanceCanAdvance_BlocksReversal_OntoActiveTrail07
CAP-04The claimed region is the smallest region with no enemy in it.AreaClaimingSystem.TrySelectEnemyFreeRegionProcessCompletedTrail_AvoidsEnemyRegion09

The service map ​

Services do not float free. The finished game has layers, and each layer may use the layers below it and never the layers above. Figure 00-3 shows the layers and the chapter that builds each box.

Figure 00-3: The layer map of the finished game, with the chapter that builds each part

Read the figure from the top. The platform starts the host. The host owns the scene manager. A scene, such as GameplayScene, owns a simulation and the renderers. The simulation calls the services, and the services read and write plain data.

Do not try to absorb every box now. Return to this figure whenever a chapter names a service and you want to know where it sits.

Why the host stays thin ​

The MonoGame host is the class that owns the window and the game loop. In this course it knows almost nothing about the rules. It builds the shared services, hands each frame to the current scene and saves the profile on exit.

The rules live in a class called GameplaySimulation. It has no window and no graphics device, so a test can create one, feed it input and read the result.

This is what makes every rule testable. Death, shields, respawn and the fuse are all reachable from a test. A rule that lives inside a window class cannot be tested until the window is open, and a test cannot open one.

How each chapter works ​

Every implementation chapter has the same shape, so you always know where you are. The sections come in this order:

  1. A recap of the last chapter and a one-sentence goal.
  2. The end-state figure and the time estimate.
  3. The requirements the chapter builds, as a table of IDs.
  4. Concept sections that explain the ideas before any code.
  5. One section per service, with one subsection per operation.
  6. Wiring the new service into the game.
  7. Running the tests, with the exact count to expect.
  8. Running the game, with the keys to press and what you should see.
  9. Common mistakes, where the chapter has any.
  10. A conclusion that lists the requirements now proved.
  11. Test Your Knowledge, with hidden answers.
  12. Extensions, where the chapter has any.

Inside each service section, every operation is built in the same five steps. The rhythm never changes:

  1. Read the contract card. It is a four-line summary of what the operation takes, gives, promises and refuses.
  2. Add the signature. The body is throw new NotImplementedException();, which keeps the test project compiling.
  3. Add the tests. You write one test per promise and one per refusal on the card, run them and see them fail.
  4. Write the body. You run the tests again and see them pass.
  5. Read the explanation. A short list, headed "The key things to note are:", says what the code does and why.

The tests come first because a test that has never failed has never proved anything. The stub lets you watch a test fail for the right reason, without first meeting a page of compiler errors.

Each chapter also asks the same six questions. They are the through-line of the course:

  1. What is the player feeling here?
  2. Which requirement makes that feeling possible?
  3. Which service owns that truth?
  4. Which operation changes it, and what does that operation promise?
  5. What maths or algorithm supports it?
  6. Which test proves it?

Sketch exercise ​

You need a pencil and paper for this exercise. Follow these steps:

  1. Draw a rectangle for the arena.
  2. Colour the wall path with one colour. This is the safe space.
  3. Draw a line from the wall into the middle with a second colour. This is the temporary danger.
  4. Fill one corner of the arena with a third colour. This is the permanent claim.
  5. Next to each colour, write the TileState or TrailState value that backs it.

Most people draw the wall path as the outline of the whole rectangle. Ask what happens to that outline after the first capture. Chapter 06 answers the question.

Compare your sketch with Figure 00-1 when you finish.

Contract exercise ​

This exercise uses the contract card format. Here is an example of a card, for an operation you build in Chapter 07:

TrailSystem.CanAdvance(intendedPosition, arena, direction, lastDirection) : bool

  • Takes: where the player wants to go, the arena, the direction of this move and the last accepted direction.
  • Gives: true when the trail may extend to that point.
  • Promises: an unclaimed target with no reversal is accepted.
  • Refuses: a move straight back along the trail, a claimed target, and any call with no active trail.
  • Requirements: TRL-04, TRL-05.

Write your own card for this requirement: "the player cannot walk through claimed ground". Use paper and give the card four lines: takes, gives, promises and refuses.

When you finish, compare your card with the MOV-03 row of the requirement catalogue. Then compare it with the TryMoveAlongPath card in Chapter 06: The Wall Path Service. The wording will differ. Check that your promises and your refusals match.

Before Chapter 01 ​

You need four things in place before the next chapter. Complete these steps in order.

  1. Install the .NET 10 SDK from the .NET download page. Open a terminal and run dotnet --version. The output should start with 10..
  2. In a terminal, run dotnet new install MonoGame.Templates.CSharp. This installs the MonoGame project templates.
  3. In a terminal, run dotnet new list monogame. The output should list the MonoGame templates.
  4. Clone the course repository, as the course index describes, and note its path. This course calls that path <course-repo>.

NOTE

The course index has the full install and clone commands for PowerShell and bash, with the ZIP download as an alternative to cloning.

Conclusion ​

In this chapter, you learned the following:

No requirements are proved in this chapter. In Chapter 01: The Project and the Host, you generate the project and open the first window.

Test Your Knowledge ​

  1. Name the three kinds of space and the data that backs each one.

    Answer

    Safe space is the wall path, derived from the tile grid. Temporary danger is a trail in progress. Permanent claim is the tiles marked ClaimedByPlayer.

  2. What is the difference between a requirement and an operation?

    Answer

    A requirement says what must be true for the player. An operation is the method that makes it true. The operation has a contract, and a test can check that contract.

  3. Why can a test reach the fuse rule in this course?

    Answer

    The rules live in GameplaySimulation and the services it calls. They need no window and no graphics device, so a test can create them and call them directly.

[^qix]: Qix was designed by Randy and Sandy Pfeiffer and published in arcades by Taito America in October 1981. Taito followed it with Qix II: Tournament (1982), Super Qix (1987), Volfied (1989) and Qix++ (2009), and many other games have borrowed the idea since. Qix is a trademark of its owner. Last Perimeter is an independent game inspired by Qix (Taito, 1981). It is not affiliated with or endorsed by that owner.