;; 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 |problem set 10 game|) (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"))))) ;; Matt Perrault and Marty Reichert ;; Problem set 10 (Game Project) ;; ============== 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 2) (process-result (+ n 1)))] [else true]) ) ) (cond [(process-result 0) (list-ref list-of-choices (- (choice-index the-choices) 1))]))) ;; get-answer: string number -> string ;; The function displays a simple text input with a question ;; and returns the answer typed in by the user ;; The second parameter (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)]) ]) )) ;; NOTE: The language is Advanced Student. Teachpacks: gui.ss, draw.ss ;; =========================== do not change anything above this line ============= ;;--- drawing functions ---- (define-struct circle-outline (center radius color)) (define (draw-a-circle-outline a-circle) (draw-circle (circle-outline-center a-circle) (circle-outline-radius a-circle) (circle-outline-color a-circle))) (define (clear-a-circle-outline a-circle) (clear-solid-disk (circle-outline-center a-circle) (circle-outline-radius a-circle)) ) ;; --- line drawing --- (define-struct line (posn1 posn2 color)) (define (draw-a-line a-line) (draw-solid-line (line-posn1 a-line) (line-posn2 a-line) (line-color a-line))) (define (clear-a-line a-line) (clear-solid-line (line-posn1 a-line) (line-posn2 a-line))) ;; --- solid circle drawing --- ;; The structure represents a circle ;; center is the position (posn structure) of the center ;; radius is its radius (a non-negative number), and ;; color is a symbol representing a color (define-struct circle (center radius color)) ;; draw-a-circle: circle -> true ;; the function draws a circle structure as a disk ;; and returns true (define (draw-a-circle a-circle) (draw-solid-disk (circle-center a-circle) (circle-radius a-circle) (circle-color a-circle)) ) ;; clear-a-circle: circle -> true ;; the function clears a disk corresponding to a circle ;; and returns true (define (clear-a-circle a-circle) (clear-solid-disk (circle-center a-circle) (circle-radius a-circle)) ) ;;--- rectangle drawing --- ;; 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 rect (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-rect a-rectangle) (draw-solid-rect (rect-left-upper a-rectangle) (rect-height a-rectangle) (rect-width a-rectangle) (rect-color a-rectangle)) ) ;; clear-a-rectangle: rectangle -> true ;; the function clears a rectangle structure ;; and returns true (define (clear-a-rect a-rectangle) (clear-solid-rect (rect-left-upper a-rectangle) (rect-height a-rectangle) (rect-width a-rectangle) ) ) ;; --- draw and clear functions (work on lists) --- ;;draw-shapes: list-of-shapes -> boolean (picture) ;; Purpose: to take a list of shapes, and draw them all, can take circle, rect, line and circle-outline structures (define (draw-shapes alosh) (cond [(empty? alosh) true] [(circle? (first alosh)) (and (draw-a-circle (first alosh)) (draw-shapes (rest alosh)))] [(rect? (first alosh)) (and (draw-a-rect (first alosh)) (draw-shapes (rest alosh)))] [(line? (first alosh)) (and (draw-a-line (first alosh)) (draw-shapes (rest alosh)))] [(circle-outline? (first alosh)) (and (draw-a-circle-outline (first alosh)) (draw-shapes (rest alosh)))] ) ) ;;clear-shapes: list-of-shapes -> boolean (clears-picture) ;; Purpose: to take a list of shapes, and clears them all, can take circle, rect, line and circle-outline structures (define (clear-shapes alosh) (cond [(empty? alosh) true] [(circle? (first alosh)) (and (clear-a-circle (first alosh)) (clear-shapes (rest alosh)))] [(rect? (first alosh)) (and (clear-a-rect (first alosh)) (clear-shapes (rest alosh)))] [(line? (first alosh)) (and (clear-a-line (first alosh)) (clear-shapes (rest alosh)))] [(circle-outline? (first alosh)) (and (clear-a-circle-outline (first alosh)) (clear-shapes (rest alosh)))] ) ) ;; ==========================: Loading Scenes :==================================== ;; the first window, name entry (define character-name (get-answer "What's your name?" 5)) ;; the first list of choices for a location: (define locations (list "Cave" "Field" "Trail")) ;; calling "get-choice" to get the user's choice, adding the choice to ;; the list of weapons. weapon-list is the new list (define location-selector (cons (get-choice "Choose where your Pokemon adventure will begin!" locations) empty)) (sleep-for-a-while 4) ;; creates the graphics window (start 800 600) ;; both functions create strings to be used to identify the start of the game (define adventure-start-message (string-append character-name "'s Pokemon adventure begins at the " (first location-selector) "!!")) (define location-loading-message (string-append "Currently loading the " (first location-selector) " . . .")) ;; draws the starting strings on the canvas at the given position (draw-solid-string (make-posn 300 20) adventure-start-message) (sleep-for-a-while 3) (draw-solid-string (make-posn 300 50) location-loading-message) (sleep-for-a-while .7) ;; clears the first beginning string: "persons adventure begins at the place" (clear-solid-string (make-posn 300 20) adventure-start-message) ;; pokeball: list of coordinates to draw a pokeball for the loading screen (define pokeball (list (make-circle (make-posn 400 300) 146 'red) (make-rect (make-posn 250 300) 300 150 'white) (make-circle-outline (make-posn 400 300) 147 'black) (make-line (make-posn 255 299) (make-posn 400 299) 'black) (make-circle (make-posn 400 300) 34 'white) (make-circle-outline (make-posn 400 300) 35 'black))) ;; pokeball-loading-sequence: number -> boolean ;; function draws and clears the pokeball multiple times to simulate a loading effect (define (pokeball-loading-sequence sleep-time) (local ((define (loading-sequence sleep-time) (and (draw-shapes pokeball) (sleep-for-a-while sleep-time) (clear-shapes pokeball) (sleep-for-a-while (- sleep-time .2))))) (and (loading-sequence sleep-time) (loading-sequence sleep-time) (loading-sequence sleep-time)))) (pokeball-loading-sequence .7) ;; clears the loading... message (clear-solid-string (make-posn 300 50) location-loading-message) ;;=======================: Loading graphics section :================================ (define cave-loading-graphic (list (make-rect (make-posn 325 140) 202 150 'brown) (make-rect (make-posn 325 270) 202 150 'black) (make-circle (make-posn 440 270) 85 'black) (make-rect (make-posn 160 140) 200 280 'brown) (make-rect (make-posn 525 140) 200 280 'brown) (make-line (make-posn 160 300) (make-posn 255 389) 'black) (make-line (make-posn 275 345) (make-posn 255 389) 'black) (make-line (make-posn 268 360) (make-posn 289 389) 'black) (make-line (make-posn 290 140) (make-posn 255 195) 'black) (make-line (make-posn 600 140) (make-posn 550 222) 'black) (make-line (make-posn 575 180) (make-posn 530 180) 'black) (make-rect (make-posn 600 340) 30 40 'tan) (make-line (make-posn 620 339) (make-posn 635 325) 'black) (make-line (make-posn 599 375) (make-posn 580 395) 'black) (make-line (make-posn 576 370) (make-posn 585 390) 'black) )) (define trail-loading-graphic (list (make-rect (make-posn 200 300) 450 150 'brown) (make-rect (make-posn 380 300) 75 150 'olive) (make-circle (make-posn 440 430) 12 'tan) (make-circle (make-posn 400 420) 10 'tan) (make-circle (make-posn 415 405) 10 'tan) (make-circle (make-posn 400 390) 8 'tan) (make-circle (make-posn 400 390) 8 'tan) (make-circle (make-posn 410 380) 8 'tan) (make-circle (make-posn 430 375) 8 'tan) (make-circle (make-posn 400 360) 7 'tan) (make-circle (make-posn 410 347) 7 'tan) (make-circle (make-posn 430 345) 7 'tan) (make-circle (make-posn 410 330) 6 'tan) (make-circle (make-posn 434 320) 6 'tan) (make-line (make-posn 200 300) (make-posn 280 150) 'brown) (make-line (make-posn 360 300) (make-posn 280 150) 'brown) (make-line (make-posn 322 230) (make-posn 400 130) 'brown) (make-line (make-posn 500 300) (make-posn 400 130) 'brown) (make-line (make-posn 649 300) (make-posn 540 145) 'brown) (make-line (make-posn 465 240) (make-posn 540 145) 'brown) )) (define field-loading-graphic (list (make-rect (make-posn 100 100) 600 350 'olive) (make-rect (make-posn 330 100) 140 350 'brown) (make-rect (make-posn 200 300) 20 100 'brown) (make-circle (make-posn 205 300) 20 'green) (make-circle (make-posn 215 300) 25 'green) (make-circle (make-posn 205 285) 20 'green) (make-rect (make-posn 600 200) 20 100 'brown) (make-circle (make-posn 605 200) 20 'green) (make-circle (make-posn 615 200) 25 'green) (make-circle (make-posn 605 185) 20 'green) (make-rect (make-posn 250 150) 20 100 'brown) (make-circle (make-posn 255 150) 20 'green) (make-circle (make-posn 265 150) 25 'green) (make-circle (make-posn 255 135) 20 'green) (make-circle (make-posn 580 380) 40 'blue) (make-circle (make-posn 620 390) 55 'blue) (make-rect (make-posn 530 170) 20 100 'brown) (make-circle (make-posn 535 170) 20 'green) (make-circle (make-posn 545 170) 25 'green) (make-circle (make-posn 535 155) 20 'green) )) ;;========================: Loading Scenes (cont.) :============================= ;; area-loaded-graphic: location(list) -> boolean (picture) ;;make function that draws the landscape for the given location they selected (define (area-loaded-graphic loc) ;; not in use yet! (cond [(string=? (first loc) "Field") (draw-shapes field-loading-graphic)] [(string=? (first loc) "Cave") (draw-shapes cave-loading-graphic)] [(string=? (first loc) "Trail") (draw-shapes trail-loading-graphic)])) (area-loaded-graphic location-selector) (sleep-for-a-while 2) ;; different-response-attack: charcter-name location(list) -> string ;; creates different strings that vary based on location and add to the story, uses the characters name and the location (define (different-response-attack char loc) (cond [(string=? (first loc) "Cave") (string-append "After a few minutes of venturing through the cave, " char " spots an old fat man, he looks like a pokemon trainer!")] [(string=? (first loc) "Field") (string-append "After a few paces through the field, " char " spots a small boy come from behind a bush, he looks like a pokemon trainer!")] [(string=? (first loc) "Trail") (string-append "After a few paces down the moutain trail, " char " ran into a rugged man power walking! He demands a battle!")] )) (draw-solid-string (make-posn 20 500) (different-response-attack character-name location-selector)) (sleep-for-a-while 5) ;; creates a flashing effect over the whole screen that starts the battle (define (battle-flash-start set-time) (local ((define black-flash (make-rect (make-posn 0 0) 800 600 'black))) (local ((define (flashing set-time) (and (draw-a-rect black-flash) (sleep-for-a-while set-time) (clear-a-rect black-flash) (sleep-for-a-while set-time)))) (and (flashing set-time) (flashing set-time) (flashing set-time) (flashing set-time) (flashing set-time) (flashing set-time))))) (battle-flash-start .1) (sleep-for-a-while 1) ;; ==========================: Drawing Section :==================================== ;; all functions here can be drawn using (draw-shapes geodude) and it will draw the pokemon ;; sets the red template for the battle scene (define battle-template (list (make-line (make-posn 0 50) (make-posn 350 50) 'red) (make-line (make-posn 400 0) (make-posn 350 50) 'red) (make-line (make-posn 0 60) (make-posn 355 60) 'red) (make-line (make-posn 415 0) (make-posn 355 60) 'red) (make-line (make-posn 800 550) (make-posn 450 550) 'red) (make-line (make-posn 400 600) (make-posn 450 550) 'red) (make-line (make-posn 800 540) (make-posn 445 540) 'red) (make-line (make-posn 385 600) (make-posn 445 540) 'red) )) (define charmander (list (make-circle (make-posn 125 500) 50 'orange) (make-rect (make-posn 75 500) 101 100 'orange) (make-rect (make-posn 40 560) 15 40 'orange) (make-circle (make-posn 45 560) 15 'yellow) (make-circle (make-posn 46 570) 8 'orange) (make-circle (make-posn 150 520) 40 'orange) (make-rect (make-posn 150 570) 60 22 'orange) (make-line (make-posn 209 573) (make-posn 200 573) 'black) (make-line (make-posn 209 578) (make-posn 200 578) 'black) (make-line (make-posn 209 583) (make-posn 200 583) 'black) )) (define squirtle (list (make-circle (make-posn 125 500) 50 'blue) (make-rect (make-posn 75 500) 101 100 'blue) (make-rect (make-posn 50 525) 150 20 'blue) (make-circle (make-posn 125 550) 65 'brown) (make-line (make-posn 60 550) (make-posn 190 550) 'black) ;; x (make-line (make-posn 125 615) (make-posn 125 485) 'black);; y (make-line (make-posn 157 550) (make-posn 125 517) 'black) (make-line (make-posn 125 517) (make-posn 92 550) 'black) (make-line (make-posn 125 582) (make-posn 92 550) 'black) (make-line (make-posn 125 582) (make-posn 157 550) 'black) )) (define geodude (list (make-circle (make-posn 610 100) 40 'tan) (make-rect (make-posn 530 98) 155 12 'tan) (make-rect (make-posn 530 70) 12 40 'tan) (make-rect (make-posn 675 70) 12 40 'tan) (make-rect (make-posn 668 60) 25 20 'tan) (make-rect (make-posn 523 60) 25 20 'tan) (make-circle (make-posn 595 88) 9 'white) (make-circle (make-posn 627 88) 9 'white) (make-circle (make-posn 595 90) 4 'black) (make-circle (make-posn 627 90) 4 'black) (make-rect (make-posn 585 68) 52 20 'tan) (make-line (make-posn 585 80) (make-posn 600 85) 'black) (make-line (make-posn 638 80) (make-posn 623 85) 'black) (make-line (make-posn 672 60) (make-posn 672 68) 'black) (make-line (make-posn 680 60) (make-posn 680 68) 'black) (make-line (make-posn 688 60) (make-posn 688 68) 'black) (make-line (make-posn 530 60) (make-posn 530 68) 'black) (make-line (make-posn 538 60) (make-posn 538 68) 'black) (make-line (make-posn 546 60) (make-posn 546 68) 'black) (make-line (make-posn 590 115) (make-posn 630 115) 'black) (make-line (make-posn 590 115) (make-posn 610 120) 'black) )) (define diglett (list (make-circle (make-posn 650 150) 50 'brown) (make-rect (make-posn 600 150) 100 130 'brown) (make-circle (make-posn 650 180) 10 'pink) (make-circle (make-posn 645 180) 10 'pink) (make-circle (make-posn 655 180) 10 'pink) (make-circle (make-posn 660 150) 5 'black) (make-circle (make-posn 660 153) 5 'black) (make-circle (make-posn 660 147) 5 'black) (make-circle (make-posn 660 145) 5 'black) (make-circle (make-posn 660 143) 5 'black) (make-circle (make-posn 660 140) 5 'black) (make-circle (make-posn 640 150) 5 'black) (make-circle (make-posn 640 153) 5 'black) (make-circle (make-posn 640 147) 5 'black) (make-circle (make-posn 640 145) 5 'black) (make-circle (make-posn 640 143) 5 'black) (make-circle (make-posn 640 140) 5 'black))) (define snorlax (list (make-circle (make-posn 650 50) 50 'teal) (make-rect (make-posn 670 10) 30 30 'teal) (make-rect (make-posn 600 10) 30 30 'teal) (make-circle (make-posn 650 150) 100 'teal) (make-circle (make-posn 650 50) 30 'tan) (make-circle (make-posn 650 180) 70 'tan) (make-rect (make-posn 735 220) 10 10 'black) (make-rect (make-posn 555 220) 10 10 'black) (make-rect (make-posn 570 205) 10 10 'black) (make-rect (make-posn 720 205) 10 10 'black) (make-rect (make-posn 690 205) 10 10 'black) (make-rect (make-posn 600 205) 10 10 'black) (make-circle (make-posn 710 240) 35 'tan) (make-circle (make-posn 710 240) 35 'tan) (make-circle (make-posn 590 240) 35 'tan) (make-circle (make-posn 590 250) 20 'brown) (make-circle (make-posn 710 250) 20 'brown) (make-rect (make-posn 605 70) 80 30 'teal) (make-line (make-posn 630 40)(make-posn 640 40) 'black) (make-line (make-posn 670 40)(make-posn 660 40) 'black) (make-line (make-posn 630 55)(make-posn 670 55) 'black))) ;; ==========================: Battle Scenes :====================================== ;; enemy-name: location(list) -> string ;; to draw the string of the correct name of the enemy the play has to battle on the screen (define (enemy-name loc) (cond [(string=? (first loc) "Cave") (string-append "Hiker Alex")] [(string=? (first loc) "Field") (string-append "Little Kid Rob")] [(string=? (first loc) "Trail") (string-append "Power Walker Gilbert")] )) ;; the second list of choices for the characters pokemon: (define characters-pokemon-choices (list "Charmander" "Squirtle")) ;; calling "get-choice" to get the user's choice, adding the choice to ;; the pokemon-choice list. pokemon-choice is the new list (define pokemon-choice (cons (get-choice "Choose your first Pokemon to send into battle!" characters-pokemon-choices) empty)) (sleep-for-a-while 3) ;; characters-pokemon-drawer: list (pokemon-choice) -> boolean (picture) ;; takes the pokemon-choice list and draws the correct pokemon that they chose as well as a string and the template to go with it, clears the string after 1 second (define (characters-pokemon-drawer pokemon-choice) (cond [(string=? (first pokemon-choice) "Charmander") (and (draw-solid-string (make-posn 480 525)(string-append character-name ": Charmander! I choose you!")) (draw-shapes battle-template) ;; draws the template as well (sleep-for-a-while 2) (draw-shapes charmander) (sleep-for-a-while 2) (clear-solid-string (make-posn 480 525)(string-append character-name ": Charmander! I choose you!")))] [(string=? (first pokemon-choice) "Squirtle") (and (draw-solid-string (make-posn 480 525) (string-append character-name ": Squirtle! I choose you!")) (draw-shapes battle-template) (sleep-for-a-while 2) (draw-shapes squirtle) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append character-name ": Squirtle! I choose you!")))])) (characters-pokemon-drawer pokemon-choice) ;; draws the pokemons name and their level on the battle template (draw-solid-string (make-posn 440 585) (string-append (first pokemon-choice) " Level: 15")) ;; creates a pokemon list, based on previous choices of the locations, the pokemon for that area will be set to this list (define pokemon empty) ;; a structure where name, move1, move2, move3, move4 are all symbols, what the elements are used for is implied by the name assigned to them already (define-struct pokemons (name move1 move2 move3 move4)) ;; add-mult-pokemon-to-list: list (of pokemons structures) -> void ;; to take a list of the given pokemon(s) the enemy will have, and set it to the empty pokemon list based on the level choice (define (add-mult-pokemon-to-list list-of-pokemon-structures) (local ((define (add-pokemon-to-list pokemon-structure) (set! pokemon (cons (list pokemon-structure) pokemon)))) (cond [(empty? list-of-pokemon-structures) empty] [else (cons (add-pokemon-to-list (first list-of-pokemon-structures)) (add-mult-pokemon-to-list (rest list-of-pokemon-structures)))]))) ;; pokemon-struct-list-setter: list (location) -> list (of pokemons structures) ;; to assign the right list of pokemon structures to the given enemy/location that was selected (define (pokemon-struct-list-setter loc) (cond [(string=? (first loc) "Cave") (add-mult-pokemon-to-list (list (make-pokemons "Snorlax" "Body Slam" "Crunch" "Defense Curl" "Tackle")))] [(string=? (first loc) "Field") (add-mult-pokemon-to-list (list (make-pokemons "Diglett" "Rock Smash" "Rock Slide" "Dig" "Tackle")))] [(string=? (first loc) "Trail") (add-mult-pokemon-to-list (list (make-pokemons "Geodude" "Rock Smash" "Rock Slide" "Defense Curl" "Tackle")))] )) (pokemon-struct-list-setter location-selector) ;; both of these functions draw the string of the enemys name and their pokemons name (draw-solid-string (make-posn 200 40) (string-append (pokemons-name (first (first pokemon))) " Level: 15")) (draw-solid-string (make-posn 40 40) (enemy-name location-selector)) ;; enemy-pokemon-drawing-setter: list (of pokemon structures) -> boolean(picture) ;; to draw the first pokemon thats specified in the given list "pokemon" as defined by pokemon-struct-list-setter (define (enemy-pokemon-drawing-setter list-of-pokemon-struct) (cond [(string=? (pokemons-name (first (first list-of-pokemon-struct))) "Snorlax") (draw-shapes snorlax)] [(string=? (pokemons-name (first (first list-of-pokemon-struct))) "Geodude") (draw-shapes geodude)] [(string=? (pokemons-name (first (first list-of-pokemon-struct))) "Diglett") (draw-shapes diglett)])) (enemy-pokemon-drawing-setter pokemon) ;; these three functions are all used in conjuction with the health bars, enemy-health-bar and player-health-bar all take the function starting-player-health, which will be modified later depending on the attacks selected (define (enemy-health-bar current-health) (and (draw-solid-string (make-posn 120 25) "HP:") (draw-a-rect (make-rect (make-posn 150 17) (first current-health) 7 'green)))) (define (player-health-bar current-health) (and (draw-solid-string (make-posn 610 573) "HP:") (draw-a-rect (make-rect (make-posn 640 565) (first current-health) 7 'green)))) (define starting-player-health (list 100)) (enemy-health-bar starting-player-health) (player-health-bar starting-player-health) (sleep-for-a-while 2) ;; takes 'pokemon-choice' list, which contains the first pokemon that the player chose (define (characters-pokemon-attack-choices pokemon-choices) (cond [(string=? (first pokemon-choices) "Charmander") (list "Ember" "Flamethrower" "Bite" "Tackle")] [(string=? (first pokemon-choices) "Squirtle") (list "Bubblebeam" "Water Gun" "Bite" "Tackle")])) ;; calling "get-choice" to get the user's choice, adding the choice to ;; the pokemon-choice list. pokemon-choice is the new list (define characters-attack-choice (cons (get-choice "Choose your attack!" (characters-pokemon-attack-choices pokemon-choice)) empty)) (sleep-for-a-while 4) ;; players-attack-damage1: list(characters-selected-attack) -> list ;; takes the characters selected attack list and makes a list of how much damage the attack chosen has inflicted on the enemy via the healthbar, the previous health bar gets removed as well (define (players-attack-damage1 selected-attack) (cond [(string=? (first selected-attack) "Bite") (begin (clear-a-rect (make-rect (make-posn 150 17) (first starting-player-health) 7 'green)) (list (- (first starting-player-health) 35 )))] [(string=? (first selected-attack) "Tackle") (begin (clear-a-rect (make-rect (make-posn 150 17) (first starting-player-health) 7 'green)) (list (- (first starting-player-health) 35 )))] [(string=? (first selected-attack) "Bubblebeam") (begin (clear-a-rect (make-rect (make-posn 150 17) (first starting-player-health) 7 'green)) (list (- (first starting-player-health) 45 )))] [(string=? (first selected-attack) "Ember") (begin (clear-a-rect (make-rect (make-posn 150 17) (first starting-player-health) 7 'green)) (list (- (first starting-player-health) 35 )))] [(string=? (first selected-attack) "Water Gun") (begin (clear-a-rect (make-rect (make-posn 150 17) (first starting-player-health) 7 'green)) (list (- (first starting-player-health) 35 )))] [(string=? (first selected-attack) "Flamethrower") (begin (clear-a-rect (make-rect (make-posn 150 17) (first starting-player-health) 7 'green)) (list (- (first starting-player-health) 45 )))] )) ;; use-players-attack1: list(characters-attack-choice) -> boolean and string ;; draws a string of the user using that attack on that oppenent, and makes their health go down using the players-attack-damage1 function (define (use-players-attack1 selected-attack) (cond [(string=? (first selected-attack) "Bite") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bite!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage1 characters-attack-choice)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bite!")))] [(string=? (first selected-attack) "Tackle") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Tackle!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage1 characters-attack-choice)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Tackle!")))] [(string=? (first selected-attack) "Bubblebeam") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bubblebeam!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage1 characters-attack-choice)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bubblebeam!")))] [(string=? (first selected-attack) "Ember") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Ember!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage1 characters-attack-choice)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Ember!")))] [(string=? (first selected-attack) "Water Gun") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Water Gun!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage1 characters-attack-choice)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Water Gun!")))] [(string=? (first selected-attack) "Flamethrower") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Flamethrower!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage1 characters-attack-choice)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Flamethrower!")))] )) (use-players-attack1 characters-attack-choice) (sleep-for-a-while 2) ;;;; their turn to attack ;; sets the damage that the enemys attack will do to the player, clears the old health bar as well (define enemys-attack-damage1 (begin (clear-a-rect (make-rect (make-posn 640 565) (first starting-player-health) 7 'green)) (list (- (first starting-player-health) 25 )))) ;; possible-enemy-attacks: list (location) -> list ;; to generate a list of attacks that the pokemon could have at that given location (define (enemy-attack1 loc) (cond [(string=? (first loc) "Cave") (and (draw-solid-string (make-posn 480 525) "Snorlax used Body Slam!") (sleep-for-a-while 1) (player-health-bar enemys-attack-damage1) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) "Snorlax used Body Slam!"))] [(string=? (first loc) "Field") (and (draw-solid-string (make-posn 480 525) "Diglett used Rock Slide!") (sleep-for-a-while 1) (player-health-bar enemys-attack-damage1) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) "Diglett used Rock Slide!"))] [(string=? (first loc) "Trail") (and (draw-solid-string (make-posn 480 525) "Geodude used Rock Smash!") (sleep-for-a-while 1) (player-health-bar enemys-attack-damage1) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) "Geodude used Rock Smash!"))])) (enemy-attack1 location-selector) ;;; players attack now ;;;;; ;; calling "get-choice" to get the user's choice, adding the choice to ;; the pokemon-choice list. pokemon-choice is the new list (define characters-attack-choice1 (cons (get-choice "Choose your attack!" (characters-pokemon-attack-choices pokemon-choice)) empty)) (sleep-for-a-while 4) ;; players-attack-damage1: list(characters-selected-attack) -> list ;; takes the characters selected attack list and makes a list of how much damage the attack chosen has inflicted on the enemy via the healthbar, the previous health bar gets removed as well (define (players-attack-damage2 selected-attack) (cond [(string=? (first selected-attack) "Bite") (begin (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage1 characters-attack-choice)) 7 'green)) (list (- (first (players-attack-damage1 characters-attack-choice)) 35 )))] [(string=? (first selected-attack) "Tackle") (begin (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage1 characters-attack-choice)) 7 'green)) (list (- (first (players-attack-damage1 characters-attack-choice)) 30 )))] [(string=? (first selected-attack) "Bubblebeam") (begin (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage1 characters-attack-choice)) 7 'green)) (list (- (first (players-attack-damage1 characters-attack-choice)) 45 )))] [(string=? (first selected-attack) "Ember") (begin (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage1 characters-attack-choice)) 7 'green)) (list (- (first (players-attack-damage1 characters-attack-choice)) 35 )))] [(string=? (first selected-attack) "Water Gun") (begin (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage1 characters-attack-choice)) 7 'green)) (list (- (first (players-attack-damage1 characters-attack-choice)) 35 )))] [(string=? (first selected-attack) "Flamethrower") (begin (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage1 characters-attack-choice)) 7 'green)) (list (- (first (players-attack-damage1 characters-attack-choice)) 45 )))] )) ;; use-players-attack2: list(characters-attack-choice1) -> boolean and string ;; draws a string of the user using that attack on that oppenent, and makes their health go down using the players-attack-damage1 function (define (use-players-attack2 selected-attack) (cond [(string=? (first selected-attack) "Bite") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bite!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage2 characters-attack-choice1)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bite!")))] [(string=? (first selected-attack) "Tackle") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Tackle!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage2 characters-attack-choice1)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Tackle!")))] [(string=? (first selected-attack) "Bubblebeam") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bubblebeam!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage2 characters-attack-choice1)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bubblebeam!")))] [(string=? (first selected-attack) "Ember") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Ember!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage2 characters-attack-choice1)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Ember!")))] [(string=? (first selected-attack) "Water Gun") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Water Gun!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage2 characters-attack-choice1)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Water Gun!")))] [(string=? (first selected-attack) "Flamethrower") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Flamethrower!")) (sleep-for-a-while 1) (enemy-health-bar (players-attack-damage2 characters-attack-choice1)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Flamethrower!")))] )) (use-players-attack2 characters-attack-choice1) (sleep-for-a-while 1) ;;;; their turn to attack again ;;;;;;; ;; sets the damage that the enemys attack will do to the player (define enemys-attack-damage2 (begin (clear-a-rect (make-rect (make-posn 640 565) (first enemys-attack-damage1) 7 'green)) (list (- (first enemys-attack-damage1) 35 )))) ;; possible-enemy-attacks: list (location) -> list ;; to generate a list of attacks that the pokemon could have at that given location (define (enemy-attack2 loc) (cond [(string=? (first loc) "Cave") (and (draw-solid-string (make-posn 480 525) "Snorlax used Crunch!") (sleep-for-a-while 1) (player-health-bar enemys-attack-damage2) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) "Snorlax used Crunch!"))] [(string=? (first loc) "Field") (and (draw-solid-string (make-posn 480 525) "Diglett used Dig!") (sleep-for-a-while 1) (player-health-bar enemys-attack-damage2) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) "Diglett used Dig!"))] [(string=? (first loc) "Trail") (and (draw-solid-string (make-posn 480 525) "Geodude used Defense Curl!") (player-health-bar enemys-attack-damage1) (sleep-for-a-while 1) (draw-solid-string (make-posn 480 505) "Geodude's defense rose!") (sleep-for-a-while 3) (clear-solid-string (make-posn 480 525) "Geodude used Defense Curl!") (clear-solid-string (make-posn 480 505) "Geodude's defense rose!"))])) (enemy-attack2 location-selector) ;;;; players attack again ;;; final;;;;; ;; calling "get-choice" to get the user's choice, adding the choice to ;; the pokemon-choice list. pokemon-choice is the new list (define characters-attack-choice2 (cons (get-choice "Choose your attack!" (characters-pokemon-attack-choices pokemon-choice)) empty)) (sleep-for-a-while 4) (define (use-players-attack3 selected-attack) (cond [(string=? (first selected-attack) "Bite") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bite!")) (sleep-for-a-while 1) (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage2 characters-attack-choice1)) 7 'green)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bite!")))] [(string=? (first selected-attack) "Tackle") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Tackle!")) (sleep-for-a-while 1) (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage2 characters-attack-choice1)) 7 'green)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Tackle!")))] [(string=? (first selected-attack) "Bubblebeam") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bubblebeam!")) (sleep-for-a-while 1) (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage2 characters-attack-choice1)) 7 'green)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Bubblebeam!")))] [(string=? (first selected-attack) "Ember") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Ember!")) (sleep-for-a-while 1) (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage2 characters-attack-choice1)) 7 'green)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Ember!")))] [(string=? (first selected-attack) "Water Gun") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Water Gun!")) (sleep-for-a-while 1) (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage2 characters-attack-choice1)) 7 'green)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Water Gun!")))] [(string=? (first selected-attack) "Flamethrower") (and (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Flamethrower!")) (sleep-for-a-while 1) (clear-a-rect (make-rect (make-posn 150 17) (first (players-attack-damage2 characters-attack-choice1)) 7 'green)) (sleep-for-a-while 1) (clear-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " used Flamethrower!")))] )) (use-players-attack3 characters-attack-choice2) ;; final-scene: list (pokemon structures) -> boolean/string ;; to draw and clear what is nessecary for the end of the game, clears the enemy pokemon and adds other strings too (define (final-scene list-of-pokemon-struct) (cond [(string=? (pokemons-name (first (first list-of-pokemon-struct))) "Snorlax") (and (draw-solid-string (make-posn 480 525) (string-append character-name " beat Hiker Alex!")) (clear-shapes snorlax) (sleep-for-a-while 3) (clear-solid-string (make-posn 480 525) (string-append character-name " beat Hiker Alex!")) (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " gained 665 Experince Points!")) (sleep-for-a-while 3) (draw-solid-string (make-posn 300 400) "CONGRATULATIONS!")) ] [(string=? (pokemons-name (first (first list-of-pokemon-struct))) "Geodude") (and (draw-solid-string (make-posn 480 525) (string-append character-name " beat Little Kid Rob!")) (clear-shapes geodude) (sleep-for-a-while 3) (clear-solid-string (make-posn 480 525) (string-append character-name " beat Little Kid Rob!")) (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " gained 244 Experince Points!")) (sleep-for-a-while 3) (draw-solid-string (make-posn 300 400) "CONGRATULATIONS!"))] [(string=? (pokemons-name (first (first list-of-pokemon-struct))) "Diglett") (and (draw-solid-string (make-posn 480 525) (string-append character-name " beat Power Walker Gilbert!")) (clear-shapes diglett) (sleep-for-a-while 3) (clear-solid-string (make-posn 480 525) (string-append character-name " beat Power Walker Gilbert!")) (draw-solid-string (make-posn 480 525) (string-append (first pokemon-choice) " gained 322 Experince Points!")) (sleep-for-a-while 3) (draw-solid-string (make-posn 300 400) "CONGRATULATIONS!"))])) (final-scene pokemon) (sleep-for-a-while 2) (stop)