Game State and Reducer Structure
Defining the Initial State and Reducer Structure
In the last two lessons, you built the global store with useReducer + Context and used it to drive screen changes. As a quick reminder, our UI now depends on state, and navigation is just dispatching actions. In this lesson, you will shape that state for a real game and set up the reducer to handle the first transitions.
Designing the Initial Game State
We start by defining constants and a single source of truth for all game data. This makes future updates predictable and testable.
Explanation:
RUSH_DURATIONandMAX_QUEUEare constants that keep magic numbers out of the state.ui.screencontrols which view is visible (from the previous lesson’s pattern).configholds difficulty, queue limits, starting resources, and arrival rates — perfect for tuning without touching UI code.timersmodel the game clock and pause state.resourcesandshophold the core gameplay stats you will read and update in later units.profilepersists player-wide stats; passingprofileintogetInitialStatelets you reset a run without losing the player’s progress.historyandresultare placeholders for undo/logging and end-of-run data.
