I.9 Semester I Review 9
Basics
-
There will be a white Christmas if the temperature is below 32 and there is
water?
;; white-christmas?: boolean(water?) number(temperature) ;; -> boolean (define (white-christmas? water? temperature) ...)
-
Give examples showing how to get “ACE”, “BETA”, and “CROW”.
(define (q2 x y? z) (cond [(and y? (< x 30)) "ACE"] [(or (not y?) (string=? z "good")) "BETA"] [else "CROW"]))
-
Write this function:
;; q3 : number number number string -> number (define (q3 m x y e) ...)
- give -10 when x > 200 and e is “button-down”
- give -20 when x < 200 and e is “button-down”
- give m otherwise
Simple Animation
- The model is a number, a multiple of 10 from 10 through 90.
- Losing is indicated by adding 100 to the number, so the losing models will be 110, 120, …, 190.
- Winning is indicated by adding 1000 to the number, so the winning models will be 1010, 1020, …, 1090.
Examples: when the model is 40, you see “PLAY 40”; when the model is 130, you see “LOSE 30”; when the model is 1070, you see “WIN 70”.
- Write the
win? : model(number) -> boolean
function to give true when the model indicates a win. Write a similar functionlose?
. Write two check-expects for yourlose?
function, picking a winning value and a “playing” value check-expect for yourwin?
function - Make a draw handler that shows WIN, LOSE, or PLAY above the number. Make sure you can still see the number in all cases.
- Make a key handler that randomly choses 10 through 90.
- Clicking the mouse on the right side of the screen wins (button-down and x>50). Clicking the mouse on the left side loses. No other mouse actions (including move) change the model.
- Test your code in a big-bang.
- Write
should-stop?
that will stop when the model indicates a win or a lose. Add it into your big bang. Use your ordinary draw handler as the final scene draw handler.
Notes
Some people did confusing things.
temperature
should not end in a question mark because it is not a true or false value- You know
water?
is a true or false, not a string, because its name ends in a question mark. - Do not compare
(string=? water? "water")
, see the previous. - Boolean variables are themselves true or false; they do not need to
be compared using
boolean=?
. The variable name poses a question, and the value inside answers it. - The
win?
function should not just be the opposite of thelose?
function.