The lab is done in groups of 2 or 3. In the beginning of each file please write (in comments) the names of all group members.
At the end of the lab please send me and your group partner(s) all your Racket files as e-mail attachments. My e-mail is elenam at morris.umn.edu. The subject of your e-mail must be "1301 Lab 3", followed by your initials, followed by "Final" or "Not final", depending on whether this is a final submission or you are still working on it. If you need to finish it, make sure to set up a time with your group partner(s) to finish the lab.
Your task is to explore and modify world programs. Use the examples we used in class (on the resources page) for reference; there is also a link to the book chapter there. Make sure to ask questions when you are stuck.
For this task you start with the following world example: world-car-example-click.rkt. It has the starting code for handling keyboard keys and for ending the program when the car reaches far right end of the canvas. You need to fill in the missing pieces. Specifically:
move-on-key
. It is supposed to
move the car to the initial position when the left arrow key is pressed.
However, as is it just returns the current car position and fails two
of the check-expect tests. Change it to return the correct value.
Test it both by making sure that check-expects work and by running the
program and using the left arrow on the keyboard to move the car back to
the start.
cond
in the
move-on-key
to make it so that pressing the right
arrow key brings the car to the rightmost position of the canvas.
Uncomment the check-expect for the "right"
key and
replace ??? for this case by the correct value. After you've made both
of these changes, test your program both using check-expect and by
actually using the right key.
stop-when
part the big-bang
attaches a
function that checks the world state to see if the program needs to end.
It ends when the function returns #true
. Uncomment the part
of the big-bang that uses stop-when
and the end?
function below in the file. Currently end?
always returns
#false
, so the program never ends. We would like the program
to end when the car reaches the right side of the canvas. Examine the test
cases
and fill in the correct expression for end?
. Again, test
the program to make sure that everything works as expected.
For this task you start with the following world example: humpty-dumpty.rkt. Your task are as follows:
main
to see
what the world program is supposed to do and what the world state is.
render
to place the glass ball at the x coordinate
specified in the constant ball-x-coord
and the y coordinate
given
by the world state (it starts at the top of the canvas). Note that
check-expects give the correct behavior and provide a hint for the
expression in render
. You don't need to implement the
ball breaking as it reaches the ground.
fall
function to make the ball falling at the number of
pixels per clock tick that's given in the variable speed
.
Uncomment the check-expects, fill in the right expression, and run the
program to test. The ball doesn't need to stop at the bottom of the canvas.
distance
and within-radius?
. Make sure to read the signatures, the
descriptions and the check-expects. Note that the
within-radius?
helper function
uses the distance
.
You might want to look up the formula
for distance between two points.
within-radius?
function, write the
move-to-start
function according to its comments and
tests. Uncomment the line in big-bang that uses it as a mouse handler.
Test your program.
fall
function so that once the ball reaches
the ground (see ground-size
constant), it stops falling and
remains at the same position. That would require making fall
into an if
or a cond
. Add tests to check
for this case.