;; Jason Bonde ;; Andy Bowe ;; Anne Krohmer ;; 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. ;; ============== 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: =============================== ;; This is an example of one round of the accummulation stage of a game. ;; Your game will have multiple rounds. ;; the first list of choices: (define item-choices1 (list "The Only Ring")) (define yesno (list "Yes" "No")) (start 800 800) (draw-solid-rect (make-posn 0 700) 800 100 'black) ; Toolbar ;Character name, not that it matters! (define character-name (get-answer "By what name would you like to be called?" 5)) (cond [(string=? "Frodo" character-name) (and (draw-solid-string (make-posn 40 40) "Good choice.") (sleep-for-a-while 1.5) (clear-solid-string (make-posn 40 40) "Good choice."))] [else (and (draw-solid-string (make-posn 40 40) "Too bad, your name is Frodo") (sleep-for-a-while 2) (clear-solid-string (make-posn 40 40) "Too bad, your name is Frodo"))]) ;Purpose - To draw the only ring ;Contract posn int int symbol -> boolean (define (draw-ring posn radius1 radius2 insidecolor) (and (draw-solid-disk posn radius1 'gold) (draw-solid-disk posn radius2 insidecolor))) ;Purpose - To print out lists of strings. Recursively going through the list and printing the first. ;Contract - int list -> boolean (define (msg-repeat posn-y list) (cond [(empty? list) (sleep-for-a-while 2)] [else (and (draw-solid-string (make-posn 40 posn-y) (first list)) (msg-repeat (+ posn-y 19) (rest list)))])) ;Purpose - To clear the list of strings ;Contract - int list -> boolean (define (clear-msg-repeat posn-y list) (cond [(empty? list) (sleep-for-a-while 1)] [else (and (clear-solid-string (make-posn 40 posn-y) (first list)) (clear-msg-repeat (+ posn-y 19) (rest list)))])) ;Purpose - To spam and make the player feel inadequate. :D ;Contract - int int -> boolean (define (game-over n initialspeed) (cond [(= n 0) (and (sleep-for-a-while 10) (stop))] [else (and (draw-solid-string (make-posn (- (random 790) 10) (random 700)) "You LOSE!") (sleep-for-a-while initialspeed) (game-over (- n 1) (/ initialspeed 1.2)))])) ;Purpose - Our win message! Yay. ;Contract - int int -> boolean (define (you-win n initialspeed) (cond [(= n 0) (and (sleep-for-a-while 10) (stop))] [else (and (draw-solid-string (make-posn (- (random 790) 10) (random 700)) "You WIN!") (sleep-for-a-while initialspeed) (you-win (- n 1) (/ initialspeed 1.2)))])) ;Our little intro message to set the mood (define intro (list "You are a hobbit. Bummer." "You live in the Shire, which is in Middle Earth." "Middle Earth has been peaceful for some time." "However, you have recently been drafted into the fight against Lord Sauron." "He has been amassing an army in Mordor." "He plans to take over Middle Earth, but needs the Only Ring to do this." "Your mission, if you choose to accept it, is to take the ring to Doom Mountain and throw it in" "the lava." "" "...Intense. You best get started.")) (msg-repeat 40 intro) (sleep-for-a-while 8) (clear-msg-repeat 40 intro) ;Their first item choice, sort of! (define firstchoice (get-choice "What would you like to bring to Doom Mountain with you today?" item-choices1)) (draw-solid-string (make-posn 30 30) "You have acquired The Only Ring! Good job... It looks very tempting.") (draw-ring (make-posn 400 380) 300 225 'white) (sleep-for-a-while 5) (clear-solid-string (make-posn 30 30) "You have acquired The Only Ring! Good job... It looks very tempting.") (clear-solid-disk (make-posn 400 380) 300 'gold) (draw-solid-disk (make-posn 400 380) 225 'white) (draw-ring (make-posn 50 750) 25 18 'black) ; Toolbar ring (define hi (list "You test out the ring." "You become invisible! Awesome! And theres a weird floating eye thing." "You spend the next four days watching people shower." "Now that you have accomplished your childhood dreams, you think its time to go.")) ; Anne in no way condones or promotes people watching others shower while they are invisible. (msg-repeat 40 hi) (sleep-for-a-while 7) (clear-msg-repeat 40 hi) (define places (list "Dells" "Doom Mountain")) (define secondchoice (get-choice "Where would you like to go today" places)) (define msg1 (cond [(string=? "Doom Mountain" secondchoice) "Nobody wants to read a 70 page story, you head to the Wisconsin Dells."] [(string=? "Dells" secondchoice) "This is the first stop on your journey. The Nazgul chase you all the way there!"])) (draw-solid-string (make-posn 30 30) msg1) (sleep-for-a-while 6) (clear-solid-string (make-posn 30 30) msg1) (define dellslist (list "You arrive at the Wisconsin Dells. There is an entrance fee." "You waste a lot of time and don't have very much fun." "But you do find some shiny chainmail at a gift shop!")) (msg-repeat 40 dellslist) (draw-solid-rect (make-posn 200 200) 400 200 'pink) ;; Chainmail (draw-solid-line (make-posn 200 200) (make-posn 400 300)) (draw-solid-line (make-posn 400 300) (make-posn 600 200)) (sleep-for-a-while 8) (clear-msg-repeat 40 dellslist) (clear-solid-rect (make-posn 200 200) 400 200 'pink) (clear-solid-line (make-posn 200 200) (make-posn 400 300)) (clear-solid-line (make-posn 400 300) (make-posn 600 200)) (draw-solid-rect (make-posn 100 750) 50 25 'pink) ;; Toolbar Chainmail (draw-solid-line (make-posn 100 750) (make-posn 125 767)) (draw-solid-line (make-posn 125 767) (make-posn 150 750)) (draw-solid-string (make-posn 30 30) "After you receive your chainmail you decide to leave the Dells.") (sleep-for-a-while 5) (clear-solid-string (make-posn 30 30) "After you receive your chainmail you decide to leave the Dells.") (define anotherlist (list "You travel quite some distance and start to get weary." "Perhaps taking those sleeping pills before leaving wasn't a good idea." "Luckily, up ahead lies Weathertop!" "It looks like a nice place to stay." "Its very cloudy and dark." "There is a small entrance fee.")) (msg-repeat 40 anotherlist) (sleep-for-a-while 7) (clear-msg-repeat 40 anotherlist) (define wtopchoice (get-choice "Would you like to start a fire to warm your hairy toes?" yesno)) (define wtopstring (cond [(string=? "Yes" wtopchoice) (list "You start a warm fire at the top of Weathertop. Feels good." "The fire can be seen for miles and miles away." "As you are about to fall asleep, the Nazgul jump out and say 'BOO'" "AHHH!" "You cry a little as you get stabbed in the shoulder. That jerkface." "Luckily, Viggo Mortensen saves the day. His rugged good looks scare off the beasts.")] [else (list "You wake up shortly after falling asleep. You really have to pee." "REALLY have to pee." "In your haste to relieve yourself, you step on a sharp rock." "Ow! That really hurt." "You hop around on one leg and accidentally slip!" "You fall off of Weathertop to your death." "The Nazgul get the ring and all of your friends and family die." "As you fall one thought clouds your mind...")])) (cond [(string=? "Yes" wtopchoice) (and (msg-repeat 40 wtopstring) (sleep-for-a-while 10) (clear-msg-repeat 40 wtopstring))] [else (and (msg-repeat 40 wtopstring) (sleep-for-a-while 10) (clear-msg-repeat 40 wtopstring) (game-over 6000 2))]) (cond [(string=? "No" wtopchoice) true] [else (and (draw-solid-string (make-posn 40 40) "You have acquired a scar. Think of all the babes you'll get!") (draw-solid-line (make-posn 250 250) (make-posn 550 550) 'red) (draw-solid-line (make-posn 251 251) (make-posn 551 551) 'purple) (sleep-for-a-while 4) (clear-solid-line (make-posn 250 250) (make-posn 550 550) 'red) (clear-solid-line (make-posn 251 251) (make-posn 551 551) 'purple) (clear-solid-string (make-posn 40 40) "You have acquired a scar. Think of all the babes you'll get!") (draw-solid-line (make-posn 200 720) (make-posn 250 780) 'red) (draw-solid-line (make-posn 201 721) (make-posn 251 781) 'purple))]) (define places2 (list "Riverdale" "Lothlorrreean")) (define thirdchoice (if (string=? "No" wtopchoice) true (get-choice "Which of the pansy elves would you like to visit?" places2))) (define msg2 (cond [(string=? "No" wtopchoice) true] [(string=? "Riverdale" thirdchoice) (list "You decide to visit the Elven city of Riverdale." "There is an entrance fee." "Here you meet up with Gandalf, Aragorn, and other members of your party." "You get a delicious meal and a good night's rest after your long journey. It's awesome." "After your night of rest you visit your uncle Bilbo. He looks old. He has something for you...")] [(string=? "Lothlorrreean" thirdchoice) (list "You decide to visit the Elven city of Lothlorrreean, in the Elven forest." "There is an outrageous entrance fee, you are insulted." "Here you and the rest of your party decide to sleep for the night." "During the night, one of the elves tries to take the ring from you!" "You calmly explain to the elf that this is your job, and that you must be the one to destroy it." "The elf nods in agreement and decides to offer you a gift for your journey.")])) ;check death condition (cond [(string=? "No" wtopchoice) true] [else (and (msg-repeat 40 msg2) (sleep-for-a-while 9) (clear-msg-repeat 40 msg2))]) (define fourthchoice (if (string=? "No" wtopchoice) true (get-choice "Would you like to see what he has for you?" yesno))) (define msg3 (cond [(string=? "No" wtopchoice) true] [(and (string=? "Yes" fourthchoice) (string=? "Riverdale" thirdchoice)) (list "Bilbo gives you Sting! It glows when its near an Orc, alerting them to your presence.")] [(and (string=? "Yes" fourthchoice) (string=? "Lothlorrreean" thirdchoice)) (list "The elf decides to give you three copper pieces, and a magical dagger." "It glows when orcs are NOT nearby. Handy.")] [(and (string=? "No" fourthchoice) (string=? "Lothlorrreean" thirdchoice)) (list "The elf decides to throw a handful of coins and a useless dagger at you!" "It really doesn't do anything for you, and randomly glows for no reason." "You collect these items anyway and bring them with you.")] [(and (string=? "No" fourthchoice) (string=? "Riverdale" thirdchoice)) (list "Bilbo stabs you! Then commits hara-kiri. You take the blade from his corpse.")])) ;check death condition (cond [(string=? "No" wtopchoice) true] [else (msg-repeat 40 msg3)]) ;Purpose - To draw Sting, or another dagger, depending on color ;COntract - symbol -> boolean (define (draw-sting color) (and (draw-solid-rect (make-posn 350 350) 80 20 color) (draw-solid-rect (make-posn 380 300) 20 50 color) (draw-solid-line (make-posn 370 370) (make-posn 390 550) color) (draw-solid-line (make-posn 390 550) (make-posn 410 370) color))) ;Purpose to draw a dagger for our toolbar ;Contract symbol -> boolean (define (draw-ministing color) (and (draw-solid-rect (make-posn 300 750) 20 5 color) (draw-solid-rect (make-posn 307 730) 6 20 color) (draw-solid-line (make-posn 308 755) (make-posn 310 770) color) (draw-solid-line (make-posn 310 770) (make-posn 312 755) color))) ;Check death condition, check elven choice to decide weapon (and (string=? "Yes" wtopchoice) (string=? "Riverdale" thirdchoice) (draw-sting 'blue) (sleep-for-a-while 4) (clear-msg-repeat 40 msg3) (draw-ministing 'blue) (clear-solid-rect (make-posn 350 350) 80 20 'blue) (clear-solid-rect (make-posn 380 300) 20 50 'blue) (clear-solid-line (make-posn 370 370) (make-posn 390 550) 'blue) (clear-solid-line (make-posn 390 550) (make-posn 410 370) 'blue) ) (and (string=? "Yes" wtopchoice) (string=? "Lothlorrreean" thirdchoice) (draw-sting 'red) (sleep-for-a-while 4) (clear-msg-repeat 40 msg3) (draw-ministing 'red) (clear-solid-rect (make-posn 350 350) 80 20 'red) (clear-solid-rect (make-posn 380 300) 20 50 'red) (clear-solid-line (make-posn 370 370) (make-posn 390 550) 'red) (clear-solid-line (make-posn 390 550) (make-posn 410 370) 'red) ) (define Riverdale-list (list "Three days out of Riverdale, you notice Sting start to glow! Orcs are near!" "You hide in a bush located conveniently to your left." "A little too conveniently..." "You see orcs swarming around you." "One of them notices your blade glowing!" "Crap." "The last thought that runs through your mind is...")) ;Check death condition, check elven choice (and (string=? "Yes" wtopchoice) (string=? "Riverdale" thirdchoice) (draw-solid-string (make-posn 40 40) "You leave Riverdale, heading towards Doom Mountain, Sting in hand.") (sleep-for-a-while 2) (clear-solid-string (make-posn 40 40) "You leave Riverdale, heading towards Doom Mountain, Sting in hand.") (sleep-for-a-while .5) (msg-repeat 40 Riverdale-list) (sleep-for-a-while 7) (clear-msg-repeat 40 Riverdale-list) (game-over 1000 2)) (define gollummsg (list "As you leave the forest, you are ambushed in the night by Gollum!" "He demands that you give him back his precious.")) (if (string=? "No" wtopchoice) true (and (msg-repeat 40 gollummsg) (sleep-for-a-while 5) (clear-msg-repeat 40 gollummsg))) (define gollum (if (or (string=? "No" wtopchoice) (string=? "Riverdale" thirdchoice)) true (get-choice "What will you do?" (list "Kill him" "Give him the Only Ring")))) (define killhim (list "You grab the dagger you got from the elves and plunge it into his heart!" "" "" "You received 5 experience points!")) (define precious (list "You give Gollum the ring and return to the Shire." "Weeks later, orcish hordes swarm the countryside, killing everyone." "And its your fault." "You brandish your dagger and go out to fight them." "You don't last long." "As you are beheaded by an orc, a final thought clouds your mind...")) (cond [(or (string=? "No" wtopchoice) (string=? "Riverdale" thirdchoice)) true] [(string=? "Give him the Only Ring" gollum) (and (msg-repeat 40 precious) (sleep-for-a-while 7) (clear-msg-repeat 40 precious) (game-over 1000 2))] [else (and (msg-repeat 40 killhim) (sleep-for-a-while 7) (clear-msg-repeat 40 killhim) (draw-solid-rect (make-posn 300 700) 100 100 'black))]) ; Definition names are a little off, oops. (define HelmsDeep (list "You continue your journey to Doom Mountain. The next stop is Crown's Shallow." "This is an ancient fotress built into the cliffs of Middle Earth." "Here, residents from the city of Zohan have taken shelter." "However a horde of 10,000 Orcs are on their way to attack the fortress." "This is an epic battle scene, and basically makes the second movie worth watching." "You arrive just minutes before the battle begins.")) (define HelmsDeep2 (list "You don your chainmail as you stand on the battlements." "The orcs run forward!" "A stray arrow nicks off your armor." "You try to run away and hide, but the armor is too restricting, so you take it ofhttp://start.fedoraproject.org/f." "The ladies are impressed by your scar.")) (define AfterHelmsD (list "While you were macking on all the elves, you receive word that the Orcs were driven off!" "And that your friends died." "And most of your family too." "Sad day :'(" "Well, off to meet Duke Sauron!")) (define TheEnd (list "Alas! Doom Mountain. There are some orcs." "You are tired of this long movie/book and hurriedly scramble up the side.")) ;Purpose: Helper function for our lava ;Contract symbol symbol -> boolean (define (draw-LAVA topbotColor midColor) (and (draw-solid-rect (make-posn 0 0) 900 150 topbotColor) (draw-solid-rect (make-posn 0 150) 900 400 midColor) (draw-solid-rect (make-posn 0 550) 900 150 topbotColor))) ;Various checks and string writes (and (string=? "Yes" wtopchoice) (string=? "Lothlorrreean" thirdchoice) (string=? "Kill him" gollum) (msg-repeat 40 HelmsDeep) (sleep-for-a-while 10) (clear-msg-repeat 40 HelmsDeep) (msg-repeat 40 HelmsDeep2) (sleep-for-a-while 10) (clear-msg-repeat 40 HelmsDeep2) (draw-solid-rect (make-posn 100 750) 50 25 'black) (msg-repeat 40 AfterHelmsD) (sleep-for-a-while 6) (clear-msg-repeat 40 AfterHelmsD) (msg-repeat 40 TheEnd) (sleep-for-a-while 6) (clear-msg-repeat 40 TheEnd) (draw-solid-string (make-posn 200 200) "You reach the top.") (sleep-for-a-while 6) (clear-solid-string (make-posn 200 200) "You reach the top.") (sleep-for-a-while 2) (draw-solid-string (make-posn 200 200) "You see a convenient entrance to the inside.") (sleep-for-a-while 6) (clear-solid-string (make-posn 200 200) "You see a convenient entrance to the inside.") (sleep-for-a-while 2) (draw-solid-string (make-posn 200 200) "You go in.") (sleep-for-a-while 6) (clear-solid-string (make-posn 200 200) "You go in.") (sleep-for-a-while 2) (draw-solid-string (make-posn 200 200) "It sure is hot.") (sleep-for-a-while 6) (clear-solid-string (make-posn 200 200) "It sure is hot.") (sleep-for-a-while 2) (draw-solid-string (make-posn 200 200) "Whew. You are sweaty. And you smell bad.") (sleep-for-a-while 6) (clear-solid-string (make-posn 200 200) "Whew. You are sweaty. And you smell bad.") (sleep-for-a-while 2) (draw-solid-string (make-posn 200 200) "You apply some elven deodorant to your armpit.") (sleep-for-a-while 6) (clear-solid-string (make-posn 200 200) "You apply some elven deodorant to your armpit.") (sleep-for-a-while 2) (draw-solid-string (make-posn 200 200) "You trudge on.") (sleep-for-a-while 6) (clear-solid-string (make-posn 200 200) "You trudge on.") (sleep-for-a-while 2) (draw-LAVA 'brown 'red) (draw-solid-string (make-posn 200 200) "You get to the end of the path. Looking down you see lava.") (sleep-for-a-while 6) (clear-solid-string (make-posn 200 200) "You get to the end of the path. Looking down you see lava.") (draw-LAVA 'brown 'red) (sleep-for-a-while 2) ) (define lavalist (list "The Only Ring" "A nearby rock" "An innocent bystander" "A baby seal" "Samwise Gamgee" "Peter Jackson" "Your underwear" "Yourself")) ;Questioning player what they want to drop in lava, checks to see if previous two death options were passed. (define mtnchoice (if (or (string=? "No" wtopchoice) (string=? "Riverdale" thirdchoice) (string=? "Give him the Only Ring" gollum)) "Lose" (get-choice "What would you like to drop into the lava?" lavalist))) (cond [(string=? "Lose" mtnchoice) true] [(string=? "The Only Ring" mtnchoice) (and (draw-solid-string (make-posn 200 200) "You take the ring and drop it into the lava.") (sleep-for-a-while 6) (clear-solid-string (make-posn 200 200) "You take the ring and drop it into the lava.") (draw-LAVA 'brown 'red) (sleep-for-a-while 2) (draw-solid-disk (make-posn 50 750) 26 'black) ; Removing ring from toolbar (draw-ring (make-posn 350 350) 200 150 'red) (sleep-for-a-while 2) (draw-LAVA 'brown 'red) (draw-ring (make-posn 350 350) 150 110 'red) (sleep-for-a-while 2) (draw-LAVA 'brown 'red) (draw-ring (make-posn 350 350) 100 70 'red) (sleep-for-a-while 2) (draw-LAVA 'brown 'red) (draw-ring (make-posn 350 350) 50 38 'red) (sleep-for-a-while 2) (draw-LAVA 'brown 'red) (you-win 1000 2) )] [else (and (draw-solid-string (make-posn 200 200) "What are you, stupid?") (sleep-for-a-while 4) (clear-solid-string (make-posn 200 200) "What are you, stupid?") (game-over 1000 2))])