Sub topic 2
Designing Win, Lose, and Fail States
This chapter assumes you know basic game mechanics, can read simple Python (conditionals, functions, and enums), and have played several game genres.
Fail states: setbacks the player can recover from
A fail state is a setback that costs the player something but does not end the run. A lost life, a dropped item, or a reset to a checkpoint are all fail states. A lose state ends the run. Separating the two lets players learn from mistakes without losing all their progress.
Keep three outcome types distinct in your design:
- Fail state: the player loses something and can continue.
- Lose state: the run ends in defeat.
- Win state: the player reaches the goal and the run ends successfully.
Modeling outcomes as a state machine
Model the outcome as a state machine with three values: playing, won, and lost. On each frame or turn, the game checks its conditions and moves to one state. The order of the checks sets precedence. If a win and a loss happen in the same frame, whichever check runs first decides the result.
from enum import Enum, auto
class Outcome(Enum):
PLAYING = auto()
WON = auto()
LOST = auto()
def evaluate(health, relics, relics_needed):
# Lose is checked first, so a simultaneous win and loss resolves as a loss.
if health <= 0:
return Outcome.LOST
if relics >= relics_needed:
return Outcome.WON
return Outcome.PLAYING
print(evaluate(0, 3, 3)) # Outcome.LOST
print(evaluate(5, 3, 3)) # Outcome.WONMaking failure fair and readable
Players accept a loss when they can see its cause. Show the reason for each fail state immediately, and apply the same rules on every attempt.
| Design choice | Player effect |
|---|---|
| Visible cause shown on screen | Player knows what to fix |
| Same rules on every retry | Player trusts the system |
| Limited lives before a lose state | Stakes stay clear |
Communicating outcomes to the player
Give feedback at the moment the event happens. A short message, a sound, and an updated counter tell the player what changed. For a fail state, show the checkpoint the player will return to. For a lose state, show the final result and a clear retry option.
Exercise
A player drops to 0 health and collects the last relic in the same frame. Using the evaluate function above, what does it return, and why?
Show answer
It returns Outcome.LOST. The health check runs first, so the loss takes precedence over the win.