CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.

Slides:



Advertisements
Similar presentations
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
Advertisements

As you come in…  Sign in (in back) and pick up  Badge  Name Card – write your first name LARGELY on back  Log in:  Launch/Start Alice  Any questions?
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
CS320n –Visual Programming Random Numbers and Random Motion (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Execution Control with If/Else and Boolean Functions Example: Single Condition Alice.
Wizard Game: Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Creating Functions Deborah Nelson Duke University Professor Susan Rodger July 22, 2008.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Shorter of two objects and changing color Functions, events and setting the color Susan Rodger, Duke University June 2008.
As you come in…  DOWNLOADS FOR TODAY:  CarGameTeacherStarter.a2w  Online student textbook.
Checking for Collisions Ellen Yuan Under the direction of Professor Susan Rodger at Duke University June 2014.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Execution Control with If/Else and Boolean Functions
Execution Control with If/Else and Boolean Functions Sec 52 Web Design.
Execution Control with If/Else and Boolean Questions Part 1 Alice.
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
CompSci 4 Chap 5 Sec 1 Oct 13, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Shorter of two objects and changing color V2 Functions, events and setting the color in sequence and randomly This is a modification of the Changing Color.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Checking for Collisions: Alternative Method Erin Taylor Under the Direction of Susan Rodger July 2015 Duke University.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Execution Control with If/Else and Boolean Functions Alice.
Game Maker Terminology
CS320n –Visual Programming Introduction to Recursion (Slides 8-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch Paul Tennent
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Mathematical Expressions, Conditional Statements, Control Structures
CS320n – Elements of Visual Programming Lists Mike Scott (Slides 9-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n – Elements of Visual Programming Sending Parameters to Event Handler Methods (Slides 5-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Programming: Simple Control Structures
Programming: Simple Control Structures MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Variables & Conditions.
Tutorial on Kangaroo visiting his animal friends - parameters, events Susan Rodger Duke University June 2009.
Obj: Programming: Simple Control Structures HW: Read section 3 – 2 AC3 D2 Do Now: 1.Log on to Alice. Open the file firstEncounter.a2w located in the folder.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Controlling Program Flow with Decision Structures.
Programming: Simple Control Structures Sec 46 Web Design.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
CS320n –Visual Programming Problem Solving Case Study (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
CS320n – Elements of Visual Programming List Search Mike Scott (Slides 9-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Programming: Simple Control Structures
Execution Control with If/Else and Boolean Functions
Programming: Simple Control Structures
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Simple Control Structures
Tutorial on Kangaroo visiting his animal friends - parameters, events
Let's Race! Typing on the Home Row
Microsoft Visual Basic 2005 BASICS
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
CS320n –Visual Programming
CS320n –Visual Programming
Checking for Collisions: Using Functions in Alice
Programming: Simple Control Structures
Restricting Events Creating Conditional Events in Alice By Henry Qin
Decision Statements.
Presentation transcript:

CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.

Elements of Visual Programming if / else statements2 What We Will Do Today Learn about –using if / else statements to control the flow of a program –using boolean functions

Elements of Visual Programming if / else statements3 Adding More Complexity to Worlds Initially programs were not interactive –program ran and user watched Then learned how to make programs interactive –add events to program –when event occurs an event handler method is called –adds variability to programs –not always the same thing happening

Elements of Visual Programming if / else statements4 Event Driven Programming a whole philosophy of programming called “event driven” programming flow of program controlled by external events as opposed to things internal to the program very important in user interfaces –the parts of programs that interact with real users think about using a computer –the operating system ( Windows XP, Mac OS X, etc. ) has a large component that is event driven –responding to your actions. (Move mouse, click, type)

Elements of Visual Programming if / else statements5 Internal Decision Making To build more complex programs and animations external decision making is needed in the form of events … But also need internal decision making important in many types of programs –good examples are simulations and games

Elements of Visual Programming if / else statements6 Examples of Decisions A race car simulation driver provides input from steering wheel, gas pedal, and brake –if car stays on road display next section of road –if car hits another car, crash –if car goes too far off road, crash –if pass checkpoints, more time

Elements of Visual Programming if / else statements7 Logical Expressions Program must make decision based on current conditions –on road? time left? intersected another car? Conditions are checked in a logical expression (also called a boolean expression) the logical expression evaluates to true or false –car on road -> true –car passed finish line -> false –car intersected any other cars -> false

Elements of Visual Programming if / else statements8 If/Else In Alice, a logical expression is used as the condition in an If/Else control structure. Decisions (using If/Else) are used in – functions – methods IF ELSE

Elements of Visual Programming if / else statements9 Example: Boolean Question Suppose you are building a simulation system used to train flight controllers. One of the tasks of a flight controller is to be alert for possible collisions in the flight space.

Elements of Visual Programming if / else statements10 Problem Description two aircraft –biplane and helicopter as biplane moves towards helicopter make sure they do not collide if they are too close, they need to adjust altitude (height) or course (direction of travel)

Elements of Visual Programming if / else statements11 Problem Description two factors in determining whether two aircraft are in danger of collision –total distance between them center point to center point –vertical distance between them differences in height both distances must be greater than some safe distance otherwise aircraft are too close red line: total distance green line: vertical distance a method or a function? class level or world level?

Elements of Visual Programming if / else statements12 tooCloseByTotalDistance isTooCloseByTotalDistance: Parameters: aircraft1, aircraft2, minDistance return true if the distance between aircraft1 and aircraft2 is less than minDistance else return false Whether the distance between aircraft1 and aircraft2 is less than minDistance is an example of a boolean expression. It is either true of false return result of expression

Elements of Visual Programming if / else statements13 Steps in building function Select the world object and click on the functions tab select new function

Elements of Visual Programming if / else statements14 Steps in building function type in name of function pick Boolean for the return type (function will return true or false) add parameters for 2 objects (the aircraft) and a number (min distance)

Elements of Visual Programming if / else statements15 Steps in building function function returns true want to return if distance between aircraft is less than minDistance select World functions pick a < b and drag to replace true –example of a relational operator

Elements of Visual Programming if / else statements16 Steps in building function replace true fill in a and b with dummy values (like 1)

Elements of Visual Programming if / else statements17 Steps in building function would like to drag aircraft1 parameter and call distance to function can’t  select biplane and the distance to function drag that to replace 1

Elements of Visual Programming if / else statements18 Steps in building function replace dummy objects with parameters aircraft1 and aircraft2 replace second 1 with minDistance

Elements of Visual Programming if / else statements19 Completed Method

Elements of Visual Programming if / else statements20 Using if / else in World.my first method check to see if the aircraft are too close IF they are then avoid a collision –hard code motion OR –create a method to avoid the collision to use if / else in program drag if /else from bottom

Elements of Visual Programming if / else statements21 Using if / else if statement tests a boolean expression can be a relation operator OR a function that returns a boolean OR a boolean value (true / false)

Elements of Visual Programming if / else statements22 Completing the if / else replace parameters with biplane and helicopter call method avoid collision if the condition is true nothing to do if they are not to close

Elements of Visual Programming if / else statements23 Completing avoid collision assume if aircraft are too close one moves up and one moves down to increase the vertical distance between them –elevation separation does it matter which moves up and which moves down?

Elements of Visual Programming if / else statements24 using if / else is avoid collision Move the aircraft that is above the other up

Elements of Visual Programming if / else statements25 isTooCloseVerticalDistance check to see if aircraft are in the same strata to find difference in altitude use the built-in distance above function –don’t know which aircraft is above the other –to avoid possible negative value, use the absolute value of the distance (World level function)

Elements of Visual Programming if / else statements26 Adding Motion create a method that moves an aircraft forward some distance if the two aircraft are closer than twice the distance of the move –avoid collision if they are the vertical distance between them is too small –move aircraft forward twice the distance

Elements of Visual Programming if / else statements27 forward And Check Collision

Elements of Visual Programming if / else statements28 check For Height Collision