;; 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 "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))))) ;; 1301 problem set 10 ;; Amy Grant ;; Emma Ireland ;; ============== 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: =============================== (start 700 500) ;; draws a string on the canvas at the given position (draw-solid-string (make-posn 250 200) "The Amazing Haunted Castle!") (draw-solid-string (make-posn 250 220) "By Amy Grant and Emma Ireland") (sleep-for-a-while 3) ;; the first list of choices: (define weapon-choices (list "pointy stick" "light saber" "magic wand")) ;; calling "get-choice" to get the user's choice, adding the choice to ;; the list of weapons. weapon-list is the new list (define weapon-list (cons (get-choice "Choose your weapon. You will need one to survive!!!" weapon-choices) empty)) (sleep-for-a-while 4) ;; calling a get-answer function to let the user type in their name ;; 4 is the number of seconds you expect the user to spend on typing ;; the answer (from the fisrt character to the last one). ;; Too short times may result in the program getting a partial answer ;; Feel free to adjust this time as needed (define character-name (get-answer "What's your name?" 4)) ;; Clears a string that is on the canvas at the given position (clear-solid-string (make-posn 250 200) "The Amazing Haunted Castle!") (clear-solid-string (make-posn 250 220) "By Amy Grant and Emma Ireland") ;; 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 weapon-list))) ;; 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 20 20) message) ;; Defining and drawing a ground (draw-solid-rect (make-posn 0 450) 700 50 'gray) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Functions that draw, clear, and move shapes. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 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-circle (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-circle (circle-center a-circle) (circle-radius a-circle)) ) ;; move-circle: circle number number -> circle ;; the function creates a new circle from a given one ;; with coordinates shifted by x-shift and y-shift (define (move-circle a-circle x-shift y-shift) (make-circle (make-posn (+ (posn-x (circle-center a-circle)) x-shift) (+ (posn-y (circle-center a-circle)) y-shift)) (circle-radius a-circle) (circle-color a-circle) )) ;; The structure represents a solid disk ;; 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 solid-disk (center radius color)) ;; draw-a-solid-disk: circle -> true ;; the function draws a circle structure as a disk ;; and returns true (define (draw-a-solid-disk a-circle) (draw-solid-disk (solid-disk-center a-circle) (solid-disk-radius a-circle) (solid-disk-color a-circle)) ) ;; clear-a-solid-disk: circle -> true ;; the function clears a disk corresponding to a circle ;; and returns true (define (clear-a-solid-disk a-circle) (clear-solid-disk (solid-disk-center a-circle) (solid-disk-radius a-circle)) ) ;; move-solid-disk: circle number number -> circle ;; the function creates a new circle from a given one ;; with coordinates shifted by x-shift and y-shift (define (move-solid-disk a-circle x-shift y-shift) (make-solid-disk (make-posn (+ (posn-x (solid-disk-center a-circle)) x-shift) (+ (posn-y (solid-disk-center a-circle)) y-shift)) (solid-disk-radius a-circle) (solid-disk-color a-circle) )) ;; The structure represents a line ;; start is a position (posn structure) that is the beginning of a line ;; end is a position that is the end of a line, and ;; color is a symbol representing a color (define-struct solid-line (start end color)) ;; draw-a-solid-line: solid-line -> true ;; the function draws a solid line structure as a solid line ;; and returns true (define (draw-a-solid-line a-solid-line) (draw-solid-line (solid-line-start a-solid-line) (solid-line-end a-solid-line) (solid-line-color a-solid-line))) ;; clear-a-solid-line: solid-line -> true ;; the function clears a solid line and returns true (define (clear-a-solid-line a-solid-line) (clear-solid-line (solid-line-start a-solid-line) (solid-line-end a-solid-line))) ;; move-solid-line: solid-line number number -> solid-line ;; the function creates a new solid line from a given one ;; with coordinates shifted by x-shift and y-shift (define (move-solid-line a-solid-line x-shift y-shift) (make-solid-line (make-posn (+ (posn-x (solid-line-start a-solid-line)) x-shift) (+ (posn-y (solid-line-start a-solid-line)) y-shift)) (make-posn (+ (posn-x (solid-line-end a-solid-line)) x-shift) (+ (posn-y (solid-line-end a-solid-line)) y-shift)) (solid-line-color a-solid-line) )) ;; The structure represents a rectangle ;; left-upper is the position (posn structure) of its ;; left upper corner, height and width are its height and ;; width (non-negative numbers), and ;; color is a symbol representing a color (define-struct rectangle (left-upper height width color)) ;; draw-a-rectangle: rectangle -> true ;; the function draws a rectangle structure as a solid rectangle ;; and returns true (define (draw-a-rectangle a-rectangle) (draw-solid-rect (rectangle-left-upper a-rectangle) (rectangle-height a-rectangle) (rectangle-width a-rectangle) (rectangle-color a-rectangle)) ) ;; clear-a-rectangle: rectangle -> true ;; the function clears a rectangle structure ;; and returns true (define (clear-a-rectangle a-rectangle) (clear-solid-rect (rectangle-left-upper a-rectangle) (rectangle-height a-rectangle) (rectangle-width a-rectangle) )) ;; move-rectangle: rectangle number number -> rectangle ;; the function creates a new rectangle from a given one ;; with coordinates shifted by x-shift and y-shift (define (move-rectangle a-rect x-shift y-shift) (make-rectangle (make-posn (+ (posn-x (rectangle-left-upper a-rect)) x-shift) (+ (posn-y (rectangle-left-upper a-rect)) y-shift)) (rectangle-height a-rect) (rectangle-width a-rect) (rectangle-color a-rect) )) ;; draw-shapes: a list of shapes -> boolean ;; the function takes a list of shapes (circles, lines, rectangles) ;; and draws them on the canvas in order (define (draw-shapes alosh) (cond [(empty? alosh) true] [(circle? (first alosh)) (and (draw-a-circle (first alosh)) (draw-shapes (rest alosh)))] [(solid-line? (first alosh)) (and (draw-a-solid-line (first alosh)) (draw-shapes (rest alosh)))] [(rectangle? (first alosh)) (and (draw-a-rectangle (first alosh)) (draw-shapes (rest alosh)))] [(solid-disk? (first alosh)) (and (draw-a-solid-disk (first alosh)) (draw-shapes (rest alosh)))] )) ;; clear-shapes: a list of shapes -> boolean ;; the function takes a list of shapes (circles, lines, rectangles) ;; and clears them on the canvas in order (define (clear-shapes alosh) (cond [(empty? alosh) true] [(circle? (first alosh)) (and (clear-a-circle (first alosh)) (clear-shapes (rest alosh)))] [(solid-line? (first alosh)) (and (clear-a-solid-line (first alosh)) (clear-shapes (rest alosh)))] [(rectangle? (first alosh)) (and (clear-a-rectangle (first alosh)) (clear-shapes (rest alosh)))] [(solid-disk? (first alosh)) (and (clear-a-solid-disk (first alosh)) (clear-shapes (rest alosh)))] )) ;; move-shapes: a list of shapes alon alon -> a list of shapes ;; the function creates a list of shapes (circles, lines, rectangles) ;; from the given list by shifting the coordinates ;; by x-shift and y-shift. (define (move-shapes alosh x-shift y-shift) (cond [(empty? alosh) empty] [(circle? (first alosh)) (cons (move-circle (first alosh) x-shift y-shift) (move-shapes (rest alosh) x-shift y-shift))] [(solid-line? (first alosh)) (cons (move-solid-line (first alosh) x-shift y-shift) (move-shapes (rest alosh) x-shift y-shift))] [(rectangle? (first alosh)) (cons (move-rectangle (first alosh) x-shift y-shift) (move-shapes (rest alosh) x-shift y-shift))] [(solid-disk? (first alosh)) (cons (move-solid-disk (first alosh) x-shift y-shift) (move-shapes (rest alosh) x-shift y-shift))] )) ;; multi-move-shapes: a list of shapes, a list of numbers, a list of numbers -> a list of lists of shapes ;; given a list of shapes and a list of x coordinate shifts and a list of y ;; coordinate shifts, creates a list of lists of shapes: for each pair x-shift, ;; y-shift it creates a shift of the original list of shapes by the ;; x-shift in x coordinate and y-shift in y-coordinate ;; If the length of alox is not the same as the length of aloy ;; then the shorter of the two is used. (define (multi-move-shapes alosh alox aloy) (cond [(or (empty? alox) (empty? aloy)) empty] [else (cons (move-shapes alosh (first alox) (first aloy)) (multi-move-shapes alosh (rest alox) (rest aloy)))] )) ;; draw-and-clear-all-shapes : a list of lists of shapes, number -> true ;; delay1 is a number of seconds that the function waits before it is cleared. ;; draw a list of lists of shapes (define (draw-and-clear-all-shapes alolsh delay1) (cond [(empty? alolsh) true] [else (and (draw-shapes (first alolsh)) (sleep-for-a-while delay1) (clear-shapes (first alolsh)) (draw-and-clear-all-shapes (rest alolsh) delay1))] )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Defining our person, weapons, and monsters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Defining a person (define person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) ;; Draws a person on the canvas during the game (draw-shapes person1) ;; Defining a pointy stick (define pointy-stick1 (list (make-rectangle (make-posn 30 50) 100 3 'brown))) ;; Defining a light saber (define light-saber1 (list (make-rectangle (make-posn 30 66) 100 3 'blue) (make-rectangle (make-posn 30 65) 20 5 'black) (make-rectangle (make-posn 50 63) 4 9 'black))) ;; Defining a wand (define magic-wand1 (list (make-rectangle (make-posn 30 86) 72 3 'brown) (make-circle (make-posn 115 87) 13 'green) (make-circle (make-posn 115 87) 10 'blue) (make-circle (make-posn 115 87) 7 'orange) (make-circle (make-posn 115 87) 4 'green))) ;; Defining ghosts (define ghost1 (list (make-solid-disk (make-posn 500 200) 40 'black) (make-rectangle (make-posn 460 200) 80 200 'black) (make-solid-disk (make-posn 485 185) 4 'red) (make-solid-disk (make-posn 515 185) 4 'red))) (define ghost2 (list (make-solid-disk (make-posn 500 200) 40 'green) (make-rectangle (make-posn 460 200) 80 200 'green) (make-solid-disk (make-posn 485 185) 4 'orange) (make-solid-disk (make-posn 515 185) 4 'orange))) (define ghost3 (list (make-solid-disk (make-posn 500 200) 30 'cyan) (make-rectangle (make-posn 460 200) 80 150 'cyan) (make-solid-disk (make-posn 490 185) 4 'purple) (make-solid-disk (make-posn 510 185) 4 'purple))) (define ghost4 (list (make-solid-disk (make-posn 500 200) 30 'blue) (make-rectangle (make-posn 460 200) 80 150 'blue) (make-solid-disk (make-posn 490 185) 4 'yellow) (make-solid-disk (make-posn 510 185) 4 'yellow))) (define ghost5 (list (make-solid-disk (make-posn 500 200) 30 'gray) (make-rectangle (make-posn 471 188) 60 175 'gray) (make-solid-disk (make-posn 490 185) 3 'green) (make-solid-disk (make-posn 510 185) 3 'green))) ;; Defining a key (define key (list (make-circle (make-posn 365 75) 15 'orange) (make-rectangle (make-posn 380 73) 75 4 'orange) (make-rectangle (make-posn 445 70) 10 3 'orange) (make-rectangle (make-posn 435 70) 5 3 'orange))) ;; Defining marbles (define marbles (list (make-solid-disk (make-posn 290 20) 7 'red) (make-solid-disk (make-posn 270 60) 8 'cyan) (make-solid-disk (make-posn 280 40) 6 'blue) (make-solid-disk (make-posn 275 80) 8 'green) (make-solid-disk (make-posn 300 65) 7 'orange) (make-solid-disk (make-posn 310 30) 6 'purple) )) ;; Defining a shield (define shield (list (make-solid-line (make-posn 600 10) (make-posn 630 60) 'blue) (make-solid-line (make-posn 630 60) (make-posn 600 110) 'blue) (make-solid-line (make-posn 600 110) (make-posn 570 60) 'blue) (make-solid-line (make-posn 570 60) (make-posn 600 10) 'blue) )) ;; Defining a door (define door (list (make-rectangle (make-posn 400 130) 200 320 'brown) (make-solid-disk (make-posn 550 300) 8 'gray) )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Drawing the weapon that the user selects. (define draw-weapon (cond [(string=? message (string-append character-name " now has a " "pointy stick")) (draw-shapes pointy-stick1)] [(string=? message (string-append character-name " now has a " "light saber")) (draw-shapes light-saber1)] [(string=? message (string-append character-name " now has a " "magic wand")) (draw-shapes magic-wand1)] )) (sleep-for-a-while 3) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Adding and removing things from the inventory ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Defining inventory (define inventory (list "run away like a coward")) ;; add-to-inventory : string -> void ;; We did not test this function in this window because it would interfere with the game. ;; Modified from the add-to-address-book function in lab 9. ;; Examples: ;; (add-to-inventory "pointy stick") -> void ;; This would add pointy stick to our existing inventory. (define (add-to-inventory weapon) (set! inventory (cons weapon inventory))) ;; Purpose: Adding weapons to the inventory (define updated-inventory (cond [(string=? message (string-append character-name " now has a " "pointy stick")) (add-to-inventory "pointy stick")] [(string=? message (string-append character-name " now has a " "light saber")) (add-to-inventory "light saber")] [(string=? message (string-append character-name " now has a " "magic wand")) (add-to-inventory "magic wand")] )) ;; remove-from-inventory : string -> void ;; Purpose: to remove an item from an inventory. ;; We did not test this function in this window because it would interfere with the game. ;; Modified from the remove1 function in lab 9. ;; Examples: (remove-from-inventory "run away like a coward") -> void (define (remove-from-inventory item) (cond [(empty? inventory) empty] [(string=? item (first inventory)) (set! inventory (rest inventory))] [else (set! inventory (new-inventory item inventory))] )) ;; new-inventory : string, a list of lists -> a list of lists ;; Purpose: To create an inventory by removing a specific item. ;; We did not test this function in this window because it would interfere with the game. ;; Modified from the new-address-book function in the class examples. ;; Examples: (new-inventory "magic wand" inventory) -> (list "pointy stick") (define (new-inventory item a-list) (cond [(empty? a-list) empty] [(string=? item (first a-list)) (rest a-list)] [else (cons (first a-list) (new-inventory item (rest a-list)))])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; clears the string that says: " now has a " (clear-solid-string (make-posn 20 20) message) ;; Welcome message (draw-solid-string (make-posn 250 200) "Welcome, poor unfortunate soul!") (draw-solid-string (make-posn 250 215) "The only way to escape is to plunge") (draw-solid-string (make-posn 250 230) "into the deep deep darkness of this") (draw-solid-string (make-posn 250 245) "frightening castle!") (sleep-for-a-while 9) ;; Clears the welcome message (clear-solid-string (make-posn 250 200) "Welcome, poor unfortunate soul!") (clear-solid-string (make-posn 250 215) "The only way to escape is to plunge") (clear-solid-string (make-posn 250 230) "into the deep deep darkness of this") (clear-solid-string (make-posn 250 245) "frightening castle!") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; A list of possible directions that the user can go (define direction-choices (list "left" "right" "up")) ;; calling "get-choice" to get the user's choice, adding the choice to ;; the list of directions. direction-list is the new list (define direction-list (cons (get-choice "You are lost. Which way will you go? Choose wisely!" direction-choices) empty)) (sleep-for-a-while 3) ;; using string-append to combine strings. In this case the strings are: ;; the character name, " has chosen to go ", and the newly-added item in the ;; directions list (define message1 (string-append character-name " has chosen to go " (first direction-list))) ;; a list of all possible outcomes that might appear after the user chooses a direction. (define outcomes (list ghost1 ghost2 ghost3 ghost4 ghost5)) ;; nth: a-list number -> number ;; Purpose: to return an element n from a list ;; Examples: (nth (list 1 2 3) 2) -> 3 ;; (nth (list 2 3 5 7) 2) -> 5 ;; (nth (list 4 5) 0) -> 4 (define (nth a-list n) (cond [(= n 0) (first a-list)] [else (nth (rest a-list) (- n 1))] )) ;; Test: (check-expect (nth (list 1 2 3) 2) 3) (check-expect (nth (list 2 3 5 7) 2) 5) (check-expect (nth (list 4 5) 0) 4) ;; After a user chooses a direction, a random monster will appear. (define random-outcome (cond [(or (string=? message1 (string-append character-name " has chosen to go " "left")) (string=? message1 (string-append character-name " has chosen to go " "right")) (string=? message1 (string-append character-name " has chosen to go " "up"))) (draw-shapes (nth outcomes (random (length outcomes))))])) (sleep-for-a-while 1) ;; calling "get-choice" to get the user's choice. (define inventory-list (cons (get-choice "Oh No! A frightening monster! Will you run away or pick a weapon to fight?" inventory) empty)) (sleep-for-a-while 4) ;; using string-append to combine strings. In this case the strings are: ;; the character name, " will employ ", and the newly-added item in the ;; inventory list (define message2 (string-append character-name " will employ " (first inventory-list))) ;; draws a string on the canvas at the given position (draw-solid-string (make-posn 20 20) message2) (sleep-for-a-while 2) ;; clears the string that says: " will employ " (clear-solid-string (make-posn 20 20) message2) ;; This will create a list of shapes that will be drawn in our fight? function. (define person2 (multi-move-shapes person1 (list 50 50 50) (list 0 0 0))) ;; Deciding if the user wants to fight or run away. (define fight? (cond [(string=? message2 (string-append character-name " will employ " "pointy stick")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 100 3 'brown)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1))] [(string=? message2 (string-append character-name " will employ " "light saber")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 100 3 'blue) (make-rectangle (make-posn 140 339) 20 5 'black) (make-rectangle (make-posn 160 337) 4 9 'black)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1))] [(string=? message2 (string-append character-name " will employ " "magic wand")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 72 3 'brown) (make-circle (make-posn 225 341) 13 'green) (make-circle (make-posn 225 341) 10 'blue) (make-circle (make-posn 225 341) 7 'orange) (make-circle (make-posn 225 341) 4 'green)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1))] [(string=? message2 (string-append character-name " will employ " "run away like a coward")) (and (draw-solid-string (make-posn 280 230) "Run, coward run!") (draw-solid-rect (make-posn 390 160) 365 240 'white) (sleep-for-a-while 2) (clear-solid-string (make-posn 280 230) "Run, coward run!") (draw-solid-string (make-posn 250 200) "You run away and find yourself in a new room") (sleep-for-a-while 3) (clear-solid-string (make-posn 250 200) "You run away and find yourself in a new room"))] )) (sleep-for-a-while 2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; First round ends. Second round starts. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; A message that says that the user picks a box. (draw-solid-string (make-posn 300 250) "A room full of boxes! You pick one before hurrying on.") (sleep-for-a-while 3) ;; The message is cleared. (clear-solid-string (make-posn 300 250) "A room full of boxes! You pick one before hurrying on.") ;; defining boxes of weapons or treasures that the user can obtain. ;; A list of possible boxes that the user can pick (define box-choices (list "box 1" "box 2" "box 3")) ;; calling "get-choice" to get the user's choice. (define box-list (cons (get-choice "Which box do you want to open?" box-choices) empty)) (sleep-for-a-while 4) ;; using string-append to combine strings. In this case the strings are: ;; the character name, " has chosen to open ", and the newly-added item in the ;; box list (define message3 (string-append character-name " has chosen to open " (first box-list))) ;; Drawing the things that are in the boxes (define draw-weapons2 (cond [(string=? message3 (string-append character-name " has chosen to open " "box 1")) (and (draw-shapes key) (draw-solid-string (make-posn 250 200) "You found a key!") (sleep-for-a-while 2) (clear-solid-string (make-posn 250 200) "You found a key!"))] [(string=? message3 (string-append character-name " has chosen to open " "box 2")) (and (draw-shapes marbles) (draw-solid-string (make-posn 250 200) "You found some marbles in the box.") (sleep-for-a-while 2) (clear-solid-string (make-posn 250 200) "You found some marbles in the box."))] [(string=? message3 (string-append character-name " has chosen to open " "box 3")) (and (draw-shapes shield) (draw-solid-string (make-posn 250 200) "You found a shield in the box.") (sleep-for-a-while 2) (clear-solid-string (make-posn 250 200) "You found a shield in the box."))] )) (sleep-for-a-while 2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Adding more weapons to the inventory (define updated-inventory1 (cond [(string=? message3 (string-append character-name " has chosen to open " "box 1")) (add-to-inventory "key")] [(string=? message3 (string-append character-name " has chosen to open " "box 2")) (add-to-inventory "marbles")] [(string=? message3 (string-append character-name " has chosen to open " "box 3")) (add-to-inventory "shield")] )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; calling "get-choice" to get the user's choice, adding the choice to ;; the list of directions. direction-list2 is the new list (define direction-list2 (cons (get-choice "Don't give up yet! Which way will you go now?" direction-choices) empty)) (sleep-for-a-while 3) ;; After a user chooses a direction, a random monster will appear. (define random-outcome2 (cond [(or (string=? message1 (string-append character-name " has chosen to go " "left")) (string=? message1 (string-append character-name " has chosen to go " "right")) (string=? message1 (string-append character-name " has chosen to go " "up"))) (draw-shapes (nth outcomes (random (length outcomes))))])) (sleep-for-a-while 1) ;; calling "get-choice" to get the user's choice. (define inventory-list1 (cons (get-choice "It's another monster! Will you run away or pick a weapon to fight?" inventory) empty)) (sleep-for-a-while 3) ;; using string-append to combine strings. In this case the strings are: ;; the character name, " will employ ", and the newly-added item in the ;; inventory list (define message5 (string-append character-name " will employ " (first inventory-list1))) ;; draws a string on the canvas at the given position (draw-solid-string (make-posn 20 20) message5) (sleep-for-a-while 3) ;; clears the string that says: " will employ " (clear-solid-string (make-posn 20 20) message5) ;; This will create a list of shapes that will be drawn in our fight1? function. (define marbles2 (multi-move-shapes marbles (list 50 50 50) (list 0 0 0))) ;; Deciding if the user wants to fight or run away. (define fight1? (cond [(string=? message5 (string-append character-name " will employ " "pointy stick")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 100 3 'brown)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1))] [(string=? message5 (string-append character-name " will employ " "light saber")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 100 3 'blue) (make-rectangle (make-posn 140 339) 20 5 'black) (make-rectangle (make-posn 160 337) 4 9 'black)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1))] [(string=? message5 (string-append character-name " will employ " "magic wand")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 72 3 'brown) (make-circle (make-posn 225 341) 13 'green) (make-circle (make-posn 225 341) 10 'blue) (make-circle (make-posn 225 341) 7 'orange) (make-circle (make-posn 225 341) 4 'green)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1))] [(string=? message5 (string-append character-name " will employ " "run away like a coward")) (and (draw-solid-string (make-posn 280 230) "Run, coward run!") (draw-solid-rect (make-posn 390 160) 365 240 'white) (sleep-for-a-while 2) (clear-solid-string (make-posn 280 230) "Run, coward run!") (draw-solid-string (make-posn 250 200) "You run away and find yourself in a new room") (sleep-for-a-while 3) (clear-solid-string (make-posn 250 200) "You run away and find yourself in a new room"))] [(string=? message5 (string-append character-name " will employ " "key")) (and (draw-solid-string (make-posn 230 230) "No good! The key has no effect here") (draw-solid-string (make-posn 230 250) "and you are forced to quickly retreat.") (sleep-for-a-while 4) (draw-solid-rect (make-posn 390 160) 365 240 'white) (clear-solid-string (make-posn 230 230) "No good! The key has no effect here") (clear-solid-string (make-posn 230 250) "and you are forced to quickly retreat."))] [(string=? message5 (string-append character-name " will employ " "marbles")) (begin (set! marbles (list (make-solid-disk (make-posn 160 300) 7 'red) (make-solid-disk (make-posn 140 340) 8 'cyan) (make-solid-disk (make-posn 150 320) 6 'blue) (make-solid-disk (make-posn 145 360) 8 'green) (make-solid-disk (make-posn 170 345) 7 'orange) (make-solid-disk (make-posn 180 310) 6 'purple))) (set! marbles2 (multi-move-shapes marbles (list 50 100 150 200) (list -10 -20 -20 10))) (draw-shapes marbles) (sleep-for-a-while .5) (clear-shapes marbles) (draw-and-clear-all-shapes marbles2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (draw-shapes person1)) ] [(string=? message5 (string-append character-name " will employ " "shield")) (begin (set! person1 (append person1 (list (make-solid-line (make-posn 170 290) (make-posn 200 340) 'blue) (make-solid-line (make-posn 200 340) (make-posn 170 390) 'blue) (make-solid-line (make-posn 170 390) (make-posn 140 340) 'blue) (make-solid-line (make-posn 140 340) (make-posn 170 290) 'blue) ))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1))] )) (sleep-for-a-while 2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Second round ends. Third round starts. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; A message that says that the user picks a box. (draw-solid-string (make-posn 290 250) "Another room full of boxes! Pick one that you didn't pick before.") (sleep-for-a-while 4) ;; The message is cleared. (clear-solid-string (make-posn 290 250) "Another room full of boxes! Pick one that you didn't pick before.") ;; calling "get-choice" to get the user's choice. (define box-list2 (cons (get-choice "Which box do you want to open?" box-choices) empty)) (sleep-for-a-while 3) ;; using string-append to combine strings. In this case the strings are: ;; the character name, " has chosen to open ", and the newly-added item in the ;; box list (define message6 (string-append character-name " has chosen to open " (first box-list2))) ;; Drawing the things that are in the boxes (define draw-weapons3 (cond [(string=? message6 (string-append character-name " has chosen to open " "box 1")) (and (draw-shapes key) (draw-solid-string (make-posn 250 200) "You found a key!") (sleep-for-a-while 2) (clear-solid-string (make-posn 250 200) "You found a key!"))] [(string=? message6 (string-append character-name " has chosen to open " "box 2")) (and (draw-shapes marbles) (draw-solid-string (make-posn 250 200) "You found some marbles in the box.") (sleep-for-a-while 2) (clear-solid-string (make-posn 250 200) "You found some marbles in the box."))] [(string=? message6 (string-append character-name " has chosen to open " "box 3")) (and (draw-shapes shield) (draw-solid-string (make-posn 250 200) "You found a shield in the box.") (sleep-for-a-while 2) (clear-solid-string (make-posn 250 200) "You found a shield in the box."))] )) (sleep-for-a-while 2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Adding more weapons to the inventory (define updated-inventory2 (cond [(string=? message6 (string-append character-name " has chosen to open " "box 1")) (add-to-inventory "key")] [(string=? message6 (string-append character-name " has chosen to open " "box 2")) (add-to-inventory "marbles")] [(string=? message6 (string-append character-name " has chosen to open " "box 3")) (add-to-inventory "shield")] )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; calling "get-choice" to get the user's choice, adding the choice to ;; the list of directions. (define direction-list3 (cons (get-choice "You must be almost there! Which way will you go now?" direction-choices) empty)) (sleep-for-a-while 3) ;; After a user chooses a direction, a random monster will appear. (define random-outcome3 (cond [(or (string=? message1 (string-append character-name " has chosen to go " "left")) (string=? message1 (string-append character-name " has chosen to go " "right")) (string=? message1 (string-append character-name " has chosen to go " "up"))) (draw-shapes (nth outcomes (random (length outcomes))))])) (sleep-for-a-while 1) ;; calling "get-choice" to get the user's choice. (define inventory-list2 (cons (get-choice "Not again! Will you run away or pick a weapon to fight?" inventory) empty)) (sleep-for-a-while 3) ;; using string-append to combine strings. In this case the strings are: ;; the character name, " will employ ", and the newly-added item in the ;; inventory list (define message7 (string-append character-name " will employ " (first inventory-list2))) ;; draws a string on the canvas at the given position (draw-solid-string (make-posn 20 20) message7) (sleep-for-a-while 2) ;; clears the string that says: " will employ " (clear-solid-string (make-posn 20 20) message7) ;; Deciding if the user wants to fight or run away. (define fight2? (cond [(string=? message7 (string-append character-name " will employ " "pointy stick")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 100 3 'brown)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1) (draw-shapes door) (sleep-for-a-while 2))] [(string=? message7 (string-append character-name " will employ " "light saber")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 100 3 'blue) (make-rectangle (make-posn 140 339) 20 5 'black) (make-rectangle (make-posn 160 337) 4 9 'black)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1) (draw-shapes door) (sleep-for-a-while 2))] [(string=? message7 (string-append character-name " will employ " "magic wand")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 72 3 'brown) (make-circle (make-posn 225 341) 13 'green) (make-circle (make-posn 225 341) 10 'blue) (make-circle (make-posn 225 341) 7 'orange) (make-circle (make-posn 225 341) 4 'green)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1) (draw-shapes door) (sleep-for-a-while 2))] [(string=? message7 (string-append character-name " will employ " "run away like a coward")) (and (draw-solid-string (make-posn 280 230) "Run, coward run!") (draw-solid-rect (make-posn 390 160) 365 240 'white) (sleep-for-a-while 2) (clear-solid-string (make-posn 280 230) "Run, coward run!") (draw-shapes door) (sleep-for-a-while 2))] [(string=? message7 (string-append character-name " will employ " "key")) (and (draw-solid-string (make-posn 230 230) "No good! The key has no effect here") (draw-solid-string (make-posn 230 250) "and you are forced to quickly retreat.") (sleep-for-a-while 4) (draw-solid-rect (make-posn 390 160) 365 240 'white) (clear-solid-string (make-posn 230 230) "No good! The key has no effect here") (clear-solid-string (make-posn 230 250) "and you are forced to quickly retreat.") (draw-shapes door) (sleep-for-a-while 2))] [(string=? message7 (string-append character-name " will employ " "marbles")) (begin (set! marbles (list (make-solid-disk (make-posn 160 300) 7 'red) (make-solid-disk (make-posn 140 340) 8 'cyan) (make-solid-disk (make-posn 150 320) 6 'blue) (make-solid-disk (make-posn 145 360) 8 'green) (make-solid-disk (make-posn 170 345) 7 'orange) (make-solid-disk (make-posn 180 310) 6 'purple))) (set! marbles2 (multi-move-shapes marbles (list 50 100 150 200) (list -10 -20 -20 10))) (draw-shapes marbles) (sleep-for-a-while .5) (clear-shapes marbles) (draw-and-clear-all-shapes marbles2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (draw-shapes person1) (draw-shapes door) (sleep-for-a-while 2))] [(string=? message7 (string-append character-name " will employ " "shield")) (begin (set! person1 (append person1 (list (make-solid-line (make-posn 170 290) (make-posn 200 340) 'blue) (make-solid-line (make-posn 200 340) (make-posn 170 390) 'blue) (make-solid-line (make-posn 170 390) (make-posn 140 340) 'blue) (make-solid-line (make-posn 140 340) (make-posn 170 290) 'blue) ))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1) (draw-shapes door) (sleep-for-a-while 2))] )) (sleep-for-a-while 2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; The final round. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Removing the run away option from the inventory (define no-more-running (remove-from-inventory "run away like a coward")) ;; A list of options for defeating the door. (define final-choices inventory) ;; calling "get-choice" to get the user's choice, adding the choice to ;; the list. (define final-list (cons (get-choice "A door. This must be the exit. Try to get through." final-choices) empty)) (sleep-for-a-while 3) ;; using string-append to combine strings. In this case the strings are: ;; the character name, " will employ ", and the newly-added item in the ;; final list (define message8 (string-append character-name " will employ " (first final-list))) ;; draws a string on the canvas at the given position (draw-solid-string (make-posn 20 20) message8) (sleep-for-a-while 2) ;; clears the string that says: " will employ " (clear-solid-string (make-posn 20 20) message8) ;; Deciding what to use for the door. (define final-action (cond [(string=? message8 (string-append character-name " will employ " "pointy stick")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 100 3 'brown)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1) (draw-shapes door) (sleep-for-a-while 2) (draw-solid-string (make-posn 200 250) "You have failed and will") (draw-solid-string (make-posn 200 270) "forever haunt these halls!!"))] [(string=? message8 (string-append character-name " will employ " "light saber")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 100 3 'blue) (make-rectangle (make-posn 140 339) 20 5 'black) (make-rectangle (make-posn 160 337) 4 9 'black)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1) (draw-shapes door) (sleep-for-a-while 2) (draw-solid-string (make-posn 200 250) "You have failed and will") (draw-solid-string (make-posn 200 270) "forever haunt these halls!!"))] [(string=? message8 (string-append character-name " will employ " "magic wand")) (begin (set! person1 (append person1 (list (make-rectangle (make-posn 140 340) 72 3 'brown) (make-circle (make-posn 225 341) 13 'green) (make-circle (make-posn 225 341) 10 'blue) (make-circle (make-posn 225 341) 7 'orange) (make-circle (make-posn 225 341) 4 'green)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1) (draw-shapes door) (sleep-for-a-while 2) (draw-solid-string (make-posn 200 250) "You have failed and will") (draw-solid-string (make-posn 200 270) "forever haunt these halls!!"))] [(string=? message8 (string-append character-name " will employ " "key")) (begin (set! person1 (append person1 (list (make-circle (make-posn 155 340) 15 'orange) (make-rectangle (make-posn 170 338) 75 4 'orange) (make-rectangle (make-posn 235 335) 10 3 'orange) (make-rectangle (make-posn 225 335) 5 3 'orange)))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 0) 700 500 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1) (draw-solid-rect (make-posn 0 450) 700 50 'green) (sleep-for-a-while 1) (draw-solid-string (make-posn 200 250) "You have escaped! Congratulations on surviving the Amazing Haunted Castle!"))] [(string=? message8 (string-append character-name " will employ " "marbles")) (begin (set! marbles (list (make-solid-disk (make-posn 160 300) 7 'red) (make-solid-disk (make-posn 140 340) 8 'cyan) (make-solid-disk (make-posn 150 320) 6 'blue) (make-solid-disk (make-posn 145 360) 8 'green) (make-solid-disk (make-posn 170 345) 7 'orange) (make-solid-disk (make-posn 180 310) 6 'purple))) (set! marbles2 (multi-move-shapes marbles (list 50 100 150 200) (list -10 -20 -20 10))) (draw-shapes marbles) (sleep-for-a-while .5) (clear-shapes marbles) (draw-and-clear-all-shapes marbles2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (draw-shapes person1) (draw-shapes door) (sleep-for-a-while 2) (draw-solid-string (make-posn 200 250) "You have failed and will") (draw-solid-string (make-posn 200 270) "forever haunt these halls!!"))] [(string=? message8 (string-append character-name " will employ " "shield")) (begin (set! person1 (append person1 (list (make-solid-line (make-posn 170 290) (make-posn 200 340) 'blue) (make-solid-line (make-posn 200 340) (make-posn 170 390) 'blue) (make-solid-line (make-posn 170 390) (make-posn 140 340) 'blue) (make-solid-line (make-posn 140 340) (make-posn 170 290) 'blue) ))) (set! person2 (multi-move-shapes person1 (list 50 100 150 200) (list 0 0 0 0))) (draw-shapes person1) (sleep-for-a-while .5) (clear-shapes person1) (draw-and-clear-all-shapes person2 1) (draw-solid-disk (make-posn 425 290) 150 'red) (sleep-for-a-while 1) (draw-solid-rect (make-posn 0 110) 700 340 'white) (set! person1 (list (make-circle (make-posn 100 200) 40 'black) (make-solid-line (make-posn 100 240) (make-posn 100 360) 'black) (make-solid-line (make-posn 100 360) (make-posn 60 450) 'black) (make-solid-line (make-posn 100 360) (make-posn 140 450) 'black) (make-solid-line (make-posn 100 270) (make-posn 60 340) 'black) (make-solid-line (make-posn 100 270) (make-posn 140 340) 'black))) (draw-shapes person1) (draw-shapes door) (sleep-for-a-while 2) (draw-solid-string (make-posn 200 250) "You have failed and will") (draw-solid-string (make-posn 200 270) "forever haunt these halls!!"))] ))