I.E Semester Review E

(Review from January 2022.)

We are writing an animation where you are supposed to click on a random target color. Hitting a key gives you a new random color.

  1. The model is a number. When the number is 10, the “target color” is red. When the model is 20, the target is green. Write a function that randomly produces either 10 or 20.

     (define (random-target n)
         ...)
    
  2. The image to make is a 300x150 rectangle. The left half is red. The right half is green. There is text that explains “Target: XXX”, depending on which color you are supposed to hit.

  3. The mouse handler is going to add 100 to the model when the correct color is clicked on, and 200 when the incorrect color is clicked on. The mouse handler ignores events that are not clicks.

  4. The game stops when you click on a color - either you win or you lose. Display a “W” or an “L” on the side of screen that you clicked on.

Starter Code

This starter code was not really necessary.

(require picturing-programs)

(define (mk-sq c) (square 150 "solid" c))
(define (mk-txt t) (text t 40 "black"))
(define R (mk-sq "red"))
(define G (mk-sq "green"))
(define gap  (mk-sq (make-color 200 200 200 150)))
(define lose (overlay (scale 2 (mk-txt "L")) gap))
(define win  (overlay (scale 2 (mk-txt "W")) gap))
(define bg (beside R G))

Sample Images

Target was green, clicked on green.

Target was green, clicked on red.

Target was red, clicked on green.

Last modified August 18, 2023: 2022-2023 End State (7352e87)