;; 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 final!) (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"))))) ;; 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 "-----------" 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)]) ]) )) (start 1500 1000) (define weapon-list (append (list (get-choice "Pick your Close Combat Weapon" (list "knife" "baseball bat")) (if (sleep-for-a-while 2) (get-choice "Pick your Mid Range Weapon" (list "cannon" "sling shot")) empty) (if (sleep-for-a-while 2) (get-choice "Pick your Long Range Weapon" (list "sniper" "kitten")) empty)) (if (and (sleep-for-a-while 2) (string=? (get-choice "Pick your Breakfast" (list "Breakfast of Champions" "Breakfast of Cheaters")) "Breakfast of Cheaters")) (list "ICBM(you cheater, you)") empty) )) (define p1-name (if (sleep-for-a-while 2) (get-answer "Input name:" 5) "Cheater")) (stop) ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;;contract: int int string number->boolean ;;purpose: Draws and clears an amount of damage at given coordinates ;;with a given delay time (define (draw/clear-damage x y damage delay) (and (draw-solid-string (make-posn x y) (string-append damage " damage!")) (sleep-for-a-while delay) (clear-solid-string (make-posn x y) (string-append damage " damage!")) )) ;;contract: int int string int int->boolean ;;purpose: calls the function draw/clear-damage multiple ;;times, going from one point to the next. (define (rise-damage x y damage x2 y2) (cond [(and (<= x x2) (<= y y2)) (draw/clear-damage x y (number->string damage) .05)] [else (and (draw/clear-damage x y (number->string damage) .05) (rise-damage (+ x 1) (- y 2) damage x2 y2))] ) ) ;;contract: posn symbol->boolean ;;purpose: draws a human (define (human position color) (and (draw-circle (make-posn (posn-x position) (- (posn-y position) 60)) 15 color) (draw-solid-line (make-posn (+ (posn-x position) 50) (- (posn-y position) 30)) (make-posn (posn-x position) (- (posn-y position) 20)) color) (draw-solid-line (make-posn (- (posn-x position) 50) (- (posn-y position) 30)) (make-posn (posn-x position) (- (posn-y position) 20)) color) (draw-solid-line (make-posn (posn-x position) (- (posn-y position) 45)) (make-posn (posn-x position) (+ (posn-y position) 30)) color) (draw-solid-line (make-posn (posn-x position) (+ (posn-y position) 30)) (make-posn (- (posn-x position) 50) (+ (posn-y position) 80)) color) (draw-solid-line (make-posn (posn-x position) (+ (posn-y position) 30)) (make-posn (+ (posn-x position) 50) (+ (posn-y position) 80)) color) ) ) ;;contract: int int->boolean ;;purpose: draws a knife (define (draw-knife x y) (and (draw-solid-disk (make-posn (+ x 6) y) 6 'brown) (draw-solid-rect (make-posn (+ x 12) (- y 4)) 30 8 'brown) (draw-solid-line (make-posn (+ x 42) (- y 12)) (make-posn (+ x 42) (+ y 12)) 'gray) (draw-solid-line (make-posn (+ x 42) (- y 12)) (make-posn (+ x 170) y) 'gray) (draw-solid-line (make-posn (+ x 42) (+ y 12)) (make-posn (+ x 170) y) 'gray) (draw-solid-line (make-posn (+ x 42) y) (make-posn (+ x 170) y) 'gray) ) ) ;;contract: int int int->boolean ;;purpose: draws a knife moving from one point to the next (define (knife-anim x y x2) (cond [(>= x x2) (draw-knife x y)] [(and (clear-solid-rect (make-posn (- x 1) (- y 12)) 180 25) (draw-knife x y) (sleep-for-a-while .0004)) (knife-anim (+ x 1) y x2)] ) ) ;;contract: int->boolean ;;purpose: draws a human throwing knives at the enemy and displays the damage dealt (define (knife-hit-anim damage) (and (start 1000 600) (human (make-posn 70 250) 'black) (human (make-posn 830 250) 'red) (knife-anim 90 200 800) (knife-anim 75 250 770) (knife-anim 120 310 850) (rise-damage 650 250 damage 700 150) (sleep-for-a-while 2) (stop) ) ) ;-------------------------------------------------- ;Contract: posn -> boolean ;Purpose: The four following functions either draw a representation of a bat or clear a bat of differing orientations (define (bat-vertical posn) (and (draw-solid-rect (make-posn (- (posn-x posn) 20) (- (posn-y posn) 80)) 10 80) (draw-solid-rect (make-posn (- (posn-x posn) 18) (posn-y posn)) 6 10) (draw-solid-rect (make-posn (- (posn-x posn) 20) (+ (posn-y posn) 10)) 10 5))) (define (bat-horizontal posn) (and (draw-solid-rect posn 80 10 ) (draw-solid-rect (make-posn (- (posn-x posn) 10) (+ (posn-y posn) 2)) 10 6) (draw-solid-rect (make-posn (- (posn-x posn) 15) (posn-y posn)) 5 10))) (define (bat-vertical-clear posn) (and (clear-solid-rect (make-posn (- (posn-x posn) 20) (- (posn-y posn) 80)) 10 80) (clear-solid-rect (make-posn (- (posn-x posn) 18) (posn-y posn)) 6 10) (clear-solid-rect (make-posn (- (posn-x posn) 20) (+ (posn-y posn) 10)) 10 5))) (define (bat-horizontal-clear posn) (and (clear-solid-rect posn 80 10 ) (clear-solid-rect (make-posn (- (posn-x posn) 10) (+ (posn-y posn) 2)) 10 6) (clear-solid-rect (make-posn (- (posn-x posn) 15) (posn-y posn)) 5 10))) ;Contract: posn var(usually you will want it to be 0) -> boolean ;Purpose: Recursively call the functions that draw and clear bats at the two orientations (define (bat-anim posn var) (cond [(> var 4) true] [else (and (bat-vertical posn) (sleep-for-a-while .2) (bat-vertical-clear posn) (sleep-for-a-while .01) (bat-horizontal posn) (sleep-for-a-while .2) (bat-horizontal-clear posn) (bat-anim posn (+ 1 var)))] ) ) ;Contract: number -> boolean ;Purpose: To call the bat animation in the canvas and to display the damage delt (define (bat-hit-anim damage) (and (start 1000 600) (human (make-posn 70 250) 'black) (human (make-posn 830 250) 'red) (bat-anim (make-posn 775 170) 0) (rise-damage 650 250 damage 700 150) (sleep-for-a-while 2) (stop) ) ) ;-------------------------------------------------- ;;contract: int int->boolean ;;purpose: draws a kitty (define (draw-kitty x y) (and (draw-solid-rect (make-posn x (- y 20)) 120 40 'gray) (draw-solid-disk (make-posn (+ x 140) (- y 42)) 24 'gray) (draw-solid-line (make-posn (+ x 3) (+ 20 y)) (make-posn (- x 12) (+ 60 y)) 'gray) (draw-solid-line (make-posn (+ x 3) (+ 20 y)) (make-posn (+ x 18) (+ 60 y)) 'gray) (draw-solid-line (make-posn (+ x 103) (+ 20 y)) (make-posn (+ x 88) (+ 60 y)) 'gray) (draw-solid-line (make-posn (+ x 103) (+ 20 y)) (make-posn (+ x 118) (+ 60 y)) 'gray) (draw-solid-line (make-posn (+ x 120) (- y 50)) (make-posn (+ x 130) (- y 80)) 'gray) (draw-solid-line (make-posn (+ x 140) (- y 50)) (make-posn (+ x 130) (- y 80)) 'gray) (draw-solid-line (make-posn (+ x 140) (- y 50)) (make-posn (+ x 150) (- y 80)) 'gray) (draw-solid-line (make-posn (+ x 160) (- y 50)) (make-posn (+ x 150) (- y 80)) 'gray) ) ) ;;contract: int int int->boolean ;;purpose: draws a kitty moving from one point to the next (define (kitty-anim x y x2) (cond [(>= x x2) (draw-kitty x y)] [(and (clear-solid-rect (make-posn (- x 13) (- y 90)) 167 153) (draw-kitty x y) (sleep-for-a-while .01)) (kitty-anim (+ x 1) y x2)] ) ) ;;contract: int->boolean ;;purpose: draws a human sending a kitty at the enemy and displays the damage dealt (define (kitty-hit-anim damage) (and (start 1000 600) (human (make-posn 70 250) 'black) (human (make-posn 830 250) 'red) (kitty-anim 150 200 800) (draw-solid-string (make-posn 20 500) "Mmmmmmmmmmmmeeeeeeeeeeeeeeeeeeeeeeoooooooooooooooooooooooooooowwwwwwwwwwwwwwwwwwww!!!") (rise-damage 650 250 damage 700 150) (sleep-for-a-while 2) (stop) ) ) ;-------------------------------------------------- ;;contract: int int->boolean ;;purpose: draws a sling shot (define (draw-sling-shot x y) (and (draw-solid-disk (make-posn (+ x 6) (- y 4)) 3 'black) (draw-solid-line (make-posn 120 200) (make-posn 120 212) 'brown) (draw-solid-line (make-posn 120 200) (make-posn 113 193) 'brown) (draw-solid-line (make-posn 120 200) (make-posn 127 193) 'brown) ) ) ;;contract: int int int->boolean ;;purpose: draws a slingshot with a moving bullet (define (sling-anim x y x2) (cond [(>= x x2) (draw-sling-shot x y)] [(and (clear-solid-rect (make-posn (- x 1) (- y 12)) 20 20) (draw-sling-shot x y) (sleep-for-a-while .0004)) (sling-anim (+ x 1) y x2)] ) ) ;;contract: int->boolean ;;purpose: draws a human shooting a sling shot at the enemy and displays the damage dealt (define (sling-hit-anim damage) (and (start 1000 600) (human (make-posn 70 250) 'black) (human (make-posn 830 250) 'red) (sling-anim 90 200 800) (rise-damage 650 250 damage 700 150) (sleep-for-a-while 2) (stop) ) ) ;-------------------------------------------------- ;the structure defining the cannon target and initial barrel coordinates (define-struct hobo-cannon (x y target-x target-y)) (define catapult(make-hobo-cannon 150 500 800 500)) ;the ammunition that is fired from the cannon (define-struct bullet (radius start-posn)) (define ammo (make-bullet 7 (make-posn 165 500))) ;contract posn, symbol, posn -> boolean ;purpose: to draw a fuse that burns red and then the cannon fires when it is done (define (fuse a-posn Y/N? when-done) (cond ;this will stop the fuse when its done [(and (<= (posn-x when-done) (posn-x a-posn)) (<= (posn-y when-done) (posn-y a-posn))) true] ;this draws the intial fuse and then calls the function again [(symbol=? Y/N? 'fire) (and (draw-solid-line a-posn when-done) (draw-solid-line (make-posn (posn-x a-posn) (+ 1 (posn-y a-posn))) (make-posn (posn-x when-done) (+ 1 (posn-y when-done)))) (fuse a-posn 'yes when-done))] ;this will delete part of the fuse and replace it with red signifying it being lit, then calls the function again [else (and (draw-solid-line a-posn (make-posn (+ 5 (posn-x a-posn)) (+ 5 (posn-y a-posn))) 'red) (draw-solid-line (make-posn (posn-x a-posn) (+ 1 (posn-y a-posn))) (make-posn (+ 5 (posn-x a-posn)) (+ 6 (posn-y a-posn))) 'red) (sleep-for-a-while .3) ;the fuse is on 'fire' and then burns out (draw-solid-line a-posn (make-posn (+ 5 (posn-x a-posn)) (+ 5 (posn-y a-posn))) 'white) (draw-solid-line (make-posn (posn-x a-posn) (+ 1 (posn-y a-posn))) (make-posn (+ 5 (posn-x a-posn)) (+ 6 (posn-y a-posn))) 'white) (sleep-for-a-while .3) (fuse (make-posn (+ 5 (posn-x a-posn)) (+ 5 (posn-y a-posn))) 'yes when-done))] ) ) ;contract symbol -> boolean ;purpose: this function waits for a signal to draw the cannon framework (define (cannon-barrel Y/N?) (cond [(symbol=? Y/N? 'no) true] [else (and ;upper half of barrel (draw-solid-line (make-posn (hobo-cannon-x catapult) (hobo-cannon-y catapult)) (make-posn (- (hobo-cannon-x catapult) 100) (+ (hobo-cannon-y catapult) 100))) ;lower half of barrel (draw-solid-line (make-posn (+ (hobo-cannon-x catapult) 15 ) (+ (hobo-cannon-y catapult) 15 )) (make-posn (- (hobo-cannon-x catapult) 85) (+ (hobo-cannon-y catapult) 115))) ;this connects the two upper end points (draw-solid-line (make-posn (- (hobo-cannon-x catapult) 100) (+ (hobo-cannon-y catapult) 100)) (make-posn (- (hobo-cannon-x catapult) 85) (+ (hobo-cannon-y catapult) 115))) ;this connects the lower endpoints (draw-solid-line (make-posn (hobo-cannon-x catapult) (hobo-cannon-y catapult)) (make-posn (+ (hobo-cannon-x catapult) 15) (+ (hobo-cannon-y catapult) 15))))] ) ) ;contract number, symbol(color), symbol(color), integer ;purpose: this function draws the animation for an explosion with a given radius, ;alternating given colors and does so a given number of times (define (explosions radius color1 color2 N-of-explosions) (cond [(= N-of-explosions 0) true] [else (and (draw-solid-disk (make-posn (hobo-cannon-target-x catapult) (hobo-cannon-target-y catapult)) radius color1) (clear-solid-rect (make-posn (- (hobo-cannon-target-x catapult) radius) (hobo-cannon-target-y catapult)) (* 3 radius) (* 3 radius)) (sleep-for-a-while .01) (explosions (+ radius 2) color2 color1 (- N-of-explosions 1)))] ) ) ;contract: number, posn, number ;purpose: this function will take a given radius for the projectile, a given start position ;and the number isn't adjusted from zero. The number is just there so ;I have a way of limiting my recursive calls (define (projectile radius start-point arc) (cond [(> arc 8) (explosions 20 'red 'yellow 50)] [(<= arc 4) (and (draw-solid-disk start-point radius 'black) (sleep-for-a-while .2) (clear-solid-disk start-point radius) (projectile radius (make-posn (+ (posn-x start-point) (/ (- (hobo-cannon-target-x catapult) (hobo-cannon-x catapult)) 8)) (- (posn-y start-point) 50)) (+ 1 arc)))] [(>= arc 2);same thing except for the change in y and then explosion (and (draw-solid-disk start-point radius 'black) (sleep-for-a-while .2) (clear-solid-disk start-point radius) (projectile radius (make-posn (+ (posn-x start-point) (/ (- (hobo-cannon-target-x catapult) (hobo-cannon-x catapult)) 8)) (+ (posn-y start-point) 50)) (+ 1 arc)) )] ) ) ;contract posn, posn -> boolean ;purpose: to open the canvas, draw the cannon, light the fuse, fire, and then close the canvas after wating 1 second ;this function essentially puts all the cannon pieces together (define (cannon-fired damage) (and (start 1000 600) (human (make-posn 70 250) 'black) (human (make-posn 830 450) 'red) (cannon-barrel 'yes) (fuse (make-posn 30 580) 'fire (make-posn 50 600)) (projectile (bullet-radius ammo) (bullet-start-posn ammo) 0) (rise-damage 800 380 damage 851 360) (sleep-for-a-while 1) (stop) ) ) ;-------------------------------------------------- ;number number -> boolean ;draws a sniper rifle and fires a bullet (define (draw-sniper x y) (and (draw-solid-disk (make-posn (+ x 50) (+ y 12)) 1 'red) (draw-solid-rect (make-posn 110 210) 100 5 'black) (draw-solid-rect (make-posn 205 205) 2 5) (draw-solid-rect (make-posn 115 210) 3 20) ) ) ;contract number -> boolean ;this function draws both players, does the weapon animation, and then animates the damage (define (sniper-hit-anim damage) (and (start 1000 600) (human (make-posn 70 250) 'black) (human (make-posn 830 250) 'red) (sniper-anim 90 200 800) (rise-damage 680 170 damage 710 140) (sleep-for-a-while 2) (stop) ) ) ;contract number number number -> boolean ;this function recursively calls the draw-sniper function until the starting x equals x2 (define (sniper-anim x y x2) (cond [(>= x x2) (draw-sniper x y)] [(and (draw-sniper x y) (sleep-for-a-while .00000000000004)) (sniper-anim (+ x 1) y x2)] ) ) ;-------------------------------------------------- ;contract: number number -> boolean ;this draws the ICBM when it is going upwards (define (draw-ICBMup start-x start-y) (and (draw-solid-disk (make-posn start-x start-y) 15 'red) (draw-solid-rect (make-posn (- start-x 15) (+ start-y 1)) 32 100 'blue)) ) ;contract number, number -> boolean ;this draws the missile as it heads back down (define (draw-ICBMdown start-x start-y) (and (draw-solid-disk (make-posn start-x start-y) 15 'red) (draw-solid-rect (make-posn (- start-x 15) (- start-y 99)) 32 100 'blue)) ) ;contract number number -> boolean ;this function clears the ICBM when it going in either direction (define (clear-ICBM start-x start-y) (and (clear-solid-disk (make-posn start-x start-y) 15 'red) (clear-solid-rect (make-posn (- start-x 15) (- start-y 99)) 32 100) ;I need two clears so that this function will clear both up and dwon movement (clear-solid-rect (make-posn (- start-x 15) (+ start-y 1)) 32 100 'blue) ) ) ;contract number number number number number number color color number number -> boolean ;this function is used to rapidly draw three expanding circles in random locations around a start point determined by the function that calls it. ;see the kaboom function below (define (randomBoom x y x2 y2 x3 y3 color1 color2 radius No.times) (cond [(= No.times 0) true] [else (and (draw-solid-disk (make-posn x y) radius color1) (draw-solid-disk (make-posn x2 y2) radius color1) (draw-solid-disk (make-posn x3 y3) radius color1) (sleep-for-a-while .005) (clear-solid-disk (make-posn x3 y3) radius color1) (clear-solid-disk (make-posn x2 y2) radius color1) (clear-solid-disk (make-posn x y) radius color1) (randomBoom x y x2 y2 x3 y3 color2 color1 (+ radius 5) (- No.times 1)))] ) ) ;contract number number color color number number -> boolean ;this function takes the number of explosions and calls the kaboom function the given number of times with a given coordinates. (define (kaboom x y color1 color2 radius No.ofExplosion) (cond [(= No.ofExplosion 0) true] [else (and (randomBoom (+ (- (random 300) 150) x) (+ (- (random 250) 125) y) (+ (- (random 300) 150) x) (+ (- (random 250) 125) y) (+ (- (random 300) 150) x) (+ (- (random 250) 125) y) ;if I made this local, it wouldn't re-evaluate the random color1 color2 radius 10) (kaboom x y color1 color2 radius (- No.ofExplosion 1)))] ) ) ;contract number number symbol number ;this function is used to create the movement of the ICBM from a given location to a set target (define (ICBM-movement x y up/down? delay) (cond [(and (= x 800) (>= y 400)) (kaboom 775 355 'red 'orange 20 30)] [(= y -125) (and (sleep-for-a-while 2) (ICBM-movement 800 (+ 1 y) 'down delay))] [(symbol=? up/down? 'up) (and (draw-ICBMup x y) (sleep-for-a-while delay) (clear-ICBM x y) (ICBM-movement x (- y 25) 'up (- delay .01)))];this reduction of delay creates the illusion of acceleration [(symbol=? up/down? 'down) (and (draw-ICBMdown x y) (sleep-for-a-while delay) (clear-ICBM x y) (ICBM-movement x (+ y 25) 'down delay))] ) ) ;;Contract: number->boolean ;;Purpose: animates a human sending a missile at the enemy (define (ICBM-hit damage) (and (start 1000 600) (human (make-posn 100 400) 'black) (human (make-posn 800 400) 'red) (sleep-for-a-while .5) (draw-solid-string (make-posn 100 300) "CHEATER!!!") (sleep-for-a-while .5) (ICBM-movement 250 600 'up .30) (draw-solid-string (make-posn 800 450) "CANCERIFIED!!" ) (rise-damage 800 400 damage 820 370) (sleep-for-a-while 1) (stop) ) ) ;-------------------------------------------------- ;;Contract: int int int->boolean ;;Purpose: draws a blue circle (define (draw-ball x y r) (draw-solid-disk (make-posn (+ x 6) (- y 4)) r 'blue) ) ;;Contract: int int int->boolean ;;Purpose: draws many circles (creates a beam) (define (ball-anim x y x2) (cond [(<= x x2) (draw-ball x y 20)] [(and (draw-ball x y 20) (sleep-for-a-while .0000004)) (ball-anim (- x 1) y x2)] ) ) ;;Contract: int->boolean ;;Purpose: draws the enemy attacking you (define (enemy-hit-anim damage) (and (start 1000 600) (human (make-posn 60 250) 'black) (human (make-posn 830 250) 'red) (draw-solid-string (make-posn 600 150) "KAH-MEH-HAH-MEH---HA!!!!!!!") (ball-anim 780 250 40) (draw-ball 60 250 80) (rise-damage 150 200 damage 200 100) (sleep-for-a-while 2) (stop) ) ) ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;Weapon definitions ;;A weapon, it has a name (string), a minimum and maximum damage (both numbers), and an animation function (define-struct weapon (name min-dmg max-dmg anim)) ;Close combat (define wpn-knife (make-weapon "knife" 200 1800 knife-hit-anim)) (define wpn-bat (make-weapon "baseball bat" 999 1001 bat-hit-anim)) ;Mid-range (define wpn-cannon (make-weapon "cannon" -1000 4000 cannon-fired)) (define wpn-sling (make-weapon "sling shot" 15 20 sling-hit-anim)) ;Long Range (define wpn-sniper (make-weapon "sniper" 1000 2000 sniper-hit-anim)) (define wpn-kitten (make-weapon "kitten" -200 -100 kitty-hit-anim)) ;Breakfast (define wpn-icbm (make-weapon "ICBM" 9000000 10000000 ICBM-hit)) (define (pick-weapon a-list) (local ((define attack-name (get-choice "Choose your attack" a-list))) (cond [(string=? attack-name "knife") wpn-knife] [(string=? attack-name "baseball bat") wpn-bat] [(string=? attack-name "cannon") wpn-cannon] [(string=? attack-name "sling shot") wpn-sling] [(string=? attack-name "sniper") wpn-sniper] [(string=? attack-name "kitten") wpn-kitten] [(string=? attack-name "ICBM(you cheater, you)") wpn-icbm] [else (pick-weapon a-list)] ) ) ) ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;;Contract: weapon->int ;;Purpose: takes a weapon, and assigns a random amount ;;of damage it deals in acordance to it's bounds (define (damage-calculator a-weapon) (+ (random (+ 1 (- (weapon-max-dmg a-weapon) (weapon-min-dmg a-weapon)))) (weapon-min-dmg a-weapon)) ) ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;;Contract: number string string->boolean ;;Purpose: draws the main screen (two people with names) and the player's health (define (health-bar hit-points p2-hp your-name opponent-name) (and (start 1000 600) (clear-solid-rect (make-posn 20 20) 300 10) (draw-solid-string (make-posn 20 500) your-name) (draw-solid-string (make-posn 750 500) opponent-name) (human (make-posn 70 250) 'black) (human (make-posn 830 250) 'red) (draw-solid-string (make-posn 780 530) (string-append (number->string p2-hp) " health!")) (cond [(= hit-points 6000) (draw-solid-rect (make-posn 20 20) 300 10 'green)] [(> hit-points 4000) (and (draw-solid-rect (make-posn 20 20) 300 10 'yellow) (draw-solid-rect (make-posn 20 20) (floor (* (/ (- hit-points 4000) 2000) 300)) 10 'green))] [(= hit-points 4000) (draw-solid-rect (make-posn 20 20) 300 10 'yellow)] [(> hit-points 2000) (and (draw-solid-rect (make-posn 20 20) 300 10 'red) (draw-solid-rect (make-posn 20 20) (floor (* (/ (- hit-points 2000) 2000) 300)) 10 'yellow))] [(= hit-points 2000) (draw-solid-rect (make-posn 20 20) 300 10 'red)] [(> hit-points 0) (draw-solid-rect (make-posn 20 20) (floor (* (/ hit-points 2000) 300)) 10 'red)] [(= hit-points 0) (draw-solid-string (make-posn 20 20) "dead")] ) (sleep-for-a-while 2) ) ) ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;;Contract: symbol symbol symbol symbol string number->boolean ;;Purpose: Draws a bunch of random circles and says a given message (define (end-game color1 color2 color3 color4 a-string num) (cond [(= num 5000) (stop)] [else (and (draw-solid-rect (make-posn 200 235) 163 20 color4) (draw-solid-string (make-posn 200 250) a-string) (draw-solid-disk (make-posn (random 500) (random 500)) 10 color1) (end-game color3 color1 color2 color4 a-string (+ num 1)))] ) ) ;;Contract: int->boolean ;;Purpose: displays win animation (define (you-win x) (and (start x x) (end-game 'blue 'red 'purple 'green "You are Victorious!" 0))) ;;Contract: int->boolean ;;Purpose: displays lose animation (define (you-lose x) (and (start x x) (end-game 'gray 'red 'black 'white "You are a Failure!" 0))) ;;Contract: number->boolean ;;Purpose: displays the mutual kill animation (define (mutual-kill delay) (and (start 500 500) (draw-solid-string (make-posn 180 200) "Well... you both died.....") (sleep-for-a-while delay) (draw-solid-string (make-posn 150 235) "This is awkward. Go play again.") (sleep-for-a-while 2) (stop) ) ) ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;----------FINALLY, The two main functions--------- ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;;Contract: number number->boolean ;;Purpose: checks if the game is over (define (handle-game p1-life p2-life) (cond [(and (>= 0 p1-life) (>= 0 p2-life)) (mutual-kill 4)] [(>= 0 p1-life) (you-lose 500)] [(>= 0 p2-life) (you-win 500)] [else (handle-combat p1-life p2-life)] ) ) ;;Contract: number number->boolean ;;Purpose: handles the combat in the game (define (handle-combat p1-life p2-life) (and (health-bar p1-life p2-life p1-name "Elena Machkasova") (sleep-for-a-while 1.5) (stop) (local ((define p1-wpn (pick-weapon weapon-list)) (define p1-hit (damage-calculator p1-wpn)) (define p2-hit (random 3000))) (and ((weapon-anim p1-wpn) p1-hit) (enemy-hit-anim p2-hit) (handle-game (- p1-life p2-hit) (- p2-life p1-hit))) ) ) ) ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;------------Time to call the game!!!!!!----------- ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- ;-------------------------------------------------- (handle-game 6000 6000)