Building a simple game with variables and score
Computer Science · Key Stage 2 · The School
Bringing the pieces together
A simple game brings together everything learned across this key stage. EVENTS trigger actions. VARIABLES remember the score. SELECTION decides what happens when something is touched. None of these ideas is new here. This is where they finally work together, all at once, in one project. A game like this can look impressive while using nothing more advanced than that.
Keeping score
A score variable starts at zero. An event rule adds one to it whenever a coin is touched. Another rule shows the current score constantly on screen. The player sees their own progress update the instant it changes. Nothing about scoring is new here. It is the same "set, change, use" pattern from the variables lesson. A lives counter or a timer could be built the exact same way.
Deciding when the game ends
A rule can check the score continuously. If the score reaches 10, show "You win!" and stop the game. This is selection again. It is just applied to a variable that keeps changing throughout play. It is not checked only once. The rule itself never changes. Only the score it is watching does.
Testing and finding an unfair rule
A first version awards a point for touching a coin. It does not remove the coin afterwards. So a player can win instantly by staying on one spot. Making the coin disappear once touched fixes the game completely. Only real play testing uncovered the shortcut. Reading the code alone had made the rule look perfectly fine.