;; 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 JaredGregNick) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))))) ;; ============== 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)]) ]) )) ;; =========================== do not change anything above this line ============= ;; NOTE: The language is Intermediate Student with lambda ;; =========================== Your work goes here: =============================== (define-struct player (full-health health class attack inventory exp)) ;health of the player, player class, current attack, current inventory, and experience points (define-struct monster (health class attack animation)) ;health of the monster, monster class, its attack, and its animation (define-struct animation (shape-list)) ;animation structure, which contains a list of shapes (define-struct row (start width length number color1 color2)) ;row structure, used to make rows when run through the draw-animation function (define-struct column (start width length number color1 color2)) ;column structure, used to make columns when run through the draw-animation function (define-struct disk (start rad color)) ;disk structure, used to make disks when run through the draw-animation function (define-struct rect (start width height color)) ;rect structure, used to make rectangles when run through the draw-animation function (define-struct line (start end color)) ;line structure, used to make lines when run through the draw-animation function (define-struct circle (start rad color)) ;circle structure, used to make circles when run through the draw-animation function (define-struct brick-lines (posn1 posn2 width color start end)) ;brick-lines structure, used to make a sequence of equal length horizontal lines parallel to one another. (define-struct stairs (posn n width height color dir)) ;stairs structure, used to make a sequence of "stairs" (define-struct pyramid (posn n width height color)) ;pyramid structure, used to make a pyramid, which is a mirrored form of stairs combined ;Level-Up inputs the player structure and a string, and outputs a player structure. (define (level-up player string) (cond ;each possible outcome produces a player structure with the defined alterations [(string=? "Attack + 1" string)(make-player(player-full-health player)(player-full-health player)(player-class player)(+(player-attack player)1)(player-inventory player)(player-exp player))] [(string=? "Hit Points + 5" string)(make-player(+(player-full-health player)5)(+(player-full-health player)5)(player-class player)(player-attack player)(player-inventory player)(player-exp player))] [(string=? "Hi-Potion" string)(make-player(player-full-health player)(player-full-health player)(player-class player)(player-attack player)(cons "Hi-Potion"(player-inventory player))(player-exp player))] [(string=? "Potion" string)(make-player(player-full-health player)(player-full-health player)(player-class player)(player-attack player)(cons "Potion"(player-inventory player))(player-exp player))] [(string=? "Potion x2" string)(make-player(player-full-health player)(player-full-health player)(player-class player)(player-attack player)(list "Potion" "Potion")(player-exp player))] ) ) ; draw-brick-helper inputs two posn, three integers, and a symbol, and outputs a complex animation, when included in a later function. (define (draw-brick-helper posn1 posn2 a color end) (cond [(and (> (posn-x posn1) end) (> (posn-x posn2) end)) true] [else (and (draw-solid-line posn1 posn2 color) (draw-brick-helper (make-posn (+ (posn-x posn1) a) (posn-y posn1)) (make-posn (+ (posn-x posn2) a) (posn-y posn2)) a color end) )] ) ) ; draw-brick-lines inputs two posn, three integers, and a symbol, and outputs a complex animation. (define (draw-brick-lines posn1 posn2 width color start end) (and (draw-brick-helper posn1 posn2 width color end) (draw-solid-line (make-posn start (posn-y posn2)) (make-posn end (posn-y posn2)) color) ) ) ; draw-stairs inputs a posn, three integers, a symbol, and a boolean, and outputs a complex animation. (define (draw-stairs posn n width height color dir) (cond [(= n 0) true] [dir(and (draw-solid-rect posn width (* n height) color) (draw-stairs (make-posn (- (posn-x posn) width) (+ (posn-y posn) height)) (- n 1) width height color dir))] [else (and (draw-solid-rect posn width (* n height) color) (draw-stairs (make-posn (+ (posn-x posn) width) (+ (posn-y posn) height)) (- n 1) width height color dir))] ) ) ; draw-pyramid inputs a posn, three integers, and a symbol, and outputs a complex animation. (define (draw-pyramid posn n width height color) (cond [(= n 0) true] [else (and (draw-solid-rect posn width (* n height) color) (draw-pyramid (make-posn (- (posn-x posn) width) (+ (posn-y posn) height)) (- n 1) width height color)(draw-pyramid (make-posn (+ (posn-x posn) width) (+ (posn-y posn) height)) (- n 1) width height color))] ) ) ; party-hat inputs two symbols, and outputs a complex animation using those symbols (define (party-hat color bobble) ;This function allows easy drawing of bear hats (make-animation (list (make-pyramid (make-posn 150 110) 8 3 10 color) (make-disk (make-posn 172 174) 14 bobble) (make-disk (make-posn 151 110) 10 bobble) ) ) ) (define skull (make-animation (list (make-rect (make-posn 0 0) 300 300 'red) (make-disk (make-posn 151 75) 80 'white) (make-rect (make-posn 0 100) 300 140 'black) (make-rect (make-posn 77 100) 149 40 'white) (make-disk (make-posn 150 115) 20 'black) (make-disk (make-posn 170 95) 20 'white) (make-disk (make-posn 130 95) 20 'white) (make-disk (make-posn 108 72) 20 'black) (make-disk (make-posn 192 72) 20 'black) (make-rect (make-posn 130 130) 40 10 'white) (make-column (make-posn 77 140) 148 20 37 'white 'clear) ) ) ) (define bear (make-monster 6 "Bear" 1 (make-animation(list (make-rect (make-posn 10 285) 40 15 'brown)(make-rect (make-posn 50 285) 6 3 'black) (make-rect (make-posn 50 295) 6 3 'black)(make-rect (make-posn 50 290) 6 3 'black) (make-rect (make-posn 10 250) 20 35 'brown)(make-rect (make-posn 10 247) 25 3 'brown) (make-rect (make-posn 10 242) 30 5 'brown)(make-rect (make-posn 10 237) 35 5 'brown) (make-rect (make-posn 10 162) 45 75 'brown)(make-rect (make-posn 10 157) 35 5 'brown) (make-rect (make-posn 10 152) 30 5 'brown)(make-rect (make-posn 10 142) 17 10 'brown) (make-rect (make-posn 10 112) 40 30 'brown)(make-rect (make-posn 45 117) 7 7 'black) (make-rect (make-posn 30 132) 20 10 'red)(make-rect (make-posn 10 102) 12 10 'brown) (make-rect (make-posn 15 105) 7 7 'red)(make-rect (make-posn 20 112) 7 7 'black) (make-rect (make-posn 55 162) 20 15 'brown)(make-rect (make-posn 75 162) 6 3 'black) (make-rect (make-posn 75 167) 6 3 'black)(make-rect (make-posn 75 172) 6 3 'black) )))) (define clown (make-monster 10 "Clown" 2 (make-animation (list (make-rect (make-posn 17 280) 65 25 'red)(make-rect (make-posn 17 210) 30 70 'blue) (make-rect (make-posn 10 120) 50 90 'yellow) (make-line (make-posn 0 120) (make-posn 70 120) 'black) (make-line (make-posn 0 100) (make-posn 70 100) 'black) (make-line (make-posn 0 100) (make-posn 0 120) 'black) (make-line (make-posn 70 100) (make-posn 70 120) 'black) (make-line (make-posn 0 100) (make-posn 10 120) 'black) (make-line (make-posn 20 100) (make-posn 10 120) 'black) (make-line (make-posn 20 100) (make-posn 30 120) 'black) (make-line (make-posn 40 100) (make-posn 30 120) 'black) (make-line (make-posn 40 100) (make-posn 50 120) 'black) (make-line (make-posn 60 100) (make-posn 50 120) 'black) (make-line (make-posn 60 100) (make-posn 70 120) 'black) (make-circle (make-posn 35 70) 30 'black)(make-disk (make-posn 35 70) 28 'white) (make-disk (make-posn 60 75) 10 'red)(make-disk (make-posn 12 62) 10 'red) (make-disk (make-posn 15 55) 10 'red)(make-disk (make-posn 18 50) 10 'red) (make-disk (make-posn 25 40) 10 'red)(make-disk (make-posn 35 40) 10 'red) (make-disk (make-posn 42 45) 10 'red)(make-disk (make-posn 15 40) 10 'red) (make-disk (make-posn 12 50) 10 'red)(make-disk (make-posn 12 30) 10 'red) (make-disk (make-posn 75 290) 10 'red) )))) (define mime (make-monster 15 "Mime" 2 (make-animation(list (make-rect (make-posn 17 280) 50 15 'black) (make-line (make-posn 17 220)(make-posn 17 280)'black) (make-line (make-posn 43 220)(make-posn 43 280)'black) (make-line (make-posn 43 220)(make-posn 17 220)'black) (make-rect (make-posn 18 221) 25 59 'white) (make-line (make-posn 17 220)(make-posn 17 280)'black) (make-line (make-posn 17 220)(make-posn 63 220)'black) (make-line (make-posn 17 140)(make-posn 63 140)'black) (make-line (make-posn 17 140)(make-posn 17 220)'black) (make-line (make-posn 63 140)(make-posn 63 220)'black) (make-rect (make-posn 17 200) 46 20'black)(make-rect (make-posn 18 180) 45 20 'white) (make-rect (make-posn 17 160) 46 20'black)(make-disk (make-posn 40 115) 25'black) (make-disk (make-posn 40 115) 24 'white)(make-rect(make-posn 17 90) 45 16'black) (make-disk (make-posn 62 98) 8'black)(make-disk (make-posn 17 98) 8'black) (make-rect (make-posn 39 81) 5 15'black) )))) (define pope-hat (make-monster 20 "Thing" 3(make-animation (list (make-circle (make-posn 150 100) 30 'yellow) (make-rect (make-posn 120 100) 60 40 'white) (make-line (make-posn 180 100) (make-posn 165 170) 'yellow) (make-line (make-posn 120 100) (make-posn 135 170) 'yellow) (make-rect (make-posn 125 169) 50 10 'red)(make-rect (make-posn 146 80) 8 89 'yellow) (make-rect (make-posn 130 100) 40 8 'yellow) )))) ;; This is an example of one round of the accummulation stage of a game. ;; Your game will have multiple rounds. ;; the initial list of weapons: ;;;;;;; ;(define starting-weapons (list "cane")) ;; the first list of choices: ;;;;;;; ;(define weapon-choices1 (list "frying pan" "light saber")) ;weapon brainstorm: fruit salad, balloon (colors affect power), lead pipe, ;back story: "for some reason". ;Character choices: Clown, Mime, Bear. ;; calling "get-choice" to get the user's choice, adding the choice to ;; the list of weapons. weapon-list1 is the new list ;;;;;;; ;(define weapon-list1 (cons ; (get-choice "Choose your weapon" weapon-choices1) ; starting-weapons)) ;; calling a get-answer function to let the user type in their name ;; 5 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?" 5)) ;; 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-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 20 20) message) ;(sleep-for-a-while 3) ; draw-stripe-columns inputs posn, three integers, and two symbols, and outputs a complex animation. (define (draw-stripe-columns start width length number color1 color2) ;draw-stripe-columns makes a row of columns of equal width and length all along the defined rectangle of given width and length. It produces the number of columns as defined when the function is called. Be careful to enter a width that can be properly divided by the number of columns, as the draw-solid-rect function requires integers. (local ((define each-width (/ width number))) (cond [(= 1 number) (draw-solid-rect start each-width length color1)] [(symbol=? color1 'clear) (draw-stripe-columns (make-posn (+ each-width (posn-x start)) (posn-y start)) (- width each-width) length (- number 1) color2 color1)] ;This segment allows that if a column color is defined as clear, it is skipped, meaning the color beneath is shown instead. [(draw-solid-rect start each-width length color1) (draw-stripe-columns (make-posn (+ each-width (posn-x start)) (posn-y start)) (- width each-width) length (- number 1) color2 color1)] ) ) ) ; draw-stripes inputs posn, three integers, and two symbols, and outputs a complex animation. (define (draw-stripe-rows start width length number color1 color2) ;draw-stripe-rows makes a column of rows of equal width and length all along the defined rectangle of given width and length. It produces the number of rows as defined when the function is called. Be careful to enter a length that can be properly divided by the number of rows, as the draw-solid-rect function requires integers. (local ((define each-length (/ length number))) (cond [(= 1 number) (draw-solid-rect start width each-length color1)] [(symbol=? color1 'clear) (draw-stripe-rows (make-posn (posn-x start)(+ each-length (posn-y start))) width (- length each-length) (- number 1) color2 color1)] ;This segment allows that if a column color is defined as clear, it is skipped, meaning the color beneath is shown instead. [(draw-solid-rect start width each-length color1) (draw-stripe-rows (make-posn (posn-x start)(+ each-length (posn-y start))) width (- length each-length) (- number 1) color2 color1)] ) ) ) ;; clear the string ;(clear-solid-string (make-posn 20 20) message) ; died function inputs nothing, and outputs an appended string to describe the player upon defeat. (define (died x) ;defines the defeat message (draw-solid-string (make-posn 60 260) (string-append name ", The "class" Has Died")) ) ; draw-animation, a major core function, inputs an animation, which is a list of objects, and draws them, in order. (define (draw-animation animation) (cond [(empty? (animation-shape-list animation)) true] [else (local ((define animation2 (make-animation (rest(animation-shape-list animation))))(define next (first (animation-shape-list animation)))) (cond [(disk? next) (and(draw-solid-disk (disk-start next) (disk-rad next) (disk-color next))(draw-animation animation2))] [(circle? next) (and(draw-circle (circle-start next) (circle-rad next) (circle-color next))(draw-animation animation2))] [(rect? next) (and(draw-solid-rect (rect-start next) (rect-width next) (rect-height next) (rect-color next))(draw-animation animation2))] [(column? next) (and(draw-stripe-columns (column-start next) (column-width next) (column-length next) (column-number next) (column-color1 next) (column-color2 next))(draw-animation animation2))] [(row? next) (and(draw-stripe-rows (row-start next) (row-width next) (row-length next) (row-number next) (row-color1 next) (row-color2 next))(draw-animation animation2))] [(stairs? next) (and(draw-stairs (stairs-posn next)(stairs-n next)(stairs-width next)(stairs-height next)(stairs-color next)(stairs-dir next))(draw-animation animation2))] [(pyramid? next) (and(draw-pyramid (pyramid-posn next)(pyramid-n next)(pyramid-width next)(pyramid-height next)(pyramid-color next))(draw-animation animation2))] [(brick-lines? next) (and(draw-brick-lines (brick-lines-posn1 next)(brick-lines-posn2 next)(brick-lines-width next)(brick-lines-color next)(brick-lines-start next) (brick-lines-end next))(draw-animation animation2))] [(line? next) (and(draw-solid-line (line-start next) (line-end next) (line-color next))(draw-animation animation2))] ) )] ) ) ; defines the animation jaw-up into a single variable (define jaw-up (make-animation(list(make-rect (make-posn 82 160) 140 10 'white)(make-column (make-posn 82 140) 140 20 35 'white 'clear)))) ; defines the animation jaw-down into a single variable (define jaw-down (make-animation(list(make-rect (make-posn 82 170) 140 10 'white)(make-column (make-posn 82 150) 140 20 35 'white 'clear)))) (define jaw-x (make-animation(list(make-rect (make-posn 82 180) 140 10 'white)(make-column (make-posn 82 160) 140 20 35 'white 'clear)))) ;makes the seperate settings for each possible jaw position to simplify code. It inputs a string that it uses to decide betweeen up and down animations (define (draw-skull up-down) (and (draw-animation skull) (died 0) (cond [(symbol=? 'up up-down) (draw-animation jaw-up)] [(symbol=? 'down up-down) (draw-animation jaw-down)] ;This condition determines if the skull's "mouth" is open or closed. [else (draw-animation jaw-x)] )) ) ; game-over inputs player, and outputs the death animation, along with the cease and desist for the game code. (define (game-over x) (local ((define (skull y) (and (draw-skull y)(sleep-for-a-while .5)))) ;defines the function game-over to display the skull and the defeat message (cond [(and (skull 'up) (skull 'down) (skull 'x) (skull 'down) (skull 'up) (skull 'down) (skull 'x) (skull 'down) (skull 'up) ) (make-player(player-full-health x)(player-full-health x)(player-class x)(player-attack x)(player-inventory x)500)] )) ) ; draw-class inputs a string, and outputs a series of shapes, made to look like the character class. (define (draw-class x) (draw-animation ( cond [(string=? class "Mime") (monster-animation mime)] [(string=? class "Clown") (monster-animation clown)] [else (monster-animation bear)] ) ) ) ; draw-room inputs a sequence of symbols, and outputs a series of shapes in the colors input, made to resemble a room. (define (draw-room ceiling floor bdrop stairs brick1 brick2)(draw-animation(make-animation(list (make-rect (make-posn 0 0) 300 100 ceiling) (make-brick-lines (make-posn 20 0) (make-posn 20 10) 20 brick1 0 300) (make-brick-lines (make-posn 10 10) (make-posn 10 20) 20 brick1 0 300) (make-brick-lines (make-posn 20 20) (make-posn 20 30) 20 brick1 0 300) (make-brick-lines (make-posn 10 30) (make-posn 10 40) 20 brick1 0 300) (make-brick-lines (make-posn 20 40) (make-posn 20 50) 20 brick1 0 300) (make-brick-lines (make-posn 10 50) (make-posn 10 60) 20 brick1 0 300) (make-brick-lines (make-posn 20 60) (make-posn 20 70) 20 brick1 0 300) (make-brick-lines (make-posn 10 70) (make-posn 10 80) 20 brick1 0 300) (make-brick-lines (make-posn 20 80) (make-posn 20 90) 20 brick1 0 300) (make-brick-lines (make-posn 10 90) (make-posn 10 99) 20 brick1 0 300) (make-rect (make-posn 0 200) 300 100 floor) (make-brick-lines (make-posn 20 200) (make-posn 20 200) 20 brick2 0 300) (make-rect (make-posn 0 100) 300 100 bdrop) (make-stairs (make-posn 0 100) 10 5 10 stairs false) (make-brick-lines (make-posn 20 200) (make-posn 20 210) 20 brick2 0 300) (make-brick-lines (make-posn 10 210) (make-posn 10 220) 20 brick2 0 300) (make-brick-lines (make-posn 20 220) (make-posn 20 230) 20 brick2 0 300) (make-brick-lines (make-posn 10 230) (make-posn 10 240) 20 brick2 0 300) (make-brick-lines (make-posn 20 240) (make-posn 20 250) 20 brick2 0 300) (make-brick-lines (make-posn 10 250) (make-posn 10 260) 20 brick2 0 300) (make-brick-lines (make-posn 20 260) (make-posn 20 270) 20 brick2 0 300) (make-brick-lines (make-posn 10 270) (make-posn 10 280) 20 brick2 0 300) (make-brick-lines (make-posn 20 280) (make-posn 20 290) 20 brick2 0 300) (make-brick-lines (make-posn 10 290) (make-posn 10 300) 20 brick2 0 300) (make-stairs (make-posn 295 100) 10 5 10 stairs true) )))) ; define wait-for-it, this function does not input anything, and exports a string reading "click screen to continue", and has the user click the screen to continue. (define (wait-for-it x) (and(draw-solid-string (make-posn 70 280) "click screen to continue") (posn?(wait-for-mouse-click)))) ; give-message inputs 3 strings, and outputs a blank screen that displays the three strings, and a message at the bottom asking the user to click the screen to continue. (define (give-message x y z) (and (draw-solid-rect (make-posn 0 0) 300 300 'white) (draw-solid-string (make-posn 0 80) x)(draw-solid-string (make-posn 0 100) y)(draw-solid-string (make-posn 0 120) z) (wait-for-it x) )) ; one-message inputs a single string, then displays it on a blank screen, waiting for the player to respond (define (one-message x) (and (draw-solid-rect (make-posn 0 0) 300 300 'white) (draw-solid-string (make-posn 0 80) x) (wait-for-it x) ) ) ;attack inputs a monster structure, and outputs a string and the animation of the monster. (define (attack x) (and (draw-solid-rect (make-posn 0 0) 300 300 'white) (draw-animation (monster-animation x)) (draw-solid-string (make-posn 0 80) (string-append"You Are Attacked By A "(monster-class x))) (wait-for-it x) ) ) ; decision is the fairly elaborate function used in the battle system. It inputs a player structure, a monster structure, and a string for the opening message, and outputs a battle sequence, followed ultimately by the remainder of the player's inventory. (define (decision player monster string) (local( (define (response player monster) ; First is the response local function. It has the enemy monster attack the player, inputing a player and monster structure, and outputing a player and monster structure, and a string put inside a recursion of the decision function. (cond [(and(>=(monster-attack monster)(player-health player))(one-message(string-append "Enemy "(monster-class monster)" Attacks For "(number->string(monster-attack monster))" Damage")))(game-over player)] [(and(empty? (player-inventory player))(one-message (string-append "Enemy "(monster-class monster)" Attacks For "(number->string(monster-attack monster))" Damage")))(decision (make-player (player-full-health player)(-(player-health player)(monster-attack monster))(player-class player)(player-attack player)(player-inventory player)(player-exp player))monster(get-choice (string-append "You Have "(number->string(-(player-health player)(monster-attack monster)))" Out Of "(number->string(player-full-health player))" Hit Points") (list "Fight" "Run")))] [(and(empty? (rest (player-inventory player)))(one-message (string-append "Enemy "(monster-class monster)" Attacks For "(number->string(monster-attack monster))" Damage")))(decision (make-player (player-full-health player)(-(player-health player)(monster-attack monster))(player-class player)(player-attack player)(player-inventory player)(player-exp player))monster(get-choice (string-append "You Have "(number->string(-(player-health player)(monster-attack monster)))" Out Of "(number->string(player-full-health player))" Hit Points") (list "Fight"(first(player-inventory player)))))] [(one-message (string-append "Enemy "(monster-class monster)" Attacks For "(number->string(monster-attack monster))" Damage"))(decision (make-player (player-full-health player)(-(player-health player)(monster-attack monster))(player-class player)(player-attack player)(player-inventory player)(player-exp player))monster(get-choice (string-append "You Have "(number->string(-(player-health player)(monster-attack monster)))" Out Of "(number->string(player-full-health player))" Hit Points") (cons "Fight"(player-inventory player))))] )) (define (fight player monster) ; Second is the fight local function. It has the player attack the enemy monster, inputing a player and monster structure, and outputing a player and monster structure, placed into the recursive response function. (cond [(and(>=(player-attack player)(monster-health monster))(one-message (string-append "You Attack "(monster-class monster)" For "(number->string(player-attack player))" Damage"))(one-message "You Defeat It"))player] [(one-message (string-append "You Attack "(monster-class monster)" For "(number->string(player-attack player))" Damage"))(response player (make-monster (-(monster-health monster)(player-attack player)) (monster-class monster) (monster-attack monster) (monster-animation monster)))] )) (define (potion player monster) ; Third is the potion local function. It has the player use a potion, inputing a player and monster structure, and outputing a player and monster structure, placed into the recursive response function, as well as removing the potion from the player's inventory. (cond [(and (<(player-full-health player)(+(player-health player)5))(one-message (string-append "You Heal "(number->string(-(player-full-health player)(player-health player)))" Hit Points, Full Health")))(response (make-player (player-full-health player)(player-full-health player)(player-class player)(player-attack player)(rempot(player-inventory player))(player-exp player))monster)] [(one-message "You Heal 5 Hit Points")(response (make-player (player-full-health player)(+(player-health player)5)(player-class player)(player-attack player)(rempot(player-inventory player))(player-exp player))monster)] )) (define (hi-potion player monster) ; Fourth is the hi-potion local function. It has the player use a hi-potion, inputing a player and monster structure, and outputing a player and monster structure, placed into the recursive response function, as well as removing the hi-potion from the player's inventory. (cond [(one-message(string-append "You Heal "(number->string(-(player-full-health player)(player-health player)))" Hit Points, Full Health"))(response (make-player (player-full-health player)(player-full-health player)(player-class player)(player-attack player)(remhi(player-inventory player))(player-exp player))monster)] ))) (cond ; Finally, we get to the meat. This core function checks between the possible outcomes, and returns a recursive call to the response function. [(string=? string "Fight")(fight player monster)] [(string=? string "Potion")(potion player monster)] [(string=? string "Hi-Potion")(hi-potion player monster)] [else (game-over player)] ) ) ) (define (rempot inv)( ;The rempot function inputs a list, and returns a list with a single item removed. cond [(string=?(first inv)"Potion")(rest inv)] [else (cons (first inv) (rempot (rest inv)))] ) ) (define (remhi inv)( ;The remhi function inputs a list, and returns a list with a single item removed. cond [(string=?(first inv)"Hi-Potion")(rest inv)] [else (cons (first inv) (remhi (rest inv)))] ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Actual Game Content Past This Point ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;(define-struct player (full-health health class attack inventory exp)) ;health of the player, player class, current weapon, current inventory, and experience points ;(define-struct monster (health attack animation)) ;health of the monster, its attack, experience for defeating it, what items it drops, and its animation (define name (get-answer "Who stands before the pit of monstrous evil?" 5)) ;gets the name of the player character (define class (get-choice "What sort of creature are you?" (list "Bear" "Mime" "Clown"))) ;records the character class (start 300 300) (draw-class 0) (draw-solid-string (make-posn 0 20) (string-append "You Are The Mighty "class" Known As "name".")) (wait-for-it 0) (define hero0 (make-player 10 10 class 1 (list "Run") 0)) (define hero (level-up hero0 (get-choice "What do you start with?" (list "Potion x2" "Hi-Potion")))) (and(=(player-exp hero)0)(draw-room 'red 'red 'white 'red 'black 'black)(wait-for-it 0)(give-message (string-append "The "class" "name" Has Stumbled Upon")"The Cave Of The Bear""Prepare To Be Mauled!")(attack bear)) (define hero2a (decision hero bear(get-choice (string-append "You Have "(number->string(player-health hero))" Hit Points") (cond [(empty?(player-inventory hero)) (list "Fight" "Run")] [(empty?(rest (player-inventory hero))) (list "Fight" (first(player-inventory hero)))] [else(cons "Fight" (player-inventory hero))] )))) (define hero2 (cond[(=(player-exp hero2a) 500)(make-player 0 0 0 0 0 500)] [else(level-up hero2a (get-choice "Level-Up! Pick Your Bonus" (list "Attack + 1" "Hit Points + 5" "Hi-Potion")))])) (and(=(player-exp hero2)0)(draw-room 'red 'white 'red 'white 'black 'black)(wait-for-it 0)(give-message (string-append "The Mighty "class" "name)"Has Entered The Lair Of The Clown""Watch Out, Or Be Traumatized!")(attack clown)) (define hero3a (cond[(=(player-exp hero2) 500)(make-player 0 0 0 0 0 500)] [else(decision hero2 clown (get-choice (string-append "You Have "(number->string(player-health hero2))" Hit Points") (cond [(empty?(player-inventory hero2)) (list "Fight" "Run")] [(empty?(rest (player-inventory hero2))) (list "Fight" (first(player-inventory hero2)))] [else(cons "Fight" (player-inventory hero2))] )))])) (define hero3 (cond[(=(player-exp hero3a) 500)(make-player 0 0 0 0 0 500)] [else(level-up hero3a (get-choice "Level-Up! Pick Your Bonus" (list "Attack + 1" "Hit Points + 5" "Hi-Potion")))])) (and(=(player-exp hero3)0)(draw-room 'white 'white 'white 'black 'black 'black)(wait-for-it 0)(give-message (string-append "The Truly Powerful "class" "name)"Now Braves The Vile Lands Of The Mime""Your Destruction Is At Hand!")(attack mime)) (define hero4a (cond[(=(player-exp hero3) 500)(make-player 0 0 0 0 0 500)] [else(decision hero3 mime (get-choice (string-append "You Have "(number->string(player-health hero3))" Hit Points") (cond [(empty?(player-inventory hero3)) (list "Fight" "Run")] [(empty?(rest (player-inventory hero3))) (list "Fight" (first(player-inventory hero3)))] [else(cons "Fight" (player-inventory hero3))] )))])) (define hero4 (cond[(=(player-exp hero4a) 500)(make-player 0 0 0 0 0 500)] [else(level-up hero4a (get-choice "Level-Up! Pick Your Bonus" (list "Attack + 1" "Hit Points + 5" "Hi-Potion")))])) (and(=(player-exp hero4)0)(draw-room 'black 'black 'white 'black 'black 'black)(wait-for-it 0) (give-message (string-append "The Ultimate "class" Known As "name)"Has Come To The Location Of...""Actually, I Don't Know Where This Is...")(attack pope-hat)) (define hero5 (cond[(=(player-exp hero4) 500)(make-player 0 0 0 0 0 500)] [else(decision hero4 pope-hat(get-choice (string-append "You Have "(number->string(player-health hero4))" Hit Points") (cond [(empty?(player-inventory hero4)) (list "Fight" "Run")] [(empty?(rest (player-inventory hero4))) (list "Fight" (first(player-inventory hero4)))] [else(cons "Fight" (player-inventory hero4))] )))])) (and(=(player-exp hero5)0)(draw-room 'yellow 'yellow 'white 'blue 'black 'black)(wait-for-it 0) (give-message (string-append "The Victorious "name" Wins.")"A Winner Is You.""We Didn't Have Time To Make More.")) ;(wait-for-it 0) ;(draw-animation (monster-animation bear)) ;(draw-animation (monster-animation clown)) ;(draw-animation (monster-animation mime)) ;(draw-animation pope-hat) ;(draw-animation (party-hat 'red 'black)) ;(draw-animation (party-hat 'red 'black)) ;(draw-animation (party-hat 'red 'black))