CompSci 4 - Classwork - Sep 27, 2005
5 pts
Today's classwork goes along with Chapter 6, Section 1.
You will be using built-in functions and writing your own functions.
Note in each step whether you are writing a function
or a method. If it is a function, make sure you select
the correct type of return value.
The following work needs to be checked off when you have completed it.
- Create a new Alice world with some type of vehicle that has four wheels.
Write a class function for this vehicle called numberOfRevolutions (similar
to what I did in lecture) that has a distance parameter and returns the
number of revolutions a wheel of the vehicle should turn for the given
distance.
In world.myFirstMethod, add code so your vehicle moves
forward and backward with all four wheels having realistic
wheel motion.
- Add in two objects, a large object (such as a pyramid or
building) and a smaller object (such as a person).
- Write a class function for your vehicle called stoppingDistanceInFrontOf
that has an object parameter. This function should return two plus twice
the width of the object parameter
- Write a class function for your vehicle called timeToJump that has an
object parameter. This function should return one plus the object's height
divided by 5.
- Write a class function for your vehicle
called OptimalHeight that has an object
parameter.
This function should return the object's height plus half of the object's
width.
- Write a class method for your vehicle called
headToObject that has two parameters,
a direction and an object. This method should have your vehicle
turn to face the object (as seen by the ground), and then realistically
roll in the given direction for the distance of the vehicle to the object
minus the stoppingDistanceInFrontOf the object.
- Write a class method for your vehicle called
jumpOver that has one object parameter.
This method should at the same time move your vehicle up the OptimalHeight of
the object and move the vehicle forward the stoppingDistanceInFrontOf
the vehicle.
Then the method should at the same time move the vehicle down the OptimalHeight
of the object and move the vehicle forward the stoppingDistanceInFrontOf
the
object. All of these commands should be done in the same amount of time,
specifically for the timeToJumpOver the object. (Thus, the total time for
this
method to execute is twice timeToJumpOver).
-
Now it is time to use all these methods and functions that you have
written.
Append to world.myFirstMethod code to have the car head to one of the
objects and jump over it, then to head to the other object and
jump over it.
If you finish early, feel free to embelish your animations.