Today's classwork goes along with Chapter 6, Section 2. You will be writing conditionals and thinking about logic.
The following work needs to be checked off when you have completed it.
You should complete the tutorial in the lecture notes that writes and uses the three functions world.objectThatIsShorter, world.objectThatIsShorterOf3, and the chicken function chicken.changeColor. If you followed along in lecture, you have already completed this part, but you still need to show us this world when you get checked off.
Download the Zeus world from the web page. Your computer may save it as a zip file, be sure to rename it as a .a2w file.
Run the program and look at the
shootBoltto see what they do.
shootBolt with a given
philosopher and color will have Zeus send a lightning bolt
at that philosopher and
turn the philosoher that color. If you try to shoot at philosopher
who's color is black, Zeus won't do it. If you try to shoot at something
is not a philosopher, Zeus won't do it.
In what follows, only modify or create the functions or methods specified. You should NOT modify other existing functions and methods.
Write the world method called
has one object parameter called target. This method attempts to shoot
bolt at target and turns it the appropriate color. This method should call
shootBolt which has already been written for you.
world.myFirstMethod, remove the call to
shootAllBoltsExampleand instead add a call to
shootAllBolts. Then add code to
shootAllBoltsto call only
shootBoltAtTargetseveral times for different philosophers. Make sure you zap one philosopher at least 4 times!
IsClosestToMethat has three object parameters: obj1, obj2 and obj3. This function returns whichever object (obj2 or obj3) that is closest to obj1.
shootAllBoltsby invoking shootBoltAtTarget with Target set to the result of calling the function
isClosestToMewith three philosophers. Test this function with several different calls.
IsClosestToMe3that has four object parameters: obj1, obj2, obj3, and obj4. This function returns whichever object (obj2, obj3 or obj4) that is closest to obj1.
shootBoltAtTargetwith Target set to the result of calling the function
IsClosestToMe3with four philosophers. Test this function with several different calls.
If you finish early, feel free to embelish your animations.