;; 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-advanced-reader.ss" "lang")((modname biggameproject) (read-case-sensitive #t) (teachpacks ((lib "hangman.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "hangman.ss" "teachpack" "htdp") (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 (time-delay) is the number of seconds ;; the function waits after the typing of the first character ;; before it returns the answer. If the user takes longer ;; than that, a partial answer may be returned ;; 5 sec delay is reasonable for a one-word answer (define (get-answer question time-delay) (local ((define the-answer (make-text question)) (define w (create-window (list (list the-answer) (list (make-button "Close" (lambda (e) (hide-window w))))))) (define (process-result n) (cond [(> n 200) (hide-window w)] ;; timeout after 200 sec [(string=? (text-contents the-answer) "") (and (sleep-for-a-while 1) (process-result (+ n 1)))] [else true] ;; the user starts typing ))) (cond [(process-result 0) (cond [(sleep-for-a-while time-delay) (text-contents the-answer)]) ]) )) ;; =========================== do not change anything above this line ============= ;; NOTE: The language is Advanced Student. Teachpacks: gui.ss, draw.ss ;; =========================== Your work goes here: =============================== ;;Structure and List Definitions ;;the character structure has a name, tools, and health ;;name: a string that represents the character's name ;;supplise: a list of all the supplise the character has obtained ;;health:an integer that is less than or equal to 100 but greater than 0 (define-struct character(name supplise health)) ;;a character structure (define char1 (make-character "" empty 100)) ;;a list of all the characters the player can choose from (define char-list(list "Vern" "R.J." "Hammy" "Stella")) ;;a list of all the places the player can choose to explore (define location-list(list "pool" "Girl Scouts" "trash cans" "done exploring")) ;;function definitions ;;contract:list of strings int-> true ;;takes a list of strings and prints them each in a new line ;;definition: (define (text-printer alos height) (cond [(empty? alos)true] [else (and (draw-solid-string(make-posn 20 height)(first alos)) (text-printer (rest alos) (+ 20 height)))])) ;;contract: null->true ;;purpose:clears the frame ;;definition: (define(clear-frame) (draw-solid-rect(make-posn 0 0 ) 600 600 'white)) ;;contract:a list of strings(the locations) a-location->a list of strings(locations) ;;purpose:to take a list of locations and removes that location from the list ;;definition: (define(remove-location alol a-location) (cond [(empty? alol)empty] [(string=? (first alol)a-location)(remove-location (rest alol) a-location)] [else(cons (first alol) (remove-location (rest alol)a-location))])) ;;contract:item -> true ;;purpose:takes an item and adds it to the list that represents the supplise a character owns ;;definition: (define(change-supplise item) (begin(set-character-supplise! char1 (cons item (character-supplise char1))))) ;;contract:a list of locations a location->true ;;sets the list of locations to not have the location in it (define(change-location-list alol a-location) (set! location-list (remove-location alol a-location))) ;;picture definitions ;;contract:null->true ;;purpose:draws a picture that looks like a hedge on the frame ;;definition: (define (draw-hedge) (and (draw-solid-rect (make-posn 50 250)250 100 'green) (draw-solid-rect (make-posn 50 350)3 20 'brown) (draw-solid-rect(make-posn 75 350)3 20 'brown) (draw-solid-rect(make-posn 100 350)3 20 'brown) (draw-solid-rect(make-posn 125 350)3 20 'brown) (draw-solid-rect(make-posn 150 350)3 20 'brown) (draw-solid-rect(make-posn 175 350)3 20 'brown) (draw-solid-rect(make-posn 200 350)3 20 'brown) (draw-solid-rect(make-posn 225 350)3 20 'brown) (draw-solid-rect(make-posn 250 350)3 20 'brown) (draw-solid-rect(make-posn 275 350)3 20 'brown) (draw-solid-rect(make-posn 295 350)3 20 'brown))) ;;contract:null->true ;;purpose:draws a picture that looks like a wagon on the frame ;;definition: (define (draw-wagon) (and (draw-solid-rect(make-posn 100 250)150 20 'red) (draw-solid-disk(make-posn 100 270) 10 'black) (draw-solid-disk(make-posn 250 270) 10 'black) (draw-solid-line(make-posn 250 250)(make-posn 300 200) 'black))) ;;contract:null->true ;;purpose:draws a picture that looks like an umbrella on the frame (define (draw-umbrella) (and (draw-solid-disk (make-posn 150 250)75 'blue) (draw-solid-rect(make-posn 50 250) 200 200 'white) (draw-solid-rect(make-posn 150 250)10 100 'black))) ;;frame definitions ;;displays the title and the text for frame 1 (define(frame1) (and (draw-solid-string game-title-posn game-title) (text-printer frame1-text 40) (sleep-for-a-while 5))) ;;assigns the name to the char1 structure (define(frame1.1) (begin(set-character-name! char1(get-choice "Which character would you like to be?" char-list)))) ;;prints the frame2 text and only continues if the user chooses to (define(frame2) (and (sleep-for-a-while 3) (clear-frame) (text-printer frame2-text 20) (local((define answer (get-choice "What would you like to do?" (list "explore" "quit")))) (cond [(string=? "explore" answer)(frame3)] [(string=? "quit" answer)(stop)])))) ;;prints the frame3 text, draws the hedge picture, and moves on to frame 4 (define (frame3) (and (clear-frame) (text-printer frame3-text 20) (sleep-for-a-while 5) (draw-hedge) (frame4))) ;;prints the frame4 text, prints the hedge picture, and only moves on if the user chooses to (define(frame4) (and (clear-frame) (text-printer frame4-text 20) (draw-hedge) (sleep-for-a-while 5) (local((define answer (get-choice "What would you like to do?" (list "see what's on the other side" "quit")))) (cond [(string=? "see what's on the other side" answer)(frame6)] [(string=? "quit" answer)(stop)])))) ;;prints the frame6 text and and moves to the location visiting chooser frame (define(frame6) (and (clear-frame) (text-printer frame6-text 20) (sleep-for-a-while 5) (local((define answer (get-choice "Where would you like to explore?" location-list))) (location-visiting-frames answer)))) ;;moves to whatever frame the user chose or moves on if the user chooses to (define (location-visiting-frames answer) (and (clear-frame) (cond [(string=? answer "pool")(frame7)] [(string=? answer "Girl Scouts") (frame8)] [(string=? answer "trash cans")(frame9)] [else(frame10)]))) ;;prints the frame7 text and draws the umbrella (define (frame7) (and (text-printer frame7-text 20) (draw-umbrella) (sleep-for-a-while 5) (local((define answer(get-choice "Where would you like to explore?" location-list))) (location-visiting-frames answer)))) ;;prints the frame8 text and draws the wagon pictue (define (frame8) (and (text-printer frame8-text 20) (draw-wagon) (sleep-for-a-while 5) (local((define answer(get-choice "Where would you like to explore?" location-list))) (location-visiting-frames answer)))) ;;prints the frame9 text (define (frame9) (and (text-printer frame9-text 20) (sleep-for-a-while 5) (local((define answer(get-choice "Where would you like to explore?" location-list))) (location-visiting-frames answer)))) ;;writes the frame10 text and uses the item the user chooses, moves to the correct frame (define(frame10) (and (clear-frame) (text-printer frame10-text 20) (sleep-for-a-while 5) (local((define answer(get-choice "Which item do you want to use?" (character-supplise char1)))) (cond [(string=? "Red Wagon" answer)(frame11)] [(string=? "Umbrella" answer)(deathFrame1)] [(string=? "Spuddies" answer) (deathFrame2)])))) ;;writes the frame11 text and uses the item the user chooses, moves to correct frame (define(frame11) (and (clear-frame) (text-printer frame11-text 20) (draw-wagon) (sleep-for-a-while 5) (local((define answer(get-choice "Which item do you want to use?" (list "Umbrella" "Spuddies")))) (cond [(string=? "Umbrella" answer)(frame12)] [(string=? "Spuddies" answer) (deathFrame2)])))) ;;writes the frame12 text and moves on to the correct frame (define(frame12) (and (clear-frame) (text-printer frame12-text 20) (draw-umbrella) (sleep-for-a-while 5) (local((define answer(get-choice "Which item do you want to use?" (list "Spuddies" "Give up now")))) (cond [(string=? "Spuddies" answer) (frame13)] [else(deathFrame3)])))) ;;writes the frame13 text (define(frame13) (and (clear-frame) (text-printer frame13-text 20) (sleep-for-a-while 5))) ;;writes the frame14 text (define(frame14) (and (clear-frame) (text-printer frame14-text 20) (sleep-for-a-while 5) (stop))) ;;writes the deathFrame1 text and ends game (define(deathFrame1) (and (clear-frame) (text-printer deathFrame1-text 20) (draw-umbrella) (sleep-for-a-while 5))) ;;writes the deathFrame2 text and ends game (define(deathFrame2) (and (clear-frame) (text-printer deathFrame2-text 20) (sleep-for-a-while 5))) ;;writes the deathFrame3 text and ends game (define(deathFrame3) (and (clear-frame) (text-printer deathFrame3-text 20) (sleep-for-a-while 5))) ;;text list definitions ;;the location of the title in the frame (define game-title-posn (make-posn 60 20)) ;; the words that are the title of the game (define game-title "Over the Hedge (the game)") ;; the text for frame 1 (define frame1-text (list "Welcome to Over the Hedge (the game)! Which character " "would you like to play as? You could be R.J., the wise-talking" "raccoon. Or you could be Vern, the hesitant turtle. Or you" "could play as Hammy, the hyperactive squirrel. Or Stella, " "the tough-talking skunk.")) ;; the text for frame 2 (define frame2-text (list "You used to live in a quiet forest without any humans to bug" "you. But when you woke up this spring, you realized that a" "huge suburb had been built all around you. You need to start" "gathering food for next winter so you don't starve, but there is" "much less forest to scavenge then there used to be.")) ;; the text for frame 3 (define frame3-text(list "I have decided that we need to search for some food, you say." "But, what if the humans took all of the food, Ozzie the possum" "said. Well, you say, we will just have to see what we find. You" "started searching the forrest for food, but had no luck until" "you came upon a giant green hedge.")) ;; the text for frame 4 (define frame4-text(list "Wh-wha-what is this thing? you asked nervously. I think it" "is some sort of monster, Lou the porcupine replied. I think it" "is some sort of bush, R.J. the raccoon stated. What should" "we do? Lou's wife Penny asked.")) ;; the text for frame 6 (define frame6-text(list "When the brave explorers went through the hedge, they" "discovered a world very different than what they were used to. The" "hedge led to a beautiful house. There were Girl Scouts selling" "cookies, trash cans, and even a pool. The animals were" "stunned, they had never seen anything like this before. What do" "you want to explore first?")) ;; the text for frame 7 (define frame7-text(list "You wander over to what looks like a small, very clear lake.""I've heard of these things before, R.J. says. They're called pools." "Everyone is very curious and examines the pool. Look what" "I found! Hammy exclaims. He has found a pool umbrella. Why don't" "we take that with us, just in case we need it later, Vern says.")) ;; the text for frame 8 (define frame8-text(list"You wander over to where two young girls are sitting with" "a red wagon. Inside the red wagon are dozens of boxes of" "Girl Scout cookies. The boxes look too difficult to open," "but their wagon looks like it could come in handy later." "Stella skunks the girls and they run away. R.J. removes all" "of the cookies from the wagon and Hammy takes the wagon.")) ;; the text for frame 9 (define frame9-text(list "You see these gigantic gleaming cans, and decide they might" "have something fun to discover. Once you tip them over," "you find that they are full of partially-eaten, delicious-looking" "food. You see an almost-full can of Spuddies and decide that it" "might come in handy later.")) ;; the text for frame 10 (define frame10-text(list"You have explored all that there is to see in this area, and you" "were just heading back through the hedge to get back home" "when all of a sudden, a bear jumped from through the hedge" "and attacked! You have been gathering items all morning," "will any help you now?")) ;; the text for frame 11 (define frame11-text(list"Everyone leaps onto the wagon, and you start running and" "pulling the wagon as fast as you can. Once you get enough" "speed, you leap onto the wagon as it races along the road." "The bear keeps following you, and you only seem to feel like" "you are pulling away from it as you race down a giant hill." "Suddenly, you realize that at the bottom of the hill is a cliff!" "And you’re racing right towards it! Use one of your items to" "try and save you!")) ;; the text for frame 12 (define frame12-text(list "Everyone grabs onto the umbrella’s pole as the wind opens it" "up. Everyone celebrates your success as you safely float down" "to the ground. That bear wouldn’t be dumb enough to follow" "you off the cliff! As you slowly descend, you realize that the" "bear has climbed down the cliff, and is waiting to meet you at" "the bottom! Is there any items you could use to save you now?")) ;; the text for frame 13 (define frame13-text(list"As you safely land at the bottom of the cliff, you bravely" "venture towards the bear. I hope this works, you think to" "yourself. You offer the bear your can of Spuddies, hoping it" "would be enough to calm him down. Please, you say to the" "bear, all we have left is this can of Spuddies. If we give them to" "you, will you let us go?")) ;; the text for frame 14 (define frame14-text (list"The bear considers your offer for a moment, and then decides" "to let everyone go in exchange for the Spuddies." "Congratulations! You have defeated the bear!")) ;;the text for deathFrame1 (define deathFrame1-text (list "The bear looks at you as you hold out the umbrella to defend" "yourselves. He suddenly grabs the umbrella with his front paws" "and breaks it in half. Then, the bear eats you. You Loose.")) ;;the text for deathFrame2 (define deathFrame2-text (list"The bear grabs for the Spuddies that you cautiously offer him." "In a single second, he eats the entire can. But, he must have still" "been hungry because he eats you too. You Loose." )) ;;the text for deathFrame3 (define deathFrame3-text (list"The bear laughs at your petty attempt to escape with your life." "If only you had something more substantial to offer him. He" "eats you. You Loose." )) ;;the actual game ;;the start of the game, opens a frame 400x400 pixles (start 400 400) ;;runs frame1 (frame1) ;;runs frame1.1 (frame1.1) ;;sets the supplise the character has to include "Red Wagon" "Umbrella" and "Spuddies" (begin(set-character-supplise! char1 (list "Red Wagon" "Umbrella" "Spuddies"))) ;;runs frame2 (2-14 runs from inside the previous frame (frame2) ;;runs frame 14 (frame14)