DOC PREVIEW
Duke CPS 004 - Chapter 6

This preview shows page 1-2-20-21 out of 21 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CompSci 4 Chap 6 Sec 2 Part 1 Mar 10, 2005AnnouncementsWhat we will do todayThinking about More Advanced WorldsExamples of DecisionsLogical ExpressionsIf/ElseExample: Boolean FunctionsStoryboardStoryboard (cont)isTooCloseByDistanceUsing a Relational OperatorImplementing the FunctionVertical Distance FunctionistooCloseByVerticalSlide 16Implementation and Calling FunctioncheckForHeightCollisionAvoid CollisionDemo and TestingClasswork todayCompSci 4Chap 6 Sec 2 Part 1 Mar 10, 2005Prof. Susan RodgerNote: thanks to Wanda Dann and Steve Cooper for slide ideasAnnouncements•Finish Chapter 6, Sec 2 for next time•Next assignment handed out after spring break – enjoy your break!•Pixar Talk – Monday, March 21, 7:30pm–Computers Don’t Make Movies–LSRC B101What we will do today•Lecture on Chap 6, Sec 2 through page 170–Execution control with if/else statements and Boolean functions•ClassworkThinking about More Advanced Worlds•How do you build animations like simulations and video games?•Need to write code that involves dec is ionsExamples of Decisions•A car-race simulation – the driver steers the car around curves and past mile markers–If the car stays on the road the score increases–If the car goes off the road into the stands, the car crashes–If the driver gets the car over the finish line, the time is posted and the driver wins!Logical Expressions•Decision is made based on current conditions.•Condition is checked in a logical expression that evaluates to true or false (Boolean) value.–car on road true–car over finish line falseIf/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–MethodsExample: Boolean Functions•Suppose we build a simulation system used to train flight controllers•One of the tasks of a flight controller is to be alert for possible collisions in flight spaceStoryboard• Two aircraft – biplane and helicopter•As the biplane moves towards the helicopter we want to make sure they do not collide•If they are too close, they need to adjust their altitude (height)Storyboard (cont)•Two factors in determining whether two aircraft are in danger of collision–Total distance between them–Vertical distance between them•Both functions return true if aircraft are too close, otherwise falseisTooCloseByDistanceisTooCloseByDistance:Parameters: aircraft1, aircraft2, minDistanceIf distance between aircraft1 and aircraft2 is less than minDistance return trueElse return falseUsing a Relational Operator•Use the < relational operator from the World’s built-in functions to check the distance against the minimumis equal tois not equal tois greater thanis greater than or equal tois less thanis less than or equal toImplementing the FunctionVertical Distance Function•To find the difference in altitude, use the built-in distance above function–Don’t know which aircraft is above the other–To avoid a possible negative value, use absolute value of the distanceistooCloseByVerticalStoryboardforwardAndCheckCollisionParameters: aircraft1, aircraft2, distanceaircraft1 move forward distanceIf aircraft1 and aircraft2 are closer than twice distance avoid collision if they are too close heightwise move aircraft1 forward twice the distanceImplementation and Calling FunctioncheckForHeightCollisionAvoid CollisionDemo and Testing•Create several events–Move plane backword–Move plane forward slowly and check for collisions–Try with planes at different heightsClasswork


View Full Document

Duke CPS 004 - Chapter 6

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 1

Java 1

24 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Graphics

Graphics

20 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

The Plan

The Plan

25 pages

Lecture

Lecture

16 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Chapter 5

Chapter 5

22 pages

Lecture

Lecture

4 pages

Chapter 4

Chapter 4

10 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download Chapter 6
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 6 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 6 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?