Game Programming Logic
שאלות 10
מפתח התשובות מוצג למורים מחוברים.
-
Variables in a game score
A game programmer writes code that stores the player's current score and increases it by 10 each time the player collects a coin. Which programming concept is being used to hold the changing score value?
A conditional branch
A loop counter only
A constant that can never change
A variable
Think about a named storage location whose stored value can be updated while the program runs. -
Loop repeating game actions
A game must move an enemy 5 steps to the left, one step per frame. Which control structure is most appropriate for repeating the movement step exactly 5 times?
A switch statement with no cases
A for loop
A variable declaration
An if statement
Consider which structure is designed to repeat a block of code a known number of times. -
Conditional logic for player health
In a game, the code should end the game when the player's health is less than or equal to zero, and otherwise continue playing. Which construct implements this decision?
A variable named health
A while loop with no condition
A function call to draw the background
An if-else statement
Think about the structure that chooses between two different paths depending on whether a condition is true or false. -
Combining loops and conditions
A game loop runs once per frame while the game is active. Inside it, the program checks whether a player has touched a power-up and, if so, sets a boolean variable named hasShield to true. What is the best description of the role of the game loop?
It declares the data type of hasShield
It repeatedly executes the game logic until the game ends
It converts the boolean value into a string
It runs only once and then the program exits
Consider how a game keeps updating and checking state over and over during play. -
-
-
-
Boolean variables and conditional statements
A _________ variable holds only true or false, and an _________ statement runs one block of code when it is true and another when it is false.
stringbooleanintegerswitchwhileif-elseThe first blank names the data type that stores only two possible values; the second blank names the decision structure with two branches. -
Tracing a while loop that moves a sprite
A game stores a sprite's travelled distance in the variable distance, starting at 0, and its speed in the variable speed, set to 12. The code runs this loop: while distance < 50: distance = distance + speed. After the loop finishes, what is the value of distance? Give only the number.
Trace each pass of the loop by hand and write down the value of distance after every pass. Stop when the condition distance < 50 is no longer true. -
Why game state must be stored in variables and updated each frame
Explain in two or three sentences why a game stores a player's position in a variable and updates that variable inside the game loop on every frame, instead of setting the position once at the start of the program.
Think about what happens to a variable's value between frames, and what the game loop repeats on each frame.
פרטים
- מקצועות
- תוכנה
- קהל יעד
- תיכון · כיתות י׳–י״ב
- רמת קושי
- 6 מתוך 10
- שפה
- אנגלית
- מי יכול לראות
- כולם
- נוצר באמצעות AI
- Claude Haiku 5.5
- נוצר
תגובות