#reader(lib "htdp-beginner-reader.ss" "lang")((modname reflex-scene) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(define react-time 50)
(define wait-time 500)
(define blink-time 10)
(define-struct world (time-remaining score))
(define init-world (make-world 0 0))
(define (key-handler world key)
(if (key=? key 'up)
(if (<= (world-time-remaining world) react-time)
(make-world (+ react-time (random wait-time)) (+ (world-score world) 1))
(make-world (+ react-time (random wait-time)) (- (world-score world) 1)))
world))
(define (tick-handler world)
(if (<= (world-time-remaining world) 0)
(make-world (+ react-time (random wait-time)) (world-score world))
(make-world (- (world-time-remaining world) 1) (world-score world))))
(define (background world)
(if (and (<= (world-time-remaining world) react-time)
(> (world-time-remaining world) (- react-time blink-time)))
(rectangle 100 100 'solid 'red)
(rectangle 100 100 'solid 'gray)))
(define (score world)
(text (number->string (world-score world)) 12 'black))
(define (redraw world)
(place-image (score world) 0 0
(place-image (background world) 0 0
(empty-scene 400 300))))
(big-bang 400 300 init-world
(on-tick 0.01 tick-handler)
(on-key key-handler)
(on-redraw redraw))