Presentation is loading. Please wait.

Presentation is loading. Please wait.

Complex Conditionals Human languages are ambiguous

Similar presentations


Presentation on theme: "Complex Conditionals Human languages are ambiguous"— Presentation transcript:

1 Complex Conditionals Human languages are ambiguous
Computer languages must be precise Complex Conditionals Describe what happens If Game.MouseX >0 duck.visible = true; else duck.visible = false; CSD Code Studio Level 9

2 Identify the parts If Game.MouseX >0 duck.visible = true; else duck.visible = false; What’s the Boolean condition? What happens when the condition is true? What happens when the condition is false?

3 Puzzle 3: Why do the gears always move?
The gears always move but they change direction if the space key is pressed down.

4 Using ELSE, before you write the statements, figure out what sprites and variables are needed.
If the temperature is below freezing, wear a heavy coat, otherwise wear a jacket If the plane is below the horizon make it disappear otherwise it should be visible. If the up arrow key is pressed, the plane moves upward otherwise it moves down

5 What sprites and variables are needed?
If the temperature is below freezing, wear a heavy coat, otherwise wear a jacket What kind of variable is temperature? How do you ask if it is below freezing? What kind of variable is a coat or jacket? How do you change a sprite to look like it’s wearing different clothes?

6 Some games react to the time of day, season of year, holidays, and other factors.
This mini game has the alien put on a coat if the temperature is low. cts/gamelab/tGSnX4SATsupM SQ996_B_3cNCEKGN1RaWBc 44JcIjO8

7 What sprites and variables are needed?
If the plane is below the horizon make it disappear otherwise it should be visible. Assume there are 2 sprites: plane and horizon. What property of the sprites are you comparing? How do you make something disappear?

8 What sprites and variables are needed?
If the up arrow key is pressed, the plane moves upward otherwise it moves down What’s the code to ask if the up arrow key is pressed down? How do you move a sprite up? How do you move a sprite down?

9 Possible answers: Using ELSE
If the temperature is below freezing, wear a heavy coat, otherwise wear a jacket If the plane sprite is below the horizon sprite make it disappear otherwise it should be visible. If the up arrow key is pressed, the plane moves upward otherwise it moves down

10 Puzzle 4: What happens? Read the code.
screen Questions: Are the bees there all the time? Yes, but their visibility changes When do the bees appear or disappear? How do you know that the bees are following the mouse? (You can’t tell from just this part of the code, but if you Look at Stage 9 puzzle 4 you can see the complete code.

11 These are more Boolean functions in CodeLab
mouseDidMove() Returns true if the mouse did move if(mouseDidMove()) {} mouseWentDown(side) Returns true once when the specified mouse button is pressed down if(mouseWentDown("left")) {} mouseWentUp(side) Returns true once when the specified mouse button is released if(mouseWentUp("left")) {} keyWentDown(key) Returns true once when the specified key is pressed down if(keyWentDown("e")) {} keyWentUp(key) Returns true once when the specified key is released if(keyWentDown("m")) {}

12 Puzzle 5: Predict what happens
What seems to be the difference between keyDown(),  keyWentDown(), and keyWentUp()? What do you think the exclamation mark (!) on line 10 does?

13 Puzzle 7: Dropping balloon
Here's a program that drops a balloon down the screen – Program the mouse button to raise the balloon back up while it's clicked. Add an if else statement that checks for mouseDown Inside the conditional, move the balloon up one pixel if the mouse is down otherwise move the balloon down Pseudocode: If mouseDown Subtract 1 from balloon.y Else Add 1 to balloon.y

14 Puzzle 9 Salt shaker mouseDidMove PSEUDOCODE:
if mouseDidMove rotate the salt sprite randomly to the left or right. How do you rotate something randomly? mouseDidMove  return false if the mouse is still, return true if the mouse has been moving. Use mouseDidMove so that you can "shake" the salt by moving the mouse back and forth. Is this an IF or an IF-ELSE?

15 Work in code studio Stage 9
Human languages are ambiguous Computer languages must be precise


Download ppt "Complex Conditionals Human languages are ambiguous"

Similar presentations


Ads by Google