;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-advanced-reader.ss" "lang")((modname |1301 Problem Set 10|) (read-case-sensitive #t) (teachpacks ((lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "gui.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp"))))) ;; CSci 1301: Problem Set 10 ;; Ken Broden, Alex Longerbone, Kate Kaus ;; ============== These are the two predefined functions ==================== ;; You don't need to understand their code, only the contract and the purpose ;; =========================================================================== ;; ===================== You may skip to the sample code below ================ ;; get-choice: string, list of strings -> integer ;; the function displays a simple menu form with the given message ;; and a drop-down menu with the list of choices. The menu ;; initially displays "Make a choice". Once a different item is chosen, ;; that item is returned. ;; When a "Close" button is pressed, the form disappears. (define (get-choice message list-of-choices) (local ( (define the-choices (make-choice (cons "Make a choice" list-of-choices))) (define w (create-window (list (list (make-message message)) (list the-choices) (list (make-button "Close" (lambda (e) (hide-window w))))))) (define (process-result n) (cond [(> n 200) (hide-window w)] ;; timeout after 200 sec [(= (choice-index the-choices) 0) (and (sleep-for-a-while 1) (process-result (+ n 1)))] [else true]) ) ) (cond [(process-result 0) (list-ref list-of-choices (- (choice-index the-choices) 1))]))) ;; get-answer: string number -> string ;; The function displays a simple text input with a question ;; and returns the answer typed in by the user ;; The second parameter (time-delay) is the number of seconds ;; the function waits after the typing of the first character ;; before it returns the answer. If the user takes longer ;; than that, a partial answer may be returned ;; 5 sec delay is reasonable for a one-word answer (define (get-answer question time-delay) (local ((define the-answer (make-text question)) (define w (create-window (list (list the-answer) (list (make-button "Close" (lambda (e) (hide-window w))))))) (define (process-result n) (cond [(> n 200) (hide-window w)] ;; timeout after 200 sec [(string=? (text-contents the-answer) "") (and (sleep-for-a-while 1) (process-result (+ n 1)))] [else true] ;; the user starts typing ))) (cond [(process-result 0) (cond [(sleep-for-a-while time-delay) (text-contents the-answer)]) ]) )) ;; =========================== do not change anything above this line ============= ;; NOTE: The language is Advanced Student. Teachpacks: gui.ss, draw.ss ;; =========================== Your work goes here: =============================== ;; =================================================== Our Characters/Backgrounds/Items/Other Functions ======================================================= ;; Characters ;;Nemo! (define (nemo start-posn) (and ;; Body (draw-solid-disk (make-posn (posn-x start-posn) (- (posn-y start-posn) 10)) 30 'darkorange) (draw-solid-disk (make-posn (posn-x start-posn)(- (posn-y start-posn) 5)) 30 'white) (draw-circle (make-posn (posn-x start-posn)(- (posn-y start-posn) 5)) 30 'black) (draw-solid-disk start-posn 30 'darkorange) ;; Mouth (draw-solid-disk (make-posn (posn-x start-posn)(+ (posn-y start-posn) 13)) 10 'white) (draw-solid-disk (make-posn (posn-x start-posn)(- (posn-y start-posn) 7)) 25 'darkorange) ;; Eyes (draw-solid-disk (make-posn (+ (posn-x start-posn) 13) (posn-y start-posn)) 8 'white) (draw-solid-disk (make-posn (- (posn-x start-posn) 13) (posn-y start-posn)) 8 'white) (draw-solid-disk (make-posn (+ (posn-x start-posn) 13) (posn-y start-posn)) 5 'darkorange) (draw-solid-disk (make-posn (- (posn-x start-posn) 13) (posn-y start-posn)) 5 'darkorange) (draw-solid-disk (make-posn (+ (posn-x start-posn) 13) (posn-y start-posn)) 3 'black) (draw-solid-disk (make-posn (- (posn-x start-posn) 13) (posn-y start-posn)) 3 'black) ;; dorsal fin (draw-solid-rect (make-posn (-(posn-x start-posn) 2) (- (posn-y start-posn) 55)) 4 15 'darkorange) (draw-solid-rect (make-posn (-(posn-x start-posn) 2) (- (posn-y start-posn) 55)) 4 2 'black) ;; small fin (draw-solid-disk (make-posn (- (posn-x start-posn) 32) (+ (posn-y start-posn) 10)) 4 'darkorange) (draw-solid-disk (make-posn (- (posn-x start-posn) 40) (+ (posn-y start-posn) 10)) 6 'black) (draw-solid-disk (make-posn (- (posn-x start-posn) 38) (+ (posn-y start-posn) 10)) 6 'darkorange) ;; regular fin (draw-solid-disk (make-posn (+ (posn-x start-posn) 32) (+ (posn-y start-posn) 10)) 6 'darkorange) (draw-solid-disk (make-posn (+ (posn-x start-posn) 44) (+ (posn-y start-posn) 10)) 12 'black) (draw-solid-disk (make-posn (+ (posn-x start-posn) 42) (+ (posn-y start-posn) 10)) 12 'darkorange) )) ;;Turtle (define (turtle start-posn) (and ;;Tail ;(draw-solid-rect (make-posn (posn-x start-posn)(-(posn-y start-posn) 70)) 5 10 'lightgreen) ;;Legs (draw-solid-rect (make-posn (+ 20 (posn-x start-posn))(+ 35 (posn-y start-posn))) 45 15 'lightgreen) (draw-solid-rect (make-posn (-(posn-x start-posn) 65)(+ 35 (posn-y start-posn))) 45 15 'lightgreen) (draw-solid-rect (make-posn (-(posn-x start-posn) 65)(-(posn-y start-posn) 50)) 45 15 'lightgreen) (draw-solid-rect (make-posn (+ (posn-x start-posn) 20)(-(posn-y start-posn) 50)) 45 15 'lightgreen) ;;Head & Body (draw-solid-disk start-posn 60 'darkgreen)(draw-solid-disk (make-posn (posn-x start-posn)(+ 62 (posn-y start-posn))) 20 'lightgreen) ;;Eyes (draw-solid-line (make-posn (- (posn-x start-posn) 10)(+ 58 (posn-y start-posn)))(make-posn (- (posn-x start-posn) 3)(+ 55 (posn-y start-posn)))'black) (draw-solid-line (make-posn (+ (posn-x start-posn) 10)(+ 60 (posn-y start-posn)))(make-posn(+ (posn-x start-posn) 3)(+ 55 (posn-y start-posn)))'black) ;;Mouth (draw-solid-line (make-posn (posn-x start-posn)(+ 78 (posn-y start-posn)))(make-posn (+ (posn-x start-posn) 12)(+ 70 (posn-y start-posn)))'black) (draw-solid-line (make-posn (posn-x start-posn)(+ 78 (posn-y start-posn)))(make-posn (- (posn-x start-posn) 12)(+ 70 (posn-y start-posn)))'black) ;;Shell designs (draw-circle start-posn 50 'lightgreen) (draw-circle start-posn 20 'lightgreen) (draw-solid-line (make-posn (- (posn-x start-posn) 45)(-(posn-y start-posn) 20))(make-posn(+ (posn-x start-posn) 45)(- (posn-y start-posn) 20)) 'lightgreen) (draw-solid-line (make-posn (- (posn-x start-posn) 45)(+(posn-y start-posn) 20))(make-posn(+ (posn-x start-posn) 45)(+ (posn-y start-posn) 20)) 'lightgreen) )) ;; Shark (define (shark start-posn) (and ;;Body (draw-solid-disk start-posn 120 'gray) ;;mouth (draw-solid-disk (make-posn (posn-x start-posn)(+ 20 (posn-y start-posn))) 80 'white) (draw-solid-disk (make-posn (posn-x start-posn)(- (posn-y start-posn) 50)) 100 'gray) ;;teeth (draw-solid-line (make-posn (- (posn-x start-posn) 20)(+ 48 (posn-y start-posn)))(make-posn (- (posn-x start-posn) 3)(+ 100 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (- (posn-x start-posn) 20)(+ 48 (posn-y start-posn)))(make-posn (- (posn-x start-posn) 45)(+ 86 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (- (posn-x start-posn) 50)(+ 37 (posn-y start-posn)))(make-posn (- (posn-x start-posn) 45)(+ 86 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (- (posn-x start-posn) 50)(+ 37 (posn-y start-posn)))(make-posn (- (posn-x start-posn) 70)(+ 60 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (- (posn-x start-posn) 70)(+ 22 (posn-y start-posn)))(make-posn (- (posn-x start-posn) 70)(+ 60 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (- (posn-x start-posn) 70)(+ 22 (posn-y start-posn)))(make-posn (- (posn-x start-posn) 78)(+ 40 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (+ (posn-x start-posn) 20)(+ 48 (posn-y start-posn)))(make-posn (- (posn-x start-posn) 3)(+ 100 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (+ (posn-x start-posn) 20)(+ 48 (posn-y start-posn)))(make-posn (+ (posn-x start-posn) 40)(+ 89 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (+ (posn-x start-posn) 50)(+ 37 (posn-y start-posn)))(make-posn (+ (posn-x start-posn) 40)(+ 89 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (+ (posn-x start-posn) 50)(+ 37 (posn-y start-posn)))(make-posn (+ (posn-x start-posn) 65)(+ 65 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (+ (posn-x start-posn) 70)(+ 20 (posn-y start-posn)))(make-posn (+ (posn-x start-posn) 65)(+ 65 (posn-y start-posn))) 'black) (draw-solid-line (make-posn (+ (posn-x start-posn) 70)(+ 20 (posn-y start-posn)))(make-posn (+ (posn-x start-posn) 80)(+ 28 (posn-y start-posn))) 'black) ;;nose (draw-solid-line start-posn (make-posn (+ (posn-x start-posn) 70)(- (posn-y start-posn) 75)) 'darkgray) (draw-solid-line start-posn (make-posn (- (posn-x start-posn) 70)(- (posn-y start-posn) 75)) 'darkgray) (draw-solid-disk (make-posn (- (posn-x start-posn) 16)(+ (posn-y start-posn) 15)) 2 'black) (draw-solid-disk (make-posn (+ (posn-x start-posn) 16)(+ (posn-y start-posn) 15)) 2 'black) ;;eyes (draw-solid-disk (make-posn (- (posn-x start-posn) 43)(- (posn-y start-posn) 30)) 8 'white) (draw-solid-disk (make-posn (- (posn-x start-posn) 43)(- (posn-y start-posn) 30)) 4 'black) (draw-solid-disk (make-posn (+ (posn-x start-posn) 43)(- (posn-y start-posn) 30)) 8 'white) (draw-solid-disk (make-posn (+ (posn-x start-posn) 43)(- (posn-y start-posn) 30)) 4 'black) ;;fins (draw-solid-rect (make-posn (- (posn-x start-posn) 120)(+ 80 (posn-y start-posn))) 45 15 'gray) (draw-solid-rect (make-posn (- (posn-x start-posn) 130)(+ 90 (posn-y start-posn))) 20 5 'darkgray) (draw-solid-rect (make-posn (+ (posn-x start-posn) 75)(+ (posn-y start-posn)70)) 45 15 'gray) (draw-solid-rect (make-posn (+ (posn-x start-posn) 115)(+ (posn-y start-posn)80)) 20 5 'darkgray) (draw-solid-rect (make-posn (+ (posn-x start-posn)2)(- (posn-y start-posn)190)) 7 30 'darkgray) (draw-solid-rect (make-posn (- (posn-x start-posn)5)(- (posn-y start-posn)170)) 16 20 'gray) (draw-solid-rect (make-posn (posn-x start-posn)(- (posn-y start-posn)185)) 7 18 'gray) ) ) ;; Jellyfish (define (JellyFish ThisIsNotUsed) (and (draw-solid-rect (make-posn 1 1) 498 498 'lightblue);Water ;(draw-solid-disk (make-posn 250 250) 20 'magenta) ;(draw-solid-line (make-posn 250 260) (make-posn 250 310) 'magenta) ;(draw-solid-line (make-posn 260 255) (make-posn 260 300) 'magenta) ;(draw-solid-line (make-posn 240 255) (make-posn 240 300) 'magenta);Jellyfish1 (draw-solid-disk (make-posn 100 100) 20 'magenta) (draw-solid-line (make-posn 100 110) (make-posn 100 155) 'magenta) (draw-solid-line (make-posn 110 105) (make-posn 110 145) 'magenta) (draw-solid-line (make-posn 90 105) (make-posn 90 145) 'magenta);Jellyfish2 (draw-solid-disk (make-posn 400 150) 20 'magenta) (draw-solid-line (make-posn 400 150) (make-posn 400 210) 'magenta) (draw-solid-line (make-posn 410 145) (make-posn 410 195) 'magenta) (draw-solid-line (make-posn 390 145) (make-posn 390 195) 'magenta);Jellyfish3 (draw-solid-disk (make-posn 200 300) 20 'magenta) (draw-solid-line (make-posn 200 300) (make-posn 200 360) 'magenta) (draw-solid-line (make-posn 210 305) (make-posn 210 350) 'magenta) (draw-solid-line (make-posn 190 305) (make-posn 190 350) 'magenta);Jellyfish4 (draw-solid-disk (make-posn 310 190) 20 'magenta) (draw-solid-line (make-posn 310 190) (make-posn 310 250) 'magenta) (draw-solid-line (make-posn 320 195) (make-posn 320 240) 'magenta) (draw-solid-line (make-posn 300 195) (make-posn 300 240) 'magenta);Jellyfish5 (draw-solid-disk (make-posn 150 190) 20 'magenta) (draw-solid-line (make-posn 150 190) (make-posn 150 250) 'magenta) (draw-solid-line (make-posn 160 195) (make-posn 160 240) 'magenta) (draw-solid-line (make-posn 140 195) (make-posn 140 240) 'magenta))) ;; School of Fish (define (Schooloffish a-color) (and (draw-solid-rect (make-posn 1 1) 498 498 'lightblue) (draw-solid-disk (make-posn 100 200) 10 a-color) (draw-solid-disk (make-posn 100 230) 10 a-color) (draw-solid-disk (make-posn 130 200) 10 a-color) (draw-solid-disk (make-posn 130 230) 10 a-color) (draw-solid-disk (make-posn 160 170) 10 a-color) (draw-solid-disk (make-posn 160 200) 10 a-color) (draw-solid-disk (make-posn 160 230) 10 a-color) (draw-solid-disk (make-posn 160 260) 10 a-color) (draw-solid-disk (make-posn 190 185) 10 a-color) (draw-solid-disk (make-posn 190 215) 10 a-color) (draw-solid-disk (make-posn 190 245) 10 a-color) (draw-solid-disk (make-posn 220 200) 10 a-color) (draw-solid-disk (make-posn 220 230) 10 a-color) (draw-solid-disk (make-posn 250 215) 10 a-color))) ;; Marlin (define (Marlin start-posn) (and ;;body (draw-solid-disk (make-posn (posn-x start-posn) (posn-y start-posn)) 50 'orange) ;;dorsal fin (draw-solid-rect (make-posn (- (posn-x start-posn) 25) (- (posn-y start-posn) 52)) 50 15 'orange) ;;tail fin ;base (draw-solid-rect (make-posn (- (posn-x start-posn) 55) (- (posn-y start-posn) 10)) 10 25 'orange) ;top (draw-solid-rect (make-posn (- (posn-x start-posn) 65) (- (posn-y start-posn) 15)) 10 13 'orange) ;bottom (draw-solid-rect (make-posn (- (posn-x start-posn) 65) (+ (posn-y start-posn) 5)) 10 13 'orange) ;;fish lips ;top (draw-solid-disk (make-posn (+ (posn-x start-posn) 50) (+ (posn-y start-posn) 5)) 5 'orange) ;bottom (draw-solid-disk (make-posn (+ (posn-x start-posn) 50) (- (posn-y start-posn) 5)) 5 'orange) ;;stripes ;middle (draw-solid-rect (make-posn (- (posn-x start-posn) 5) (- (posn-y start-posn) 43)) 10 86 'white) ;left (draw-solid-rect (make-posn (- (posn-x start-posn) 35) (- (posn-y start-posn) 30)) 10 66 'white) ;right (draw-solid-rect (make-posn (+ (posn-x start-posn) 25) (- (posn-y start-posn) 30)) 10 66 'white) ;;eyeball (draw-solid-disk (make-posn (+ (posn-x start-posn) 30) (- (posn-y start-posn) 15)) 6 'black) (draw-solid-disk (make-posn (+ (posn-x start-posn) 30) (- (posn-y start-posn) 15)) 5 'white) (draw-solid-disk (make-posn (+ (posn-x start-posn) 30) (- (posn-y start-posn) 15)) 2 'black))) ;; Dory (define (Dory start-posn) (and ;;dorsal fin (draw-solid-rect (make-posn (- (posn-x start-posn) 35) (- (posn-y start-posn) 72)) 75 20 'black) ;;body (draw-solid-disk (make-posn (posn-x start-posn) (posn-y start-posn)) 65 'blue) ;;designs on body (draw-solid-disk (make-posn (posn-x start-posn) (posn-y start-posn)) 55 'yellow) (draw-solid-disk (make-posn (- (posn-x start-posn) 15) (posn-y start-posn)) 50 'blue) ;;eyeball (draw-solid-disk (make-posn (+ (posn-x start-posn) 45) (- (posn-y start-posn) 15)) 8 'black) (draw-solid-disk (make-posn (+ (posn-x start-posn) 45) (- (posn-y start-posn) 15)) 7 'white) (draw-solid-disk (make-posn (+ (posn-x start-posn) 45) (- (posn-y start-posn) 15)) 3 'black) ;;tail fin ;base (draw-solid-rect (make-posn (- (posn-x start-posn) 80) (- (posn-y start-posn) 10)) 20 25 'yellow) ;top (draw-solid-rect (make-posn (- (posn-x start-posn) 90) (- (posn-y start-posn) 17)) 17 18 'yellow) ;bottom (draw-solid-rect (make-posn (- (posn-x start-posn) 90) (+ (posn-y start-posn) 7)) 17 18 'yellow) ;;fish lips ;top (draw-solid-disk (make-posn (+ (posn-x start-posn) 65) (+ (posn-y start-posn) 5)) 5 'blue) ;bottom (draw-solid-disk (make-posn (+ (posn-x start-posn) 65) (- (posn-y start-posn) 5)) 5 'blue))) ;;*******NEED NEMO******** ;; Backgrounds ;; 1st background: Reef (define (Background1 ThisIsNotUsed) (and (draw-solid-rect (make-posn 1 1) 499 499 'lightblue);Water (draw-solid-rect (make-posn 1 450) 499 50 'gold) (draw-solid-rect (make-posn 1 440) 150 10 'gold) (draw-solid-rect (make-posn 350 430) 249 20 'gold) (draw-solid-rect (make-posn 280 435) 70 15 'gold);Sand (draw-solid-rect (make-posn 355 390) 144 40 'brown) (draw-solid-rect (make-posn 365 310) 134 80 'brown) (draw-solid-rect (make-posn 440 200) 59 110 'brown);Rock1 (draw-solid-rect (make-posn 151 430) 130 20 'brown);Rock2 (draw-solid-disk (make-posn 370 380) 8 'pink) (draw-solid-disk (make-posn 375 370) 8 'pink) (draw-solid-disk (make-posn 380 385) 8 'pink) (draw-solid-disk (make-posn 380 380) 8 'pink) (draw-solid-disk (make-posn 371 381) 5 'purple) (draw-solid-disk (make-posn 376 371) 4 'purple) (draw-solid-disk (make-posn 381 386) 3 'purple);Coral1 (draw-solid-disk (make-posn 440 305) 8 'orange) (draw-solid-disk (make-posn 445 300) 8 'orange) (draw-solid-disk (make-posn 450 305) 8 'orange) (draw-solid-disk (make-posn 455 310) 8 'orange) (draw-solid-disk (make-posn 440 315) 8 'orange) (draw-solid-disk (make-posn 441 306) 5 'lightblue) (draw-solid-disk (make-posn 456 311) 5 'lightblue) (draw-solid-disk (make-posn 441 316) 5 'lightblue) (draw-solid-disk (make-posn 445 301) 4 'lightblue);Coral2 (draw-solid-line (make-posn 420 429) (make-posn 420 380) 'red) (draw-solid-line (make-posn 420 429) (make-posn 450 400) 'red) (draw-solid-line (make-posn 420 429) (make-posn 390 400) 'red) (draw-solid-line (make-posn 420 429) (make-posn 400 380) 'red) (draw-solid-line (make-posn 420 429) (make-posn 440 380) 'red);Coral3 (draw-solid-line (make-posn 370 309) (make-posn 370 270) 'green) (draw-solid-line (make-posn 370 309) (make-posn 400 280) 'green) (draw-solid-line (make-posn 370 309) (make-posn 340 280) 'green) (draw-solid-line (make-posn 370 309) (make-posn 390 260) 'green) (draw-solid-line (make-posn 370 309) (make-posn 350 260) 'green);Coral4 (draw-solid-disk (make-posn 170 425) 8 'purple) (draw-solid-disk (make-posn 175 430) 8 'purple) (draw-solid-disk (make-posn 170 435) 8 'purple) (draw-solid-disk (make-posn 180 435) 8 'purple) (draw-solid-disk (make-posn 171 426) 5 'orange) (draw-solid-disk (make-posn 171 436) 3 'orange) (draw-solid-disk (make-posn 181 436) 4 'orange);Coral5 (draw-solid-rect (make-posn 10 300) 10 140 'green) (draw-solid-line (make-posn 20 439) (make-posn 80 380) 'green) (draw-solid-line (make-posn 20 429) (make-posn 70 370) 'green) (draw-solid-line (make-posn 20 409) (make-posn 60 350) 'green) (draw-solid-line (make-posn 20 399) (make-posn 50 340) 'green) (draw-solid-line (make-posn 20 379) (make-posn 40 330) 'green) (draw-solid-line (make-posn 20 369) (make-posn 30 325) 'green)));Coral6 ;; 2nd background: Trench (define (Background2 ThisIsNotUsed) (and (draw-solid-rect (make-posn 1 1) 498 498 'darkblue) (draw-solid-rect (make-posn 1 400) 498 100 'gold) (draw-solid-rect (make-posn 1 300) 200 100 'brown) (draw-solid-rect (make-posn 1 200) 180 100 'brown) (draw-solid-rect (make-posn 1 100) 160 100 'brown) (draw-solid-rect (make-posn 1 1) 140 100 'brown) (draw-solid-rect (make-posn 298 300) 200 100 'brown) (draw-solid-rect (make-posn 318 200) 180 100 'brown) (draw-solid-rect (make-posn 338 100) 160 100 'brown) (draw-solid-rect (make-posn 358 1) 140 100 'brown))) ;;3rd background: vortex (define (Vortex ThisIsNotUsed) (and (draw-solid-rect (make-posn 0 0) 500 500 'blue) (draw-solid-disk (make-posn 250 250) 310 'darkblue) (draw-solid-disk (make-posn 250 250) 295 'blue) (draw-solid-disk (make-posn 250 250) 280 'darkblue) (draw-solid-disk (make-posn 250 250) 265 'blue) (draw-solid-disk (make-posn 250 250) 250 'darkblue) (draw-solid-disk (make-posn 250 250) 235 'blue) (draw-solid-disk (make-posn 250 250) 220 'darkblue) (draw-solid-disk (make-posn 250 250) 205 'blue) (draw-solid-disk (make-posn 250 250) 190 'darkblue) (draw-solid-disk (make-posn 250 250) 175 'blue) (draw-solid-disk (make-posn 250 250) 160 'darkblue) (draw-solid-disk (make-posn 250 250) 145 'blue) (draw-solid-disk (make-posn 250 250) 130 'darkblue) (draw-solid-disk (make-posn 250 250) 115 'blue) (draw-solid-disk (make-posn 250 250) 100 'darkblue) (draw-solid-disk (make-posn 250 250) 85 'blue) (draw-solid-disk (make-posn 250 250) 70 'darkblue) (draw-solid-disk (make-posn 250 250) 55 'blue) (draw-solid-disk (make-posn 250 250) 40 'darkblue) (draw-solid-disk (make-posn 250 250) 25 'blue) (draw-solid-disk (make-posn 250 250) 10 'darkblue) (draw-solid-disk (make-posn 250 250) 5 'blue))) ;;4th Background: East Australian Current (define (EAC ThisIsNotUsed) (and (draw-solid-rect (make-posn 0 0) 500 500 'blue) (draw-solid-rect (make-posn 0 175) 500 145 'lightblue) (draw-solid-line (make-posn 30 200) (make-posn 110 200) 'blue) (draw-solid-line (make-posn 70 300) (make-posn 150 300) 'blue) (draw-solid-line (make-posn 350 200) (make-posn 430 200) 'blue) (draw-solid-line (make-posn 390 300) (make-posn 460 300) 'blue) (draw-solid-line (make-posn 20 250) (make-posn 100 250) 'blue) )) ;;Treasure (define (treasure ThisIsNotUsed) (and (draw-solid-rect (make-posn 0 0) 500 500 'lightskyblue) (draw-solid-rect (make-posn 0 450) 500 50 'gold) (draw-solid-rect (make-posn 100 300) 300 175 'brown) (draw-solid-rect (make-posn 100 350) 300 10 'black) (draw-solid-rect (make-posn 244 345) 12 12 'gold) (draw-solid-rect (make-posn 246 347) 8 8 'black) (draw-solid-disk (make-posn 249 363) 10 'gold))) ;; Items ;; Map (define (draw-Map ThisIsNotUsed) (and (draw-solid-string (make-posn 175 100) "The fish give you a map!") (draw-solid-rect (make-posn 25 150) 450 300 'tan) (draw-solid-string (make-posn 75 200) "YOU ARE") (draw-solid-string (make-posn 90 213) "HERE") (draw-solid-disk (make-posn 110 230) 5 'blue) (draw-solid-string (make-posn 350 350) "Nemo?") (draw-solid-disk (make-posn 367 367) 7 'orange) (draw-solid-disk (make-posn 367 367) 5 'white) (draw-solid-disk (make-posn 367 367) 3 'orange) (draw-solid-disk (make-posn 367 367) 1 'white))) ;;Jellie-Power (define (Jellie-Power ThisIsNotUsed) (and (draw-solid-rect (make-posn 220 220) 70 110 'black) (draw-solid-rect (make-posn 222 222) 66 106 'lightblue) (draw-solid-rect (make-posn 215 200) 80 25 'gold) (draw-solid-disk (make-posn 250 250) 20 'magenta) (draw-solid-line (make-posn 250 260) (make-posn 250 310) 'magenta) (draw-solid-line (make-posn 260 255) (make-posn 260 300) 'magenta) (draw-solid-line (make-posn 240 255) (make-posn 240 300) 'magenta))) ;;Dude-Power (define (Dude-Power ThisIsNotUsed) (and (draw-solid-disk (make-posn 250 250) 151 'black) (draw-solid-disk (make-posn 250 250) 150 'yellow) (draw-solid-disk (make-posn 250 275) 80 'black) (draw-solid-disk (make-posn 250 265) 82 'yellow) (draw-solid-disk (make-posn 250 215) 9 'silver) (draw-solid-disk (make-posn 250 220) 9 'yellow) (draw-solid-disk (make-posn 200 215) 41 'black) (draw-solid-disk (make-posn 200 215) 40 'silver) (draw-solid-disk (make-posn 200 215) 38 'black) (draw-solid-disk (make-posn 200 215) 37 'red) (draw-solid-disk (make-posn 300 215) 41 'black) (draw-solid-disk (make-posn 300 215) 40 'silver) (draw-solid-disk (make-posn 300 215) 38 'black) (draw-solid-disk (make-posn 300 215) 37 'red) )) ;;Mask (define (Mask ThisIsNotUsed) (and (draw-solid-disk (make-posn 150 250) 100 'green) (draw-solid-disk (make-posn 350 250) 100 'green) (draw-solid-rect (make-posn 50 150) 400 100 'green) (draw-solid-disk (make-posn 150 250) 80 'silver) (draw-solid-disk (make-posn 350 250) 80 'silver) (draw-solid-rect (make-posn 70 170) 360 80 'silver) (draw-solid-string (make-posn 75 165) "P. Sherman, 42, Wallaby Way, Sydney" ))) ;;Other Functions used in our game: ;draw-character: draws either Dory or Marlin, depending on players choice (define (draw-character ThisIsNotUsed) (cond [(string=? (first character-list) "Marlin")(Marlin (make-posn 250 250))] [else (Dory (make-posn 250 250))])) ;ClearCanvas: draws a solid white rectangle the size of the canvas, to appear as though the canvas has been cleared (define (ClearCanvas ThisIsNotUsed) (draw-solid-rect (make-posn 1 1) 500 500 'white)) ;; The structure represents a circle ;; center is the position (posn structure) of the center ;; radius is its radius (a non-negative number), and ;; color is a symbol representing a color (define-struct circle (center radius color)) ;; draw-a-circle: circle -> true ;; the function draws a circle structure as a disk ;; and returns true (define (draw-a-circle a-circle) (draw-solid-disk (circle-center a-circle) (circle-radius a-circle) (circle-color a-circle))) ;; clear-a-circle: circle -> true ;; the function clears a disk corresponding to a circle ;; and returns true (define (clear-a-circle a-circle) (clear-solid-disk (circle-center a-circle) (circle-radius a-circle))) (define colors (list 'magenta 'pink 'purple)) (define (nth a-list n) (cond [(= n 0) (first a-list)] [else (nth (rest a-list) (- n 1))])) ;; CONTRACT: random-circle: number -> circle ;; PURPOSE: to create a random circle ;; DEFINITION: (define (random-circle a-num) (make-circle (make-posn (random 500)(random 500)) (+ 1 (random 49)) (local ((define random-color (nth colors (random 3)))) random-color))) ;add-item: this uses set to add an item to the item-list for later use (define (add-item item) (set! item-list (cons item item-list)) ) ;remove-item: removes chosen item from item-list (define (remove-item item) (set! item-list (filter (lambda (entry) (not (string=? entry item))) item-list)) ) ;; ======================================================= Our Game ================================================================== ;;User Input1: choosing a character ;the list of choices (define character-choices (list "Marlin" "Dory")) ;calling "get-choice" to choose character (define character-list (cons (get-choice "Choose your character" character-choices) empty)) (sleep-for-a-while 2) ;;Frame1: showing the player their chosen character (define message (string-append " You chose " (first character-list)"!!!")) (start 500 500) ;drawing the reef background *value of parameter is irrelevant (Background1 5) (draw-solid-string (make-posn 20 30) message) ;drawing chosen character *value of parameter is irrelevant (draw-character 48) (sleep-for-a-while 5) ;;Frame2 ;clearing the canvas *value of parameter is irrelevant (ClearCanvas 4) (draw-solid-string (make-posn 185 250) "Let's find Nemo!") (sleep-for-a-while 3) (ClearCanvas 2901238498) ;;Frame3: school of fish ;drawing the school of fish (Schooloffish 'blue) (draw-solid-string (make-posn 150 300) "Look! A school of fish!") (sleep-for-a-while 3) ;;User Input2:choosing whether to get directions from the school of fish ;defining the choices (define sof-choices (list "Yes" "No")) ;calling "get-choice" (define sof-list (cons (get-choice "Would you like to follow the school of fish?" sof-choices) empty)) (sleep-for-a-while 2) ;;Frame3: this frame varies depending on the answer to User Input2 ;draws a new frame corresponding to User Input2 ;NOTE: this function is included here rather than in the section for 'Other Functions' because it must be included in the code AFTER 'sof-list' has been defined. It makes more sense to leave the definition of 'sof-list' where it is. (define draw-sof-response (cond ;if the player chooses to follow the school of fish ('Yes') the fish will flash [(string=? (first sof-list) "Yes") (and (Schooloffish 'blue) (sleep-for-a-while .5) (Schooloffish 'silver) (sleep-for-a-while .5) (Schooloffish 'blue) (sleep-for-a-while .5) (Schooloffish 'silver) (sleep-for-a-while .5) (Schooloffish 'blue) (sleep-for-a-while .5) (Schooloffish 'silver) (sleep-for-a-while .5) (Schooloffish 'blue))] ;if the player does not choose to follow the fish, they lose and the 'Game Over Screen' appears [else (and (ClearCanvas 3) (draw-solid-string (make-posn 150 250) "You are lost!") (sleep-for-a-while .5) (draw-solid-string (make-posn 80 270) "There's no hope of finding Nemo :(") (sleep-for-a-while .5) (draw-solid-string (make-posn 150 300) "GAME OVER") (sleep-for-a-while 4) (exit))])) ;actually drawing the new frame (see function for more details) draw-sof-response ;if the player chose 'No' in User Input2, the canvas will be closed, and nothing else will be drawn. ;if the player chose 'Yes' in User Input2, the game will continue ;;Frame4: showing the player that they have acquired the Map (sleep-for-a-while 1) ;clearing the canvas *value of parameter is irrelevant (ClearCanvas 2) ;drawing the map *value of parameter is irrelevant (draw-Map 3) ;;Accumulation Round1 ;defining our list of items (define item-list (list "Map")) (sleep-for-a-while 4) ;;Frame5 ;drawing the trench *value of parameter is irrelevant (Background2 32) (draw-solid-string (make-posn 30 480) "A deep scary trench! You decide to swim over it.") (sleep-for-a-while 4) ;;Frame6 ;drawing the school of jellyfish *value of parameter is irrelevant (JellyFish 4) ;drawing chosen character among the school of jellyfish *value of parameter is irrelevant (draw-character 5) (draw-solid-string (make-posn 145 450) "A school of jellies! Don't touch the tentacles!") (sleep-for-a-while 3) ;;Frame7 ;clearing the canvas *value of parameter is irrelevant (ClearCanvas 3) ;defining sets of 50/30 random circles representing jellyfish (define random-circles50 (build-list 50 random-circle )) (define random-circles30 (build-list 30 random-circle )) ;drawing multiplle sets of random jellyfish, this is supposed to look like you're moving through the school of jellyfish. (map draw-a-circle random-circles50) (sleep-for-a-while .3) (map clear-a-circle random-circles50) (sleep-for-a-while .3) (map draw-a-circle random-circles30) (sleep-for-a-while .3) (map clear-a-circle random-circles30) (sleep-for-a-while .3) (map draw-a-circle random-circles50) (sleep-for-a-while .3) (map clear-a-circle random-circles50) (sleep-for-a-while .3) (map draw-a-circle random-circles30) (sleep-for-a-while .3) (map clear-a-circle random-circles30) (sleep-for-a-while .3) (map draw-a-circle random-circles50) (sleep-for-a-while .3) (map clear-a-circle random-circles50) (sleep-for-a-while .3) ;;Frame8: showing the player that they have earned 'Jellie-Power' ;drawing Jellie-Power *value of parameter is irrelevant (draw-solid-string (make-posn 150 50) "You made it through the Jellies!") (sleep-for-a-while 1) (Jellie-Power 7) (draw-solid-string (make-posn 150 450) "You have earned Jellie-Power!") ;;Accumulation Round2 (add-item "Jellie-Power") (sleep-for-a-while 4) ;;Frame9: ;drawing the vortex *value of parameter is irrelevant (Vortex 88) (clear-solid-string (make-posn 140 255) "You have been sucked into a vortex!") (sleep-for-a-while 4) ;;Frame10: ;drawing current *value of parameter is irrelevant (EAC 44) (clear-solid-string (make-posn 85 400) "You are now traveling on the East Australian Current.") ;drawing chosen character in the current *value of parameter is irrelevant (draw-character 5) (sleep-for-a-while 4) ;;Frame11 ;background (ocean) (draw-solid-rect (make-posn 0 0) 500 500 'lightblue) ;drawing chosen character *value of parameter is irrelevant (draw-character 8) ;drawing the turtle (turtle (make-posn 375 400)) (draw-solid-string (make-posn 130 100) "In your journey along the current") (draw-solid-string (make-posn 130 113) "you meet a strange old sea turtle.") (sleep-for-a-while 2) (draw-solid-string (make-posn 100 480) "Woah, Mini-Man! Takin' on the Jellies!") (sleep-for-a-while 4) ;;Frame12 ;clearing the canvas *value of parameter is irrelevant (ClearCanvas 3) (draw-solid-string (make-posn 100 80) "Crush admires your strength takin' on the jellies.") (sleep-for-a-while 2) ;showing the player they now have Dude-Power (Dude-Power 3) (draw-solid-string (make-posn 75 450) "He helps you out of the current and gives you Dude-Power!") ;;Accumulation Round3 (add-item "Dude-Power") (sleep-for-a-while 4) ;;Frame13 ;ocean background (draw-solid-rect (make-posn 0 0) 500 500 'lightskyblue) ;drawing the shark (shark (make-posn 250 300)) (draw-solid-string (make-posn 100 50) "You've been tracked down by a hungry shark!") (sleep-for-a-while 2) ;;User Input3:choosing your method of defense (define shark-choices item-list) ;calling "get-choice" (define shark-list (cons (get-choice "How will you defend yourself?" shark-choices) empty)) ;drawing the 'life-bar' (draw-solid-string (make-posn 30 455) "LIFE:") (draw-solid-rect (make-posn 20 460) 460 20 'green) (sleep-for-a-while 5) ;removing the chosen item from item-list ;Using Item1 (remove-item (first shark-list)) ;;Frame13.5 ;shark weakened ;ocean background (draw-solid-rect (make-posn 0 30) 500 25 'lightskyblue) (draw-solid-string (make-posn 100 50) "Bruce is weakened!") ;drawing modified life bar (draw-solid-string (make-posn 30 455) "LIFE:") (draw-solid-rect (make-posn 20 460) 100 20 'red) (draw-solid-rect (make-posn 120 460) 360 20 'gray) ;choosing how to defeat the shark ;using item 2 (define shark-choices2 item-list) (define shark-list2 (cons (get-choice "How will you defeat Bruce?" shark-choices2) empty)) ;removing the second choice from item-list (remove-item (first shark-list2)) (sleep-for-a-while 5) ;;Frame 14: this frame varies depending on the choices for using items 1 and 2 (define shark-response (cond ;if the player has chosen Jellie-Power and Dude-Power, Map will be left in item-list [(string=? (first item-list) "Map") (and ;ocean background (draw-solid-rect (make-posn 0 0) 500 500 'lightskyblue) ;empty life-bar (draw-solid-string (make-posn 30 455) "LIFE:") (draw-solid-rect (make-posn 20 460) 460 20 'gray) (draw-solid-string (make-posn 175 50) "You defeated Bruce!"))] ;if the player has chosen Map and another item, the remaining item will not be Map, it will go to the else clause [else (and ;ocean background (draw-solid-rect (make-posn 0 0 ) 500 500 'lightskyblue) ;drawing the shark (shark (make-posn 250 300)) (draw-solid-string (make-posn 160 50) "You did not defeat Bruce.") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 250) "OM NOM NOM!") (sleep-for-a-while 2) (draw-solid-string (make-posn 185 450) "GAME OVER") (sleep-for-a-while 2) (exit))])) ;;if the player has chosen to use Map, the game will end ;;if the player has not chosen to use Map, the game will continue ;;Frame 15: showing the mask (sleep-for-a-while 4) ;clearing the canvas *value of parameter is irrelevant (ClearCanvas 3) (draw-solid-string (make-posn 175 50) "You have earned the Mask!") ;drawing the mask *value of parameter is irrelevant (Mask 78) ;adding the mask to item-list ;Accumulation Round4 (add-item "Mask") (sleep-for-a-while 4) ;;Frame 16 (ClearCanvas 3) (draw-solid-string (make-posn 175 250) "You still have to find Nemo!") (sleep-for-a-while 2) ;;User Input 4:choosing how to find Nemo ;using 3rd item ;defining choices for how to find Nemo (define Nemo-choices item-list) ;using get-choice to choose how to find Nemo (define Nemo-list (cons (get-choice "What will you use to find Nemo?" Nemo-choices) empty)) (sleep-for-a-while 5) ;;Frame 17: this frame will vary depending on what in chosen for User Input 4 (define nemo-response (cond ;if Mask is chosen, they find Nemo and win [(string=? (first Nemo-list) "Mask") (and ;drawing reef background *value of parameter is irrelevant (Background1 3) (nemo (make-posn 250 250)) (draw-solid-string (make-posn 175 50) "You found Nemo!") (draw-solid-string (make-posn 175 63) "You win!") (sleep-for-a-while 8) (exit))] ;if Map is chosen, they are led to a treasure instead, and lose because they didn't find Nemo [else (and ;drawing treasure background *value of parameter is irrelevant (treasure 30) (draw-solid-string (make-posn 175 50) "The map leads you to a treasure.") (sleep-for-a-while 2) (draw-solid-string (make-posn 175 63) "But you didn't find Nemo,") (sleep-for-a-while 2) (draw-solid-string (make-posn 185 76) "so you lose.") (sleep-for-a-while 4) (stop))]))