;; 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 |Project 1 Final|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))))) ;; Project 1 by Vincent Borchardt, Kele Cable, Jonathan Yasosky ;; The Adventure of You ;; ============== 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 (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 1) (process-result (+ n 1)))] [else true] ;; the user starts typing ))) (cond [(process-result 0) (cond [(sleep-for-a-while delay) (text-contents the-answer)]) ]) )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; replace ;; Contract: any list->list ;; Purpose: Remove an item from a list and replace it with a new item (define (replace removed added a-list) (cond [(empty? a-list) empty] [(equal? (first a-list) removed) (cons added (rest a-list))] [else (cons (first a-list) (replace removed added (rest a-list)))] ) ) ;; Tests (replace "cat" "dog" (list "cat" "monkey")) ;;;;;;;;;;;;;;;;;;;;;;;;; PICTURE STRUCTURES ;;;;;;;;;;;;;;;;;;;;; ;; Wall (solid rectangle): x,y = upper left corner (integer); h,w = height, width (integer); color (symbol) (define-struct wall (x y h w color)) ;; Bomb (solid circle): x,y = center (integer); r = radius (integer); color (symbol) (define-struct bomb (x y r color)) ;; Bombed Wall Animation ;; ;; (draw-wall) ;; Contract: wall->boolean ;; Purpose: Draw a wall based on a wall structure (define (draw-wall a-wall) (draw-solid-rect (make-posn (wall-x a-wall) (wall-y a-wall)) (wall-h a-wall) (wall-w a-wall) (wall-color a-wall))) ;; (draw-bomb) ;; Contract: bomb->boolean ;; Purpose: Draw a bomb based on a bomb structure (define (draw-bomb a-bomb) (draw-solid-disk (make-posn (bomb-x a-bomb) (bomb-y a-bomb)) (bomb-r a-bomb) (bomb-color a-bomb))) ;; (clear-bomb) ;; Contract: bomb->boolean ;; Purpose: Clear a drawn bomb (define (clear-bomb a-bomb) (clear-solid-disk (make-posn (bomb-x a-bomb) (bomb-y a-bomb)) (bomb-r a-bomb) (bomb-color a-bomb))) (define wall1 (make-wall 25 100 250 200 'brown)) (define wall2 (make-wall 25 100 50 200 'brown)) (define wall3 (make-wall 225 100 50 200 'brown)) (define bomb1 (make-bomb 150 280 20 'black)) (define bomb2 (make-bomb 150 280 50 'yellow)) (define bomb3 (make-bomb 150 280 130 'orange)) (define bomb4 (make-bomb 150 280 200 'red)) ;; Chest: x,y = upper left corner (integer), h,w = height, width (integer); color (symbol);; (define-struct chest (x y h w color)) ;; (draw-chest) ;; Contract: chest->boolean ;; Purpose: Draw a chest based on a chest structure (define (draw-chest a-chest) (draw-solid-rect (make-posn (chest-x a-chest) (chest-y a-chest)) (chest-h a-chest) (chest-w a-chest) (chest-color a-chest))) (define-struct rect (x y h w color)) ;; (draw-rect) ;; Contract: rect->boolean ;; Purpose: Draw a rectangle based on a rect structure (define (draw-rect a-rect) (draw-solid-rect (make-posn (rect-x a-rect) (rect-y a-rect)) (rect-h a-rect) (rect-w a-rect) (rect-color a-rect))) (define chest1 (make-chest 100 150 100 50 'brown)) (define rect1 (make-rect 100 160 100 5 'black)) (define rect2 (make-rect 145 159 10 10 'yellow)) ;; Sword: a,b = upper left corner of horizontal (integer), c,d = height, width of horizontal (integer); x,y = upper left corner of vertical (integer), h,w = height, width of vertical (integer); color (symbol);; (define-struct handle ( a b c d x y h w color)) ;; (draw-handle) ;; Contract: handle->boolean ;; Purpose: Draw a handle based on a handle structure (define (draw-handle a-handle) (and (draw-solid-rect (make-posn (handle-a a-handle) (handle-b a-handle)) (handle-c a-handle) (handle-d a-handle) (handle-color a-handle)) (draw-solid-rect (make-posn (handle-x a-handle) (handle-y a-handle)) (handle-h a-handle) (handle-w a-handle) (handle-color a-handle)))) (define handle1 (make-handle 330 190 50 10 345 200 20 40 'blue)) (define rect3 (make-rect 345 50 20 140 'gray)) ;; Magic Sword ;; (define handle2 (make-handle 550 190 50 10 565 200 20 40 'gray)) (define rect4 (make-rect 565 50 20 140 'red)) ;; Wand ;; ;;x,y,h,w: normal parameters of a rectangle drawing (integer); color (symbol); second rectangle defined by first (define-struct wand (x y h w color)) ;; (draw-wand) ;; Contract: wand->boolean ;; Purpose: Draw a wand based on a wand structure (define (draw-wand a-wand) (and (draw-solid-rect (make-posn (wand-x a-wand) (wand-y a-wand)) (wand-h a-wand) (wand-w a-wand) (wand-color a-wand)) (draw-solid-rect (make-posn (- (wand-x a-wand) 2) (+ (wand-y a-wand) 20)) (+ (wand-h a-wand) 4) (wand-w a-wand) (wand-color a-wand)))) (define wand1 (make-wand 250 150 5 20 'black)) ;; Staff ;; ;; (draw-staff) ;; Contract: rect->boolean ;; Purpose: Draw a staff based on a rect structure (define (draw-staff x) (and (draw-solid-rect (make-posn 250 150) 7 140 'brown) (draw-solid-disk (make-posn 253 140) 10 'brown))) ;; Humor ;; ;; (draw-wand) ;; Contract: any->boolean ;; Purpose: Draw a humor abstraction (define (draw-humor x) (and (draw-solid-line (make-posn 250 150) (make-posn 250 250) 'black) (draw-solid-line (make-posn 250 250) (make-posn 300 250) 'black) (draw-circle (make-posn 350 200) 40 'black) (draw-solid-line (make-posn 420 150) (make-posn 420 250) 'black) (draw-solid-line (make-posn 420 250) (make-posn 470 250) 'black))) ;; Microphone ;; ;; (draw-wand) ;; Contract: any->boolean ;; Purpose: Draw a microphone (define (draw-microphone x) (and (draw-solid-rect (make-posn 150 150) 7 25 'black) (draw-solid-disk (make-posn 153 142) 8 'gray))) ;; Skeleton ;; ;; (make-skeleton) ;; Contract: any->boolean ;; Purpose: Draw a skeleton (define (make-skeleton x) (and (draw-circle (make-posn 250 355) 25 'black) (draw-solid-line (make-posn 250 440) (make-posn 250 380) 'black) (draw-solid-line (make-posn 250 400) (make-posn 200 410) 'black) (draw-solid-line (make-posn 250 400) (make-posn 300 410) 'black) (draw-solid-line (make-posn 250 440) (make-posn 200 490) 'black) (draw-solid-line (make-posn 250 440) (make-posn 300 490) 'black) (draw-solid-disk (make-posn 240 345) 5 'black) (draw-solid-disk (make-posn 260 345) 5 'black) (draw-solid-line (make-posn 240 365) (make-posn 260 365) 'black) (draw-solid-line (make-posn 240 410) (make-posn 260 410) 'black) (draw-solid-line (make-posn 240 420) (make-posn 260 420) 'black) (draw-solid-line (make-posn 240 430) (make-posn 260 430) 'black))) ;; Ghost ;; ;; (draw-ghost) ;; Contract: any->boolean ;; Purpose: Draw a ghost (define (draw-ghost x) (and (draw-circle (make-posn 150 300) 50 'black) (draw-solid-rect (make-posn 100 300) 100 60 'white) (draw-solid-line (make-posn 100 300) (make-posn 100 495) 'black) (draw-solid-line (make-posn 200 300) (make-posn 200 495) 'black) (draw-solid-line (make-posn 100 495) (make-posn 200 495) 'black) (draw-solid-disk (make-posn 125 300) 10 'black) (draw-solid-disk (make-posn 175 300) 10 'black))) ;; Tree ;; ;; (draw-tree) ;; Contract: any->boolean ;; Purpose: Draw a tree (define (draw-tree x) (and (draw-solid-rect (make-posn 140 300) 17 140 'brown) (draw-solid-line (make-posn 157 370) (make-posn 190 330) 'brown) (draw-solid-line (make-posn 150 355) (make-posn 100 290) 'brown) (draw-solid-disk (make-posn 100 290) 25 'darkgreen) (draw-solid-disk (make-posn 190 330) 25 'darkgreen) (draw-solid-disk (make-posn 153 290) 40 'darkgreen))) ;; Fairy: x,y = center of a disk (integer), z = radius of a disk (integer), color (symbol);; (define-struct fairy (x y z color)) ;; (draw-fairy) ;; Contract: fairy->boolean ;; Purpose: Draw a fairy based on a fairy structure (define (draw-fairy a-fairy) (draw-solid-disk (make-posn (fairy-x a-fairy) (fairy-y a-fairy)) (fairy-z a-fairy) (fairy-color a-fairy))) (define fairy1 (make-fairy 150 300 20 'lightblue)) ;;Grappling Hook: x,y = start position of rope (integer), a,b = end position of rope (integer) color (symbol);; (define-struct rope (x y a b color)) ;; (draw-rope) ;; Contract: rope->boolean ;; Purpose: Draw a rope based on a rope structure (define (draw-rope a-rope) (draw-solid-line (make-posn (rope-x a-rope) (rope-y a-rope)) (make-posn (rope-a a-rope) (rope-b a-rope)) (rope-color a-rope))) (define-struct circle (x y r color)) ;; (draw-circle) ;; Contract: circle->boolean ;; Purpose: Draw a disk based on a circle structure (define (create-circle a-circle) (draw-solid-disk (make-posn (circle-x a-circle) (circle-y a-circle)) (circle-r a-circle) (circle-color a-circle))) (define rope1 (make-rope 275 290 150 100 'black)) (define circle99 (make-circle 150 100 10 'gray)) (define chest-yes-no-list (list "yes" "no")) ;; (chest-yes-no) ;; Contract: any->string ;; Purpose: Uses a new get-choice from the gui (define (chest-yes-no a) (get-choice "Open the chest?" chest-yes-no-list)) ;; THE GAME BEGINS ;; ;; The draw-rect function is used as a clear screen function in our game. In order to keep from changing every rectangle whenever we change the canvas size, we define a width and height for the canvas. (define width 800) (define height 500) (start width height) ;; Part 1: Beginnings (draw-solid-string (make-posn 20 20) "You wake up to find yourself in a cave.") (draw-solid-string (make-posn 20 40) "You don't remember how you got here.") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 80) "You find a nametag on your person. It says:") (sleep-for-a-while 2) (define character-name (get-answer "Hi, my name is" 2)) ;; The player is able to choose between three classes: fighter, wizard, and jester. Their choice will affect the items they receive and how they can defeat certain obstacles. (define fighting-styles (list "fighter" "wizard" "jester")) (define style (get-choice "I am a " fighting-styles)) (clear-solid-string (make-posn 20 20) "You wake up to find yourself in a cave.") (clear-solid-string (make-posn 20 40) "You don't remember how you got here.") (clear-solid-string (make-posn 20 80) "You find a nametag on your person. It says:") ;; The nametag ;; The player "learns" their name and combat style by finding a nametag on their person. The nametag is color-coded according to class. (define color-nametag (cond [(string=? style "fighter") 'red] [(string=? style "wizard") 'lightblue] [(string=? style "jester") 'yellow] ) ) (draw-solid-rect (make-posn 10 10) 200 70 color-nametag) (draw-solid-string (make-posn 20 30) (string-append "Hi, my name is " character-name)) (draw-solid-string (make-posn 20 70) (string-append "I am a " style)) ;; The player is given a weapon according to their class. This weapon is put into a list called weapon-list1. (define weapon-list1 (cond [(string=? style "fighter") (cons "sword" empty)] [(string=? style "wizard") (cons "wand" empty)] [(string=? style "jester") (cons "humor" empty)] ) ) (sleep-for-a-while 2) (draw-solid-string (make-posn 20 120) (string-append "You find a " (first weapon-list1))) ;; A picture of the player's weapon is shown. (cond [(string=? style "fighter") (and (draw-handle handle1) (draw-rect rect3))] [(string=? style "wizard") (draw-wand wand1)] [(string=? style "jester") (draw-humor 0)] ) (sleep-for-a-while 2) ;; After acquiring their main weapon, the player finds a chest with three items: the grappling hook, the bomb and the spoon. (draw-solid-string (make-posn 20 140) (string-append "You see a chest next to the " (first weapon-list1))) ;; Picture of the chest (draw-chest chest1) (draw-rect rect1) (draw-rect rect2) (sleep-for-a-while 2) ;; The weapon and the three items are combined into an inventory, called inventory2. Whenever the player gains a new item, the number of the inventory increases. (define inventory2 (list "grappling hook" "bomb" "spoon" (first weapon-list1))) (draw-solid-string (make-posn 20 270) "You receive a grappling hook, a bomb, and a spoon!") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 290) "You see a door to your right and walk through it.") (sleep-for-a-while 3) ; Clear screen (draw-solid-rect (make-posn 0 0) width height 'white) ;; Part 2: The Wall and The Pit ;; (draw-solid-string (make-posn 20 20) "In the next room, you come across a large wall.") (sleep-for-a-while 1) (draw-wall wall1) ;; This part is defined by the wall and pit obstacles. The player needs to find a way to pass the wall using the items given. Following the wall, the player falls down a pit. ;; (wall-choice) ;; Contract: any->string ;; Purpose: Uses a new get-choice from the gui (define (wall-choice a) (get-choice "Which item will you use to proceed?" inventory2)) (define wall1a (wall-choice 0)) ;; Their main weapons have no effect on the wall. ;; The grappling hook allows ascent of the wall. ;; The bomb blows a hole into the wall. ;; The spoon has a 1 in 5 chance of blowing up the wall. ;; (wall1-response) ;; Contract: string->boolean ;; Purpose: Uses a string to draw on the canvas (define (wall1-response answer) (cond [(string=? answer "grappling hook") (and (draw-solid-string (make-posn 20 50) "You ascend the wall!") (sleep-for-a-while 2) (draw-rope rope1) (create-circle circle99) (sleep-for-a-while 2) (draw-solid-string (make-posn 20 70) "You jump down and start falling down a pit!"))] [(string=? answer "bomb") (and (draw-solid-string (make-posn 20 50) "You blast a hole in the wall!") (sleep-for-a-while 2) ; The bombed wall animation: (draw-bomb bomb1) (sleep-for-a-while 1) (draw-bomb bomb4) (draw-bomb bomb3) (draw-bomb bomb2) (sleep-for-a-while 1) (clear-bomb bomb4) (draw-wall wall2) (draw-wall wall3) (sleep-for-a-while 3) (draw-solid-string (make-posn 20 70) "You walk forward and start falling down a pit!"))] [(and (string=? answer "spoon") (>= (random 5) 4)) (and (draw-solid-string (make-posn 20 50) "It's a miracle! The spoon destroyed the wall!") (sleep-for-a-while 1) (draw-solid-rect (make-posn 75 100) 150 200 'white) (draw-solid-string (make-posn 20 70) "Bet you didn't see that one coming!") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 90) "You walk forward and start falling down a pit!"))] [else (and (draw-solid-string (make-posn 20 50) "The item seems to be ineffective...") (sleep-for-a-while 2) (and (clear-solid-string (make-posn 20 50) "The item seems to be ineffective...") (wall1-response (wall-choice 0))))] ) ) (wall1-response wall1a) (sleep-for-a-while 2) (draw-solid-rect (make-posn 0 0) width height 'white) (draw-solid-string (make-posn 20 20) "A chest appears falling next to you!") (define chest2 (chest-yes-no 0)) ;; The player is falling down a pit and has to open the chest. However, we give the player a choice between opening the chest and death. They have 5 tries. ;; (chest2-response) ;; Contract: string integer->boolean (or exit) ;; Purpose: Uses a string to draw on the canvas (define (chest2-response answer tries) (cond [(string=? answer "yes") true] [(and (string=? answer "no") (= tries 5)) (and (draw-solid-string (make-posn 20 40) "You do know you're falling right?") (sleep-for-a-while 1) (chest2-response (chest-yes-no 0) 4))] [(and (string=? answer "no") (= tries 4)) (and (draw-solid-string (make-posn 20 60) "This appears to be the only option.") (sleep-for-a-while 1) (chest2-response (chest-yes-no 0) 3))] [(and (string=? answer "no") (= tries 3)) (and (draw-solid-string (make-posn 20 80) "You're falling very fast.") (sleep-for-a-while 1) (chest2-response (chest-yes-no 0) 2))] [(and (string=? answer "no") (= tries 2)) (and (draw-solid-string (make-posn 20 100) "You see the ground below.") (sleep-for-a-while 1) (chest2-response (chest-yes-no 0) 1))] [(and (string=? answer "no") (= tries 1)) (and (draw-solid-string (make-posn 20 120) "You don't appear to have much time left.") (sleep-for-a-while 1) (chest2-response (chest-yes-no 0) 0))] [(and (string=? answer "no") (= tries 0)) (and (draw-solid-string (make-posn 20 140) "The ground was very hard.") (sleep-for-a-while 1) (exit))] ) ) (chest2-response chest2 5) (draw-solid-rect (make-posn 0 0) width height 'white) (define inventory3 (cons "umbrella" inventory2)) (draw-solid-string (make-posn 20 20) "You found an umbrella!") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 40) "The umbrella allows you to land safely.") (sleep-for-a-while 2) ;; Part 3: The Skeleton ;; Now the player encounters a skeleton. Ultimately, this obstacle is for the fighter to receive an upgraded sword. (draw-solid-string (make-posn 20 60) "After you land, a skeleton crashes through the wall!") (sleep-for-a-while 1) ; Skeleton picture (make-skeleton 0) (sleep-for-a-while 1) (draw-solid-string (make-posn 20 80) "He appears to want to hurt you.") (sleep-for-a-while 1) ;; (skeleton-choice) ;; Contract: any->string ;; Purpose: Uses a new get-choice from the gui (define (skeleton-choice a) (get-choice "Quick! Do something!" inventory3)) (define skeleton1a (skeleton-choice 0)) ;; The game makes it so the fighter HAS to use their sword. For the wizard and jester, the bomb works fine. Other items do nothing. Following the fight, if the player is a fighter, a fairy upgrades the player's sword to a magic sword. The player also receives an axe. ;; Possible Items: ; Success: ; Sword: Destroys the skeleton ; Bomb: Blows up the skeleton ; Umbrella: Defends hit from skeleton ; Failure: ; Grappling hook, spoon ; Wand, humor ;; (skeleton1-response) ;; Contract: string integer->boolean (or exit) ;; Purpose: Uses a string to draw on the canvas (define (skeleton1-response answer tries) (cond [(string=? answer "sword") (and (draw-solid-string (make-posn 20 (+ 100 (* (- 3 tries) 20))) "The sword caused the foul monster to collapse in a heap.") (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 250) width 250 'white) (sleep-for-a-while 1) (draw-solid-string (make-posn 20 (+ 120 (* (- 3 tries) 20))) "A fairy approaches you:") (sleep-for-a-while 1) (draw-fairy fairy1) (sleep-for-a-while 1) (draw-solid-string (make-posn 20 (+ 140 (* (- 3 tries) 20))) "'You have shown great skills with the sword young warrior.'") (sleep-for-a-while 1) (draw-solid-string (make-posn 20 (+ 160 (* (- 3 tries) 20))) "'Allow me to enhance your sword, allowing it to do more damage.'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 (+ 180 (* (- 3 tries) 20))) "Your sword now glows with everlasting power!") (draw-handle handle2) (draw-rect rect4) (sleep-for-a-while 2) (draw-solid-string (make-posn 20 (+ 200 (* (- 3 tries) 20))) "You found an axe in the skeleton's remains!"))] [(and (string=? answer "bomb") (string=? style "fighter")) (and (draw-solid-string (make-posn 20 (+ 100 (* (- 3 tries) 20))) "The skeleton dodges the bomb, but stops his attack.") (sleep-for-a-while 1) (draw-solid-string (make-posn 20 (+ 120 (* (- 3 tries) 20))) "Do you have an easier way to kill him?") (sleep-for-a-while 2) (clear-solid-string (make-posn 20 (+ 100 (* (- 3 tries) 20))) "The skeleton dodges the bomb, but stops his attack.") (clear-solid-string (make-posn 20 (+ 120 (* (- 3 tries) 20))) "Do you have an easier way to kill him?") (skeleton1-response (skeleton-choice 0) tries))] [(string=? answer "bomb") (and (draw-solid-string (make-posn 20 (+ 100 (* (- 3 tries) 20))) "The explosion causes the skeleton to collapse in a heap, and another finishes the job.") (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 250) width 250 'white) (sleep-for-a-while 1) (draw-solid-string (make-posn 20 (+ 120 (* (- 3 tries) 20))) "You were very lucky to escape there. Was there a better way?") (sleep-for-a-while 1) (draw-solid-string (make-posn 20 (+ 140 (* (- 3 tries) 20))) "You found an axe in the skeleton's remains!"))] [(string=? answer "umbrella") (and (draw-solid-string (make-posn 20 (+ 100 (* (- 3 tries) 20))) "The umbrella did no damage, however, it shielded you from the skeleton's attack.") (sleep-for-a-while 2) (clear-solid-string (make-posn 20 (+ 100 (* (- 3 tries) 20))) "The umbrella did no damage, however, it shielded you from the skeleton's attack.") (skeleton1-response (skeleton-choice 0) tries))] [(= tries 3) (and (draw-solid-string (make-posn 20 100) "Your attack does nothing, only angering the beast.") (sleep-for-a-while 1) (skeleton1-response (skeleton-choice 0) (- tries 1)))] [(= tries 2) (and (draw-solid-string (make-posn 20 120) "Your attempts to repel the monster are futile as he charges to take a piece of your life away.") (sleep-for-a-while 1) (skeleton1-response (skeleton-choice 0) (- tries 1)))] [(= tries 1) (and (draw-solid-string (make-posn 20 140) "You really should try to kill him before he kills you, you know ;)") (sleep-for-a-while 1) (skeleton1-response (skeleton-choice 0) (- tries 1)))] [(= tries 0) (and (draw-solid-string (make-posn 20 160) "The skeleton has a few new bones for his collection.") (sleep-for-a-while 1) (exit))] ) ) (skeleton1-response skeleton1a 3) ; The magic sword replaces the sword in the fighter's inventory. (define inventory4 (cond [(string=? style "fighter") (cons "axe" (replace "sword" "magic sword" inventory3))] [else (cons "axe" inventory3)] ) ) (sleep-for-a-while 2) (draw-solid-rect (make-posn 0 0) width height 'white) ;; Part 4: The Ghost ;; ;; In this part, the player encounters a ghost. If the player tries to run past the ghost, the player is frozen. However, if the player chooses to use the grappling hook, they can swing past the ghost unless the player is a jester. The purpose of this encounter is to upgrade the jester's weapon. To do this, the player gets to enter a joke. Whatever the joke, the ghost laughs and helps the player. No matter the class, the player receives a flyswatter. (draw-solid-string (make-posn 20 20) "You walk into the next room.") (sleep-for-a-while 2) (draw-ghost 0) (draw-solid-string (make-posn 20 40) "Out of nowhere, a ghost appears, blocking your path, yelling:") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 60) "'Why have you come here?!'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 80) "'You must turn back and leave!'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 100) "'If you try to pass me, I must kill you!'") (sleep-for-a-while 1) ;; (pass-yes-no) ;; Contract: any->string ;; Purpose: Uses a new get-choice from the gui (define (pass-yes-no a) (get-choice "Try to run past?" chest-yes-no-list)) (define pass1 (pass-yes-no 0)) ;; (skeleton1-response) ;; Contract: string->boolean (or exit) ;; Purpose: Uses a string to draw on the canvas (define (pass-response answer) (cond [(string=? answer "yes") (and (draw-solid-string (make-posn 20 120) "The ghost freezes you within a second, leaving you at his mercy.") (sleep-for-a-while 2) (exit))] [else true] ) ) (pass-response pass1) ;; (ghost-choice) ;; Contract: any->string ;; Purpose: Uses a new get-choice from the gui (define (ghost-choice a) (get-choice "So what will you do to get by?" inventory4)) (define ghost1a (ghost-choice 0)) ;; Possible Items: ; Success: ; Humor: Makes the ghost laugh ; Grappling hook: The player swings past the ghost ; Failure: ; Bomb, spoon, axe ; Magic sword, wand ; Umbrella ;; (ghost1-response) ;; Contract: string->boolean ;; Purpose: Uses a string to draw on the canvas (define (ghost1-response answer) (cond [(string=? answer "humor") (and (draw-solid-string (make-posn 20 120) "You muster up your best comedic genius:") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 140) (get-answer "What's your setup?" 7)) (sleep-for-a-while 2) (draw-solid-string (make-posn 20 160) (get-answer "What's your punchline?" 5)) (sleep-for-a-while 2) (draw-solid-string (make-posn 20 180) "The ghost laughs, but with humor and excitement!") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 200) "'After calming down, the ghost exclaims:'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 220) "'That is the best thing I've heard in 1000 years!'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 240) "'Maybe you do have what it takes to defeat the beast...'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 260) "'Here, take my flyswatter, it's the only way I've gotten this far.'") (sleep-for-a-while 3) (draw-solid-rect (make-posn 0 0) width height 'white) (draw-solid-string (make-posn 20 20) "After leaving the room, a fairy appears.") (sleep-for-a-while 1) (draw-fairy fairy1) (sleep-for-a-while 1) (draw-solid-string (make-posn 20 40) "'You have shown great skills with the voice, young jester.'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 60) "'Allow me to give you a way to communicate your humor to the masses.'") (sleep-for-a-while 2) (draw-microphone 0) (draw-solid-string (make-posn 20 80) "You now have a microphone!") (sleep-for-a-while 2))] [(and (string=? answer "grappling hook") (string=? style "jester")) (and (draw-solid-string (make-posn 20 140) "You miss the ledge above the ghost.") (sleep-for-a-while 1) (draw-solid-string (make-posn 20 160) "Should a jester really be throwing a grappling hook?") (sleep-for-a-while 2) (clear-solid-string (make-posn 20 140) "You miss the ledge above the ghost.") (clear-solid-string (make-posn 20 160) "Should a jester really be throwing a grappling hook?") (ghost1-response (ghost-choice 0)))] [(string=? answer "grappling hook") (and (draw-solid-string (make-posn 20 140) "You grab onto a ledge above the ghost and swing over his head.") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 160) "The ghost yells as you run away:") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 180) "'You have disobeyed my command!'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 200) "'You will perish at the hands of the beast inside its trunk!'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 220) "As you exit, a flyswatter hits you in the head and lands beside you.") (sleep-for-a-while 1) (draw-solid-string (make-posn 20 240) "You pick it up for no particular reason."))] [else (and (draw-solid-string (make-posn 20 160) "Your weapons do nothing to the spiritual being.") (sleep-for-a-while 1) (draw-solid-string (make-posn 20 180) "The ghost only laughs with spite.") (sleep-for-a-while 2) (clear-solid-string (make-posn 20 160) "Your weapons do nothing to the spiritual being.") (clear-solid-string (make-posn 20 180) "The ghost only laughs with spite.") (ghost1-response (ghost-choice 0)))] ) ) (ghost1-response ghost1a) ;; The microphone replaces the humor in the jester's inventory. The flyswatter is added to all inventories. (define inventory5 (cond [(string=? style "jester") (cons "flyswatter" (replace "humor" "microphone" inventory4))] [else (cons "flyswatter" inventory4)] ) ) (sleep-for-a-while 3) (draw-solid-rect (make-posn 0 0) width height 'white) ;; Part 5: The Tree ;; ;; In this part, the player is getting close to the end but has to get through a tree. The ultimate goal of this part is for the wizard to receive an upgraded wand: a staff. For the other players, the axe they picked up from the skeleton is sufficient. (draw-solid-string (make-posn 20 20) "In the final room, you see the exit just beyond a large tree.") (draw-tree 0) (sleep-for-a-while 1) ;; (tree-choice) ;; Contract: any->string ;; Purpose: Uses a new get-choice from the gui (define (tree-choice a) (get-choice "Which item will you use?" inventory5)) (define tree1a (tree-choice 0)) ;; Possible Items: ; Success: ; Wand: Lights tree on fire ; Axe: Chops tree down ; Failure: ; Bomb, spoon, grappling hook ; Magic sword, microphone ; Umbrella, flyswatter ;; (tree1-response) ;; Contract: string->boolean ;; Purpose: Uses a string to draw on the canvas (define (tree1-response answer) (cond [(string=? answer "wand") (and (draw-solid-string (make-posn 20 40) "A fireball launches from the wand!") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 60) "The tree lights on fire and slowly burns down!") (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 250) width 50 'white) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 300) width 50 'white) (draw-solid-string (make-posn 20 80) "While the tree burns, a fairy approaches...") (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 350) width 50 'white) (draw-fairy fairy1) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 400) width 100 'white) (draw-solid-string (make-posn 20 100) "'You have shown great skill with your wand, young wizard.'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 120) "'Let me give you a new way to cast your spells.'") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 140) "You receive a staff!") (draw-staff 0) (sleep-for-a-while 2) )] [(and (string=? answer "axe") (string=? style "wizard")) (and (draw-solid-string (make-posn 20 40) "You can barely lift the axe, much less swing it.") (sleep-for-a-while 1) (draw-solid-string (make-posn 20 60) "Can't a wizard do things a little less physically?") (sleep-for-a-while 2) (clear-solid-string (make-posn 20 40) "You can barely lift the axe, much less swing it.") (clear-solid-string (make-posn 20 60) "Can't a wizard do things a little less physically?") (tree1-response (tree-choice 0)))] [(string=? answer "axe") (draw-solid-string (make-posn 20 40) "The tree falls to the ground harmlessly.")] [else (and (draw-solid-string (make-posn 20 40) "A few leaves fall off the tree, but the trunk is still structurally intact.") (sleep-for-a-while 2) (clear-solid-string (make-posn 20 40) "A few leaves fall off the tree, but the trunk is still structurally intact.") (tree1-response (tree-choice 0)))] ) ) (tree1-response tree1a) ;; The staff replaces the wand in the wizard's inventory. (define inventory6 (cond [(string=? style "wizard") (replace "wand" "staff" inventory5)] [else inventory5] ) ) (sleep-for-a-while 2) (draw-solid-rect (make-posn 0 0) width height 'white) ;; Part 6: The Fairy ;; ;; In this part, the player encounters the fairy yet again. However, she is a bit more annoying now. The player gets to swat her with the flyswatter he/she recently received. But once he/she swats the fairy, the fairy becomes a huge beast. All the player has to do is hit the fairy with their upgraded weapon. (draw-solid-string (make-posn 20 20) "With the tree destroyed, you can clearly see the exit of the cave.") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 40) "However, as you walk towards the exit, a vile beast rises from the tree's remains.") (sleep-for-a-while 2) (draw-fairy fairy1) (draw-solid-string (make-posn 20 60) "'Hey! Look! Listen! Hey!'") (sleep-for-a-while 3) (draw-solid-string (make-posn 20 80) "You try to pass but the annoying fairy gets in your way.") (sleep-for-a-while 2) ;; (fairy-choice) ;; Contract: any->string ;; Purpose: Uses a new get-choice from the gui (define (fairy-choice a) (get-choice "Now what?" inventory6)) (define fairy1a (fairy-choice 0)) ;; Possible Items: ; Success: ; Flyswatter ; Failure: ; Bomb, spoon, grappling hook ; Magic sword, staff, microphone ; Umbrella, axe ;; (fairy1-response) ;; Contract: string->boolean ;; Purpose: Uses a string to draw on the canvas (define (fairy1-response answer) (cond [(string=? answer "flyswatter") (draw-solid-string (make-posn 20 100) "You swat the pest and it falls to the ground.")] [else (and (draw-solid-string (make-posn 20 100) "The item seems to be ineffective...") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 120) "'Hey! Look! Listen!'") (and (clear-solid-string (make-posn 20 100) "The item seems to be ineffective...") (clear-solid-string (make-posn 20 120) "'Hey! Look! Listen!'") (fairy1-response (fairy-choice 0))))] ) ) (fairy1-response fairy1a) (sleep-for-a-while 2) (draw-solid-rect (make-posn 0 0) width height 'white) (draw-solid-string (make-posn 20 20) "Angered, the fairy becomes an indescribable and unspeakable horror of doom!") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 40) "'HEY! LOOK! LISTEN! I WILL EAT YOUR SOUL!'") (sleep-for-a-while 2) ;; (boss-choice) ;; Contract: any->string ;; Purpose: Uses a new get-choice from the gui (define (boss-choice a) (get-choice "The final battle is here! Do something!" inventory6)) (define boss1a (boss-choice 0)) ;; Possible Items: ; Success: ; Magic sword, staff, microphone: Kills the beast ; Failure: ; Bomb, spoon, grappling hook ; Umbrella, axe, flyswatter ;; (boss1-response) ;; Contract: string->boolean ;; Purpose: Uses a string to draw on the canvas (define (boss1-response answer tries) (cond [(string=? answer "magic sword") (draw-solid-string (make-posn 20 60) "You slash the beast's hide and blood pours out!")] [(string=? answer "staff") (draw-solid-string (make-posn 20 60) "Your staff unleashes a huge fireball burning the hide of the beast!")] [(string=? answer "microphone") (draw-solid-string (make-posn 20 60) "Your amplified voice bursts the beast's heart right out of its chest!")] [(= tries 1) (and (draw-solid-string (make-posn 20 60) "The item seems to be ineffective...") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 80) "The beast retaliates with a vicious bite, draining half your life!") (and (clear-solid-string (make-posn 20 60) "The item seems to be ineffective...") (clear-solid-string (make-posn 20 80) "The beast retaliates with a vicious bite, draining half your life!") (boss1-response (boss-choice 0) (- tries 1))))] [(= tries 0) (and (draw-solid-string (make-posn 20 60) "The creature laughs at your futile attempts and eats you whole!") (sleep-for-a-while 2) (exit))] ) ) (boss1-response boss1a 1) (sleep-for-a-while 2) (draw-solid-string (make-posn 20 80) "As the beast dies, it cries:") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 100) (string-append "'Curse you, " character-name ", fierce " style "!")) (sleep-for-a-while 2) (draw-solid-string (make-posn 20 120) "The beast falls to the ground. Dead. At the hands of its own weapon.") (sleep-for-a-while 4) (draw-solid-rect (make-posn 0 0) width height 'white) ;; Part 7: Epilogue (draw-solid-string (make-posn 20 20) "As you exit the cave, you are startled by the sun and blue sky.") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 40) "You now remember who you are and are proud of what you have become.") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 100) "You now start your journey home.") (sleep-for-a-while 2) (draw-solid-string (make-posn 20 140) "The End.")