;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |group project gamma|) (read-case-sensitive #t) (teachpacks ((lib "master.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "master.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))))) ;; 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 2) (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 (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 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 2) (process-result (+ n 1)))] [else true] ;; the user starts typing ))) (cond [(process-result 0) (cond [(sleep-for-a-while delay) (text-contents the-answer)]) ]) )) ; Here is the canvas for the game. (start 1200 850) ; The following displays the title card. (draw-solid-string (make-posn 500 400) "SOME GUY FINDS SOME STUFF") (draw-solid-string (make-posn 400 500) "Created by Nick Cornhill, Niko Simmons, and Michael Rislow") (sleep-for-a-while 3) (clear-solid-string (make-posn 500 400) "SOME GUY FINDS SOME STUFF") (clear-solid-string (make-posn 400 500) "Created by Nick Cornhill, Niko Simmons, and Michael Rislow") ; Drawing functions for the character ;Contract: draw-head, posn -> boolean ;Purpose: To draw a head looking at the screen, helper function used in later draws. (define (draw-head posn) (local ((define xposn-20 (- (posn-x posn) 20)) (define yposn-20 (- (posn-y posn) 20))) (and ;Draw Mouth (draw-solid-rect (make-posn xposn-20 (+ (posn-y posn) 25)) 40 5) ;Draw head circle (draw-circle posn 50 'black) ;Draw eyes (draw-solid-disk (make-posn xposn-20 yposn-20) 4 'black) (draw-solid-disk (make-posn (+ (posn-x posn) 20) yposn-20) 4 'black) ))) ;Contract: draw-arms-normal, posn -> boolean ;Purpose: To draw a stick figures "at rest" arms, helper funtion used later in draws. (define (draw-arms-normal posn) (local ((define yposn+75 (+ (posn-y posn) 75)) (define yposn+200 (+ (posn-y posn) 200))) (and ;Left arm (draw-solid-line (make-posn (posn-x posn) yposn+75) (make-posn (- (posn-x posn) 50) yposn+200) 'black) ;Right arm (draw-solid-line (make-posn (posn-x posn) yposn+75) (make-posn (+ (posn-x posn) 50) yposn+200) 'black)))) (define (draw-standing posn) (local ((define yposn+175 (+ (posn-y posn) 175)) (define yposn+350 (+ (posn-y posn) 350)) (define xposn-50 (- (posn-x posn) 50))) (and ;clears area behind guy in case we are making him turn, so there would be something behind him. (clear-solid-rect (make-posn xposn-50 (- (posn-y posn) 50)) 105 400) (draw-head posn) (draw-arms-normal posn) ;draw spine (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 50)) (make-posn (posn-x posn) yposn+175) 'black) ;draw left leg (draw-solid-line (make-posn (posn-x posn) yposn+175) (make-posn xposn-50 yposn+350) 'black) ;draw right leg (draw-solid-line (make-posn (posn-x posn) yposn+175) (make-posn (+ (posn-x posn) 50) yposn+350) 'black) (sleep-for-a-while .5) ))) ;Contract: clear-standing, posn -> boolean ;Purpose: To clear a drawn guy. (define (clear-standing posn) (clear-solid-rect (make-posn (- (posn-x posn) 50) (- (posn-y posn) 50)) 101 400) ) ;Contract: head-facing-left, posn -> boolean ;Purpose: To draw the head of a guy facing left, helper function used later. (define (head-facing-left posn) (and ;mouth (draw-solid-rect (make-posn (- (posn-x posn) 41) (+ (posn-y posn) 25)) 30 5) ;head circle (draw-circle (make-posn (posn-x posn) (posn-y posn)) 50 'black) ;eye (draw-solid-disk (make-posn (- (posn-x posn) 25) (- (posn-y posn) 25)) 4 'black) )) ;Contract: turn-to-left posn -> boolean ;Purpose: To draw a man facing the left (define (turn-to-left posn) (local ((define yposn+175 (+ (posn-y posn) 175)) (define yposn+350 (+ (posn-y posn) 350))) (and (clear-solid-rect (make-posn (- (posn-x posn) 50) (- (posn-y posn) 50)) 105 400) (head-facing-left posn) (draw-arms-normal posn) ;spine (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 50)) (make-posn (posn-x posn) yposn+175) 'black) ;left leg (draw-solid-line (make-posn (posn-x posn) yposn+175) (make-posn (- (posn-x posn) 40) yposn+350) 'black) ;right leg (draw-solid-line (make-posn (posn-x posn) yposn+175) (make-posn (+ (posn-x posn) 40) yposn+350) 'black) ))) ;Contract: move-left, posn number -> boolean ;Purpose: To make our guy walk left (define (move-left posn distance) (local ((define xposn-50 (- (posn-x posn) 50)) (define yposn-50 (- (posn-y posn) 50)) (define xposn-17 (- (posn-x posn) 17)) (define yposn+50 (+ (posn-y posn) 50)) (define yposn+175 (+ (posn-y posn) 175)) (define yposn+250 (+ (posn-y posn) 250)) (define yposn+300 (+ (posn-y posn) 300)) (define yposn+200 (+ (posn-y posn) 200)) (define yposn+75 (+ (posn-y posn) 75)) (define xposn-34 (- (posn-x posn) 34))) (cond [(= 0 distance) true] [else (and (sleep-for-a-while .5) (clear-solid-rect (make-posn xposn-50 yposn-50) 130 401) ;;First Draw (head-facing-left (make-posn xposn-17 (posn-y posn))) ;spine (draw-solid-line (make-posn xposn-17 yposn+50) (make-posn xposn-17 yposn+175) 'black) ;right leg (draw-solid-line (make-posn xposn-17 yposn+175) (make-posn xposn-17 yposn+250) 'black) (draw-solid-line (make-posn xposn-17 yposn+250) (make-posn (+ (posn-x posn) 33) yposn+300) 'black) ;left leg (draw-solid-line (make-posn xposn-17 yposn+175) (make-posn (- (posn-x posn) 22) (+ (posn-y posn) 350)) 'black) ;left arm (draw-solid-line (make-posn xposn-17 yposn+75) (make-posn (- (posn-x posn) 54) yposn+200) 'black) ;right arm (draw-solid-line (make-posn xposn-17 yposn+75) (make-posn (+ (posn-x posn) 20) yposn+200) 'black) (sleep-for-a-while .5) ;clear person so we can draw second stage of the step (clear-solid-rect (make-posn (- (posn-x posn) 80) yposn-50) 150 401) ;Second Draw (head-facing-left (make-posn xposn-34 (posn-y posn))) ;torso (draw-solid-line (make-posn xposn-34 yposn+50) (make-posn xposn-34 yposn+175) 'black) ;right leg (draw-solid-line (make-posn xposn-34 yposn+175) (make-posn xposn-50 yposn+250) 'black) (draw-solid-line (make-posn xposn-50 yposn+250) (make-posn (- (posn-x posn) 1) yposn+300) 'black) ;;left leg (draw-solid-line (make-posn xposn-34 yposn+175) (make-posn (- (posn-x posn) 22) (+ (posn-y posn) 350)) 'black) ;left arm (draw-solid-line (make-posn xposn-34 yposn+75) (make-posn (- (posn-x posn) 71) yposn+200) 'black) ;right arm (draw-solid-line (make-posn xposn-34 yposn+75) (make-posn (+ (posn-x posn) 3) yposn+200) 'black) (sleep-for-a-while .5) ;clear area for third step (clear-solid-rect (make-posn (+ (posn-x posn) 0) yposn-50) 160 401) ;;Third Draw ;Draw man, who has finished his step (turn-to-left (make-posn xposn-50 (posn-y posn))) ;Make man step again if necessary (move-left (make-posn xposn-50 (posn-y posn)) (- distance 50)) )] ))) ;Contract: head-facing-right posn -> boolean ;Purpose: Draw a head facing left, helper function. (define (head-facing-right posn) (and ;mouth (draw-solid-rect (make-posn (+ (posn-x posn) 12) (+ (posn-y posn) 25)) 30 5) ;head circle (draw-circle (make-posn (posn-x posn) (posn-y posn)) 50 'black) ;eye (draw-solid-disk (make-posn (+ (posn-x posn) 25) (- (posn-y posn) 25)) 4 'black) )) ;Contract: turn-to-right, posn -> boolean ;Purpose: Draw a man facing left. (define (turn-to-right posn) (and ;clear area in case man is turning (clear-solid-rect (make-posn (- (posn-x posn) 50) (- (posn-y posn) 50)) 105 400) (head-facing-right posn) ;spine (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 50)) (make-posn (posn-x posn) (+ (posn-y posn) 175)) 'black) ;left leg (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 175)) (make-posn (- (posn-x posn) 40) (+ (posn-y posn) 350)) 'black) ;right leg (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 175)) (make-posn (+ (posn-x posn) 40) (+ (posn-y posn) 350)) 'black) ;left arm (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 75)) (make-posn (- (posn-x posn) 50) (+ (posn-y posn) 200)) 'black) ;right arm (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 75)) (make-posn (+ (posn-x posn) 50) (+ (posn-y posn) 200)) 'black) (sleep-for-a-while .5) )) ;Contract: move-right, posn number -> boolean ;Purpose: To move our guy right (define (move-right posn distance) (local ((define xposn+17 (+ (posn-x posn) 17)) (define yposn+175 (+ (posn-y posn) 175)) (define yposn+200 (+ (posn-y posn) 200)) (define yposn+75 (+ (posn-y posn) 75)) (define xposn+34 (+ (posn-x posn) 34))) (cond [(= 0 distance) true] [else (and (sleep-for-a-while .5) (clear-solid-rect (make-posn (- (posn-x posn) 50) (- (posn-y posn) 50)) 130 401) ;;First Draw (head-facing-right (make-posn xposn+17 (posn-y posn))) ;torso (draw-solid-line (make-posn xposn+17 (+ (posn-y posn) 50)) (make-posn xposn+17 yposn+175) 'black) ;right leg (draw-solid-line (make-posn xposn+17 yposn+175) (make-posn xposn+17 (+ (posn-y posn) 250)) 'black) (draw-solid-line (make-posn xposn+17 (+ (posn-y posn) 250)) (make-posn (- (posn-x posn) 33) (+ (posn-y posn) 300)) 'black) ;left leg (draw-solid-line (make-posn xposn+17 yposn+175) (make-posn (+ (posn-x posn) 22) (+ (posn-y posn) 350)) 'black) ;right arm (draw-solid-line (make-posn xposn+17 yposn+75) (make-posn (+ (posn-x posn) 54) yposn+200) 'black) ;left arm (draw-solid-line (make-posn xposn+17 yposn+75) (make-posn (- (posn-x posn) 20) yposn+200) 'black) (sleep-for-a-while .5) (clear-solid-rect (make-posn (- (posn-x posn) 75) (- (posn-y posn) 50)) 150 401) ;;Second Draw (head-facing-right (make-posn xposn+34 (posn-y posn))) ;torso (draw-solid-line (make-posn xposn+34 (+ (posn-y posn) 50)) (make-posn xposn+34 yposn+175) 'black) ;right leg (draw-solid-line (make-posn xposn+34 yposn+175) (make-posn (+ (posn-x posn) 50) (+ (posn-y posn) 250)) 'black) (draw-solid-line (make-posn (+ (posn-x posn) 50) (+ (posn-y posn) 250)) (make-posn (+ (posn-x posn) 1) (+ (posn-y posn) 300)) 'black) ;left leg (draw-solid-line (make-posn xposn+34 yposn+175) (make-posn (+ (posn-x posn) 22) (+ (posn-y posn) 350)) 'black) ;arms (draw-solid-line (make-posn xposn+34 yposn+75) (make-posn (+ (posn-x posn) 71) yposn+200) 'black) (draw-solid-line (make-posn xposn+34 yposn+75) (make-posn (- (posn-x posn) 3) yposn+200) 'black) ;;Third Draw (sleep-for-a-while .5) (clear-solid-rect (make-posn (- (posn-x posn) 75) (- (posn-y posn) 50)) 130 401) (turn-to-right (make-posn (+ (posn-x posn) 50) (posn-y posn))) (move-right (make-posn (+ (posn-x posn) 50) (posn-y posn)) (- distance 50)) )] ))) ;Contract: draw-chest, posn -> boolean ;Purpose: To draw a chest. ;I would write notes in this, but I can't. The drawing is too complexe and overlaps in ways that make it impossible. (define (draw-chest posn) (and (draw-solid-disk (make-posn (+ (posn-x posn) 149) (posn-y posn)) 100 'yellow) (draw-solid-disk (make-posn (+ (posn-x posn) 149) (posn-y posn)) 90 'brown) (draw-solid-rect posn 200 200 'yellow) (draw-solid-disk (make-posn (+ (posn-x posn) 99) (posn-y posn)) 100 'yellow) (draw-solid-disk (make-posn (+ (posn-x posn) 99) (posn-y posn)) 90 'brown) (draw-solid-rect (make-posn (+ (posn-x posn) 10) (+ (posn-y posn) 10)) 180 180 'brown) (draw-solid-rect posn 200 10 'yellow) (draw-solid-rect (make-posn (+ (posn-x posn) 100) (- (posn-y posn) 100)) 50 10 'yellow) (draw-solid-rect (make-posn (+ (posn-x posn) 200) (posn-y posn)) 51 200 'yellow) (draw-solid-rect (make-posn (+ (posn-x posn) 200) (+ (posn-y posn) 10)) 40 180 'brown) (draw-solid-disk (make-posn (+ (posn-x posn) 218) (+ (posn-y posn) 4)) 10 'yellow) (draw-solid-disk (make-posn (+ (posn-x posn) 100) (+ (posn-y posn) 35)) 35 'yellow) (draw-solid-disk (make-posn (+ (posn-x posn) 100) (+ (posn-y posn) 35)) 30 'brown) (draw-solid-rect (make-posn (+ (posn-x posn) 80) (+ (posn-y posn) 0)) 40 10 'yellow) (draw-solid-rect (make-posn (+ (posn-x posn) 87.5) (+ (posn-y posn) 63)) 30 10 'black) )) ;Contract: draw-opened-chest, posn -> boolean ;Purpose: To draw an opened chest. (define (draw-opened-chest posn) (and ;draws a regular chest (draw-chest posn) ;clears top of chest (clear-solid-rect (make-posn (- (posn-x posn) 1) (- (posn-y posn) 100)) 252 100) ;redraws the top of the chest, but in the opened position. (draw-solid-disk (make-posn (+ (posn-x posn) 5) (- (posn-y posn) 150)) 100 'yellow) (draw-solid-disk (make-posn (+ (posn-x posn) 5) (- (posn-y posn) 150)) 90 'brown) (draw-solid-disk (make-posn (+ (posn-x posn) 5) (- (posn-y posn) 100)) 100 'yellow) (draw-solid-disk (make-posn (+ (posn-x posn) 5) (- (posn-y posn) 100)) 90 'brown) (draw-solid-disk (make-posn (+ (posn-x posn) 8) (- (posn-y posn) 220)) 10 'yellow) (clear-solid-rect (make-posn (+ (posn-x posn) 5) (- (posn-y posn) 250)) 102 250) (draw-solid-rect (make-posn (+ (posn-x posn) 5) (- (posn-y posn) 250)) 5 250 'yellow) (draw-solid-rect (make-posn (- (posn-x posn) 95) (- (posn-y posn) 140)) 10 40 'yellow) )) ;Contract: clear-chest posn -> boolean ;Purpose: To clear an opened or closed chest. (define (clear-chest posn) (clear-solid-rect (make-posn (- (posn-x posn) 95) (- (posn-y posn) 250)) 346 450) ) ;Contract: open-chest, posn -> boolean ;Purpose: To draw our guy opening a chest (define (open-chest posn) (local ((define xposn-50 (- (posn-x posn) 50)) (define yposn-175 (+ (posn-y posn) 175)) (define yposn+350 (+ (posn-y posn) 350))) (and (clear-solid-rect (make-posn xposn-50 (- (posn-y posn) 50)) 105 400) (head-facing-left posn) ;arms (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 75)) (make-posn xposn-50 (+ (posn-y posn) 150)) 'black) (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 75)) (make-posn (- (posn-x posn) 150) (+ (posn-y posn) 150)) 'black) (clear-solid-rect (make-posn xposn-50 (- (posn-y posn) 50)) 105 400) ;First Draw (head-facing-left posn) ;Body & Legs (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 50)) (make-posn (posn-x posn) yposn-175) 'black) (draw-solid-line (make-posn (posn-x posn) yposn-175) (make-posn (- (posn-x posn) 40) yposn+350) 'black) (draw-solid-line (make-posn (posn-x posn) yposn-175) (make-posn (+ (posn-x posn) 40) yposn+350) 'black) ;arms (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 75)) (make-posn (- (posn-x posn) 125) (+ (posn-y posn) 150)) 'black) (sleep-for-a-while .5) ;Second Draw (clear-solid-rect (make-posn (- (posn-x posn) 52) (- (posn-y posn) 50)) 105 400) (draw-opened-chest (make-posn (- (posn-x posn) 300) (+ (posn-y posn) 150))) ;Body & Legs (head-facing-left posn) (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 50)) (make-posn (posn-x posn) yposn-175) 'black) (draw-solid-line (make-posn (posn-x posn) yposn-175) (make-posn (- (posn-x posn) 40) yposn+350) 'black) (draw-solid-line (make-posn (posn-x posn) yposn-175) (make-posn (+ (posn-x posn) 40) yposn+350) 'black) ;arms (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 75)) (make-posn xposn-50 (- (posn-y posn) 45)) 'black) (draw-solid-line (make-posn (posn-x posn) (+ (posn-y posn) 75)) (make-posn xposn-50 (- (posn-y posn) 45)) 'black) ))) ; Accumulation 1 ; Starting Weapons (define starting-items(list "bag")) ; The following allows the player to choose their character's name. (define character-name (get-answer "What's your name?" 5)) (define chest-message (string-append character-name " found a chest. Choose your item!")) ; The character is animated (draw-chest (make-posn 500 450)) (draw-standing (make-posn 1000 300)) (turn-to-left (make-posn 1000 300)) (move-left (make-posn 1000 300) 200) (open-chest (make-posn 800 300)) (draw-solid-string (make-posn 300 50) chest-message) (sleep-for-a-while 2) (clear-solid-string (make-posn 300 50) chest-message) ; The first list of item choices. (define item-choices1 (list "black hat" "Ball of Teleporty")) (define item-list1 (cons (get-choice "Choose Your Item" item-choices1) starting-items)) ;; using string-append to combine strings. In this case the strings are: ;; the character name, " now has a ", and the newly-added item in the ;; weapons list (define message (string-append character-name " now has a " (first item-list1))) ;; draws a string on the canvas at the given position ;; no control over the font or the color, sorry... ;; you might want to add a drawing, too (draw-solid-string (make-posn 300 50) message) (sleep-for-a-while 3) ; Drawing for "Ball of Teleporty" ;; concentric-circles: posn, number, number, color, color -> boolean ;; The function draws a series of concentric circles of ;; alternatining colors (color1, color2) with the center ;; given by the parameter center, the largest radius given by ;; radius (>= 0), the smallest radius given by min-radius, the ;; outer color given by color1. The radius of the next circle is ;; 20 pixels less than of the current one (define (concentric-circles center radius min-radius color1 color2) (cond [(< radius min-radius) true] [else (and (draw-solid-disk center radius color1) (concentric-circles center (- radius 20) min-radius color2 color1))])) ; Drawing for "black hat" ; black-hat: integer, integer, integer, integer, integer -> boolean ; Purpose: To draw a picture of a black hat at the given position and with the given dimentions. (define (black-hat x y w h) (and (draw-solid-rect (make-posn x y) h w 'black) (draw-solid-rect (make-posn (- x (/ w 2)) (+ y h)) (* 2 h) (* .2 w)'black))) ;; clear the string (clear-solid-string (make-posn 300 50) message) (sleep-for-a-while 1) ; draw-items1: list -> boolean ; Purpose: To determine which item was chosen from item-list1, and then to draw that item. (define (draw-items1 item-list1) (cond [(string=? "black hat" (first item-list1)) (black-hat 100 50 100 100)] [else (concentric-circles (make-posn 150 130) 120 12 'green 'red)])) (draw-items1 item-list1) (sleep-for-a-while 2) (clear-chest (make-posn 500 450)) (clear-standing (make-posn 800 300)) ; Accumulation 2 ; The character is animated (draw-standing (make-posn 400 300)) (turn-to-right (make-posn 400 300)) (move-right (make-posn 400 300) 300) (draw-standing (make-posn 700 300)) (turn-to-left (make-posn 700 300)) (draw-chest (make-posn 400 450)) (open-chest (make-posn 700 300)) (draw-solid-string (make-posn 300 50) chest-message) (sleep-for-a-while 2) (clear-solid-string (make-posn 300 50) chest-message) ; The second list of item choices. (define item-choices2 (list "Lightsaber" "laptop")) (define item-list2 (cons (get-choice "Choose Your Item" item-choices2) item-list1)) ; message2: string, string, string -> boolean ; Purpose: to use "string-append" to link 3 strings together to form a sentence. (define message2 (string-append character-name " now has a " (first item-list2))) (sleep-for-a-while 2) (draw-solid-string (make-posn 300 50) message2) (sleep-for-a-while 3) (clear-solid-string (make-posn 300 50) message2) (sleep-for-a-while 1) ; laptop drawing ; laptop: symbol -> boolean ; Purpose: To draw a picture of a laptop using the given color (define (laptop color) (and (draw-solid-rect (make-posn 50 300) 200 120 color) (draw-solid-rect (make-posn 60 310) 180 100 'white) (draw-solid-line (make-posn 50 420) (make-posn 10 500) color) (draw-solid-line (make-posn 250 420) (make-posn 290 500) color) (draw-solid-line (make-posn 10 500) (make-posn 290 500) color) (draw-solid-rect (make-posn 10 500) 280 10 color))) ; Lightsaber drawing ; Lightsaber: symbol -> boolean ; Purpose: To draw a picture of a Lightsaber with the given blade color (define (Lightsaber color) (and (draw-solid-rect (make-posn 142 455) 16 65 'gray) (draw-solid-rect (make-posn 142 260) 16 195 color) (draw-solid-line (make-posn 140 258) (make-posn 140 455) 'black) (draw-solid-line (make-posn 159 258) (make-posn 159 455) 'black))) ; draw-items2: list -> boolean ; Purpose: To determine which item was chosen from item-list2, and then to draw that item. (define (draw-items2 item-list2) (cond [(string=? "Lightsaber" (first item-list2)) (Lightsaber 'red)] [else (laptop 'black)])) (draw-items2 item-list2) (clear-chest (make-posn 400 450)) (clear-standing (make-posn 700 300)) (sleep-for-a-while 2) ; Accumulation 3 ; The character is animated (draw-standing (make-posn 400 300)) (turn-to-right (make-posn 400 300)) (move-right (make-posn 400 300) 300) (draw-standing (make-posn 700 300)) (turn-to-left (make-posn 700 300)) (draw-chest (make-posn 400 450)) (open-chest (make-posn 700 300)) (draw-solid-string (make-posn 300 50) chest-message) (sleep-for-a-while 2) (clear-solid-string (make-posn 300 50) chest-message) ; The third list of item choices. (define item-choices3 (list "knife" "bat")) (define item-list3 (cons (get-choice "Choose Your Item" item-choices3) item-list2)) (sleep-for-a-while 2) ; message3: string, string, string -> boolean ; Purpose: to use "string-append" to link 3 strings together to form a sentence. (define message3 (string-append character-name " found a " (first item-list3))) (sleep-for-a-while 2) (draw-solid-string (make-posn 300 50) message3) (sleep-for-a-while 2) (clear-solid-string (make-posn 300 50) message3) ; bat drawing ; bat: symbol -> boolean ; Purpose: To draw a picture of a bat of the given color. (define (bat color) (and (draw-solid-disk (make-posn 30 600) 20 color) (draw-solid-rect (make-posn 50 590) 100 20 color) (draw-solid-rect (make-posn 150 585) 150 30 color) (draw-solid-disk (make-posn 300 600) 15 color))) ; knife drawing ; knife: symbol -> boolean ; Purpose: To draw a picture of a knife with a handle of the given color. (define (knife color) (and (draw-solid-rect (make-posn 50 590) 75 30 color) (draw-solid-rect (make-posn 125 590) 175 60 'gray) (draw-solid-disk (make-posn 50 605) 15 color) (draw-solid-disk (make-posn 85 605) 5 'gray) (draw-solid-disk (make-posn 105 605) 5 'gray))) ; draw-items3: list -> boolean ; Purpose: To determine which item was chosen from item-list3, and then to draw that item. (define (draw-items3 item-list3) (cond [(string=? "knife" (first item-list3)) (knife 'black)] [else (bat 'orange)])) (draw-items3 item-list3) (clear-chest (make-posn 400 450)) (clear-standing (make-posn 700 300)) (draw-standing (make-posn 600 300)) (sleep-for-a-while 2) ; Accumulation 4 ; sub-message: string, string -> boolean ; Purpose: To use "string-append" to link two strings together and form a sentence. (define sub-message (string-append character-name " gained a new power")) (draw-solid-string (make-posn 300 50) sub-message) (sleep-for-a-while 2) (clear-solid-string (make-posn 300 50) sub-message) (sleep-for-a-while 2) ; The fouth list of item accumulation. (define item-choices4 (list "strength" "intelligence" "endurance")) (define item-list4 (cons (get-choice "Choose Your Item" item-choices4) item-list3)) ; message43: string, string, string -> boolean ; Purpose: to use "string-append" to link 3 strings together to form a sentence. (define message4 (string-append character-name " now has great " (first item-list4))) (sleep-for-a-while 2) (draw-solid-string (make-posn 20 700) message4) (sleep-for-a-while 3) ; Accumulation 5 ; get-nth: number list -> element (number, symbol, etc.) ; Purpose: To take a list of a certain length and a number n >0 and return the element in the list ; that is at the n-th position. If there is no element at that position, the function should return ; an error message, "No such element." ; Examples: ; (get-nth 2 (cons 2 (cons 3 (cons 5 (cons 7 empty))))) -> 3 ; (get-nth 2 (cons 4 (cons 5 empty))) -> 5 ; (get-nth 3 (cons 4 (cons 5 empty))) -> get-nth: No such element (define (get-nth n list) (cond [(empty? list) (error 'get-nth "No such Element")] [(= 1 n) (first list)] [else (get-nth (- n 1) (rest list))])) ; random-event: integer, list -> string ; Purpose: To obtain a random string from a list of strings of given length. (define (random-event n list) (get-nth (+ (random n) 1) list)) (define event-list (list "weight" "height" "greatness")) (define event-message (string-append character-name " gained " (random-event 3 event-list))) (draw-solid-string (make-posn 20 750) event-message) (sleep-for-a-while 3) (define final-message (string-append character-name " has " " a bag " " , " (first item-list1) " , " (first item-list2) " , " (first item-list3) " , " (first item-list4) ", and extra weight, height, or greatness ")) (draw-solid-string (make-posn 20 800) final-message) (sleep-for-a-while 2) ; A possible win scenario ; win: string, string, string -> boolean ; Purpose: To compare two strings to see if they are equal (to check if your character name is "Stanley the Manley," since that's an automatic win). (define (win a-string a-choice win-message) (cond [(string=? a-choice a-string) (and (draw-solid-string (make-posn 500 150) win-message) (error 'stop "stop"))] [else true])) (win "Stanley the Manley" character-name "Your name is Stanley the Manley, so you win!?") ; Level 1 (draw-solid-rect (make-posn 700 250) 75 450 'gray) (draw-solid-string (make-posn 500 150) (string-append character-name " encounters a largish concrete wall.")) (sleep-for-a-while 2) (clear-solid-string (make-posn 500 150) (string-append character-name " encounters a largish concrete wall.")) (draw-solid-string (make-posn 500 150) "What will you use?") (sleep-for-a-while 2) (clear-solid-string (make-posn 500 150) "What will you use?") (sleep-for-a-while 2) (define level1-choices (list (first item-list1) (first item-list2))) (define level1-list (cons (get-choice "Choose Your Item" level1-choices) empty)) (define move-on-message "You have passed the test.") (define lose-message "You failed the test...Get a job, then lose it 'cause you're that bad") ; win-or-lose: string, string, list, list -> boolean ; Purpose: To determine the player's choice to pass first obstacle and what would happen with the choice. (define (win-or-lose win-item-1 win-item-2 collection-stage-list1 collection-stage-list2 message-1 message-2) (cond [(or (string=? win-item-1 (first collection-stage-list1)) (string=? win-item-2 (first collection-stage-list2))) (and (draw-solid-string (make-posn 500 150) message-1) (sleep-for-a-while 3) (clear-solid-string (make-posn 500 150) message-1))] [else (and (draw-solid-string (make-posn 350 150) message-2 ) (sleep-for-a-while 3) (error 'win-or-lose "You lose because you fail, 'kay?"))])) (win-or-lose "Ball of Teleporty" "Lightsaber" item-list1 item-list2 move-on-message lose-message) (define level1-reason1 "You teleport over the wall") (define level1-reason2 "You melt the wall") ; reason: string, string, list, string, string -> boolean ; Purpose: To display a reason for passing the first obstacle, given the item of choice. (define (reason a-string1 a-string2 a-list a-message1 a-message2) (cond [(string=? (first a-list) a-string1) (and (draw-solid-string (make-posn 500 150) a-message1) (sleep-for-a-while 3) (clear-solid-string (make-posn 500 150) a-message1))] [(string=? (first a-list) a-string2) (and (draw-solid-string (make-posn 500 150) a-message2) (sleep-for-a-while 3) (clear-solid-string (make-posn 500 150) a-message2))] ) ) (reason "Ball of Teleporty" "Lightsaber" level1-list level1-reason1 level1-reason2) (clear-standing (make-posn 600 300)) (draw-standing (make-posn 850 300)) (sleep-for-a-while 3) (clear-solid-rect (make-posn 700 250) 75 450) ; Level 2 (draw-solid-rect (make-posn 500 205) 200 450 'brown) (draw-solid-disk (make-posn 670 425) 15 'yellow) (draw-solid-string (make-posn 300 150) (string-append character-name " encounters a locked door. A key is thrown at " character-name " at fatal speed")) (sleep-for-a-while 3) (clear-solid-string (make-posn 300 150) (string-append character-name " encounters a locked door. A key is thrown at " character-name " at fatal speed")) (draw-solid-string (make-posn 500 150) (string-append "What item will you use to deflect the key?...")) (sleep-for-a-while 3) (clear-solid-string (make-posn 500 150) (string-append "What item will you use to deflect the key?...")) (sleep-for-a-while 3) (define level2-choices (list (first level1-list) (first item-list3))) (define level2-list (cons (get-choice "Choose Your Item" level2-choices) empty)) (sleep-for-a-while 3) (define lose-message2 "You destroyed the key. Now you will starve to death in front of this door!") (win-or-lose "Ball of Teleporty" "bat" level1-list item-list3 move-on-message lose-message2) (define level2-reason1 "You teleport the key into the door") (define level2-reason2 "You bat the key down and use it to open the door") (reason "Ball of Teleporty" "bat" level2-list level2-reason1 level2-reason2) (sleep-for-a-while 3) (clear-solid-rect (make-posn 500 205) 200 450 'brown) (clear-solid-disk (make-posn 670 425) 15 'yellow) (clear-standing (make-posn 850 300)) (sleep-for-a-while 2) ; Level 3 ; leel-3-guard: integer, integer, symbol -> boolean ; Purpose: to draw three figures with a given colored shirt at the given position (define (level-3-guard x y shirt-color) (and (draw-standing (make-posn x y)) (draw-solid-rect (make-posn (- x 25) (+ y 60)) 50 150 shirt-color) ) ) (draw-solid-rect (make-posn 1000 400) 50 110 'brown) (draw-solid-disk (make-posn 1006 455) 5 'yellow) (level-3-guard 750 220 'orange) (level-3-guard 900 220 'yellow) (level-3-guard 625 220 'black) (draw-solid-string (make-posn 500 150) "You encounter a door guarded by 3 men") (sleep-for-a-while 3) (clear-solid-string (make-posn 500 150) "You encounter a door guarded by 3 men") (draw-solid-string (make-posn 500 150) "Let's see what you have...") (sleep-for-a-while 3) (clear-solid-string (make-posn 500 150) "Let's see what you have...") (win-or-lose "strength" "endurance" item-list4 item-list4 move-on-message lose-message) (sleep-for-a-while 3) (draw-solid-string (make-posn 500 150) (string-append "Your great " (first item-list4) " helped you decimate the guards")) (sleep-for-a-while 3) (clear-solid-string (make-posn 500 150) (string-append "Your great " (first item-list4) " helped you decimate the guards")) (sleep-for-a-while 2) (clear-solid-rect (make-posn 0 0) 1200 900) (draw-solid-string (make-posn 560 400) "YOU WIN")