Computer Science Grade 5 20 min

Conditional Games

Conditional Games

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Design a game that uses a state variable to track progress (e.g., 'start', 'playing', 'win'). Write nested conditional statements (an IF inside another IF) to handle multi-step logic. Use compound conditionals with 'AND' to check if two or more conditions are true at the same time. By the end of a this lesson, students will be able to use compound conditionals with 'OR' to check if at least one of several conditions is true. Construct an 'IF...ELSE IF...ELSE' chain to choose between multiple possible outcomes. Debug a simple game by tracing the logic of its conditional statements. Ever played a game where you need a key AND to be at the right door to open it? How does the computer know to check f...
2

Key Concepts & Vocabulary

TermDefinitionExample Nested ConditionalAn IF statement that is placed inside another IF statement. The inner check only happens if the outer check is true.IF you have a ticket, THEN { IF you are on the right train, THEN you can ride. } Compound Conditional (AND)A single IF statement that checks if two or more conditions are true at the same time. All conditions must be true for the code to run.IF player_score > 100 AND player_level == 5, THEN unlock the boss level. Compound Conditional (OR)A single IF statement that checks if at least one of two or more conditions is true. Only one condition needs to be true for the code to run.IF has_magic_key OR has_super_strength, THEN open the enchanted gate. State VariableA variable that keeps track of the current status or 'state' of t...
3

Core Syntax & Patterns

The 'AND' Pattern IF (condition1 AND condition2) THEN ... Use this when an action requires multiple things to be true simultaneously. For example, to enter a secret room, you might need a key AND a map. The 'OR' Pattern IF (condition1 OR condition2) THEN ... Use this when an action can be completed in more than one way. For example, to defeat a monster, you could use a magic sword OR a fire spell. The Nested IF Pattern IF (outer_condition) THEN { IF (inner_condition) THEN ... } Use this for sequential checks. The program only checks the inner condition if the outer one is already met. This is great for things like checking if a player is at a door before checking if they have the key. The IF / ELSE IF / ELSE Pattern IF (condition1) THEN ......

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
You are fixing a bug in the 'Dragon's Treasure' game. The current code is: `IF (health > 50) THEN { IF (has_magic_shield) THEN { win_game() } }`. What is the critical logic error with this nesting order?
A.player with a shield but low health can still win.
B.player with no shield but high health will pass the first check, which is illogical.
C.The code will crash if the player has no shield.
D.The code uses 'health' which is a number, and IF statements only work with true/false.
Challenging
A game vault opens if a player has the `password` AND EITHER the `gold_key` OR the `silver_key`. Which code snippet correctly represents this complex logic?
A.IF (has_password AND has_gold_key OR has_silver_key) THEN ...
B.IF (has_password) OR (has_gold_key AND has_silver_key) THEN ...
C.IF (has_password AND (has_gold_key OR has_silver_key)) THEN ...
D.IF (has_password) THEN { IF (has_gold_key) THEN { IF (has_silver_key) THEN ... } }
Challenging
In a game, you need a `rope` AND a `torch` to enter a dark cave. You are testing the game. You discover that you can enter with just the rope, and you can also enter with just the torch. What is the most likely bug in the code?
A.The programmer used a nested IF instead of a compound conditional.
B.The programmer used `OR` where they should have used `AND`.
C.The programmer used `AND` where they should have used `OR`.
D.The variables for `rope` and `torch` are spelled incorrectly.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Advanced Topics

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.