The Interrupted Turn Keeper
Follow instruction sequences to guide the character to the goal.
- Web browser (Chrome, Edge, Firefox)
- Internet connection
- Scratch 3.0 online editor
🔧 Build Your Interrupted Turn Keeper
when [green flag] clicked
set [current_player v] to [1]
set [game_paused v] to [0]
say [Game ready! Player 1 goes first.]
when [space v] key pressed
if <(game_paused) = [0]> then
if <(current_player) = [1]> then
set [current_player v] to [2]
else
set [current_player v] to [1]
end
say (join [Active Turn: Player ] (current_player))
end
when [p v] key pressed
if <(game_paused) = [0]> then
set [game_paused v] to [1]
say [Paused! Turn saved safely.]
else
set [game_paused v] to [0]
say (join [Resumed! Ready for Player ] (current_player))
end
The game_paused guard prevents the turn counter from changing during an interruption.
⚗️ Test your model
| Test Condition / Action | Expected Result |
|---|---|
| Press Space key | Toggles turn display between Player 1 and Player 2 |
| Press P key (Pause) | Freezes turn keeper; says 'Paused! Turn saved safely' |
| Press Space while paused | Turn does not advance; previous active player is preserved |
Add a third player (Player 3 - Chidi) so three friends can share game turns fairly!
📖 Our Story & Concepts
Have you ever played a fun board game with a friend during school break, and suddenly the bell rang for assembly? When you return to the classroom, who had the next turn? Arguments often happen when people forget!
Computers have a wonderful superpower called digital memory. By storing information in a labeled container called a variable, a program can remember who was playing even if hours pass or the game is paused. This ensures fairness and trust for everyone.
</> Full Annotated Code Walkthrough
// Full Turn Keeper with 3-Player Support & Pause Memory
when [green flag] clicked
set [current_player v] to [1]
set [game_paused v] to [0]
set [total_turns v] to [0]
say [Fair Play Turn Keeper Online!] for (2) seconds
when [space v] key pressed
if <(game_paused) = [0]> then
change [total_turns v] by (1)
if <(current_player) = [1]> then
set [current_player v] to [2]
else
set [current_player v] to [1]
end
play sound [Pop v]
say (join [Turn ] (join (total_turns) (join [: Player ] (current_player))))
end
when [p v] key pressed
set [game_paused v] to ((1) - (game_paused)) // Toggle 0 and 1
The game_paused guard prevents the turn counter from changing during an interruption.
▷ Expected Results & Troubleshooting
| Test Condition / Action | Expected Result |
|---|---|
| Press Space key | Toggles turn display between Player 1 and Player 2 |
| Press P key (Pause) | Freezes turn keeper; says 'Paused! Turn saved safely' |
| Press Space while paused | Turn does not advance; previous active player is preserved |
⚑ Extension Challenges & Blueprints
- Level 1: Add a sound effect that plays a high note for Player 1 and a low note for Player 2.
- Level 2: Display a turn counter showing how many total turns have been played today.
- Level 3: Add Player 3 so the rotation follows: 1 -> 2 -> 3 -> 1.