;; 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 |Game Final|) (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"))))) ;;Michael Hoffman ;;Andrew Reiman ;;Paul Brandt ;;Game Project ;; 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 5) (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)]) ]) )) ;;Island Hopping ;;The object of the game is to collect all the pieces of a radio. The player will start in the center Island in which we name Indy. They will then pick a resource that will take them to a certain Island. At this island they will be able to find one part of the radio. In order to win they need to collect all the parts of the radio. When this occurs the player wins and a helicopter will come and take you to Csci Island. You then have won the game. ;;This will collect the name of the character playing the game. (define character-name (get-answer "What's your name?" 5)) ;Create a canvas to draw the different islands (start 500 500) ;;Create a structure in order to be able to draw a circle. (define-struct circle (center radius color)) ;;Contract: draw-a-circle: a circle -> boolean ;;Purpose: To take a circle and draw it on a canvas. (define (draw-a-circle a-circle) (draw-solid-disk (circle-center a-circle) (circle-radius a-circle) (circle-color a-circle))) ;;To create a drawing of the different islands for the game. (define board (and (draw-solid-rect (make-posn 0 0) 500 500 'blue) (draw-a-circle (make-circle (make-posn 250 50) 30 'black)) (draw-a-circle (make-circle (make-posn 450 450) 30 'green)) (draw-a-circle (make-circle (make-posn 50 450) 30 'yellow)) (draw-a-circle (make-circle (make-posn 250 250) 30 'brown)))) ;;The names of the different Islands of the games. (define islands (list "Indy" "Pine" "Blakely" "Spooner")) ;;Person starts on Island Indy ;;The definition of the different resources. (define resources (list "canoe" "jetpack" "airplane" "dolphin" "cannon" "submarine")) ;;Definition of the drawing of a helicopter. The helicopter will come when you have collected all the parts of the radio. (define (helicopter x) (and (start 400 400) (draw-solid-rect (make-posn 0 0) 400 400 'blue) (draw-solid-disk (make-posn 150 200) 60 'black) (draw-solid-rect (make-posn 150 195) 200 30 'black) (draw-solid-rect (make-posn 340 175) 20 50 'black) (draw-solid-rect (make-posn 123 253) 10 30 'black) (draw-solid-rect (make-posn 162 253) 10 30 'black) (draw-solid-rect (make-posn 97 283) 100 10 'black) (draw-solid-disk (make-posn 120 170) 22 'white) (draw-solid-line (make-posn 80 145) (make-posn 205 75)) (draw-solid-line (make-posn 205 145) (make-posn 95 75)) (draw-solid-line (make-posn 147 105) (make-posn 147 150)) (draw-solid-rect (make-posn 170 200) 8 30 'red) (draw-solid-rect (make-posn 160 210) 30 8 'red))) ;;A structure which gives you where each resource will take you. (define-struct island-resource (island resource1 resource2)) ;;The master list of each island with its resource. (define master-list (list (make-island-resource "Pine" "dolphin" "submarine") (make-island-resource "Blakely" "jetpack" "airplane") (make-island-resource "Spooner" "cannon" "canoe"))) ;;A radio structure in which it gives you the radio part that you find on each island. (define-struct radio (island part)) ;;The list of radio part on each island. (define radio-list (list (make-radio "Pine" "antenna") (make-radio "Blakely" "battery") (make-radio "Spooner" "Radio Box"))) ;;Contract: look-up: list string -> string ;;Purpose: To take a resource and tell you the associated Island in which you will go. (define (look-up list1 resource) (cond [(empty? list) 'NoSuchIsland] [(or (string=? (island-resource-resource1 (first list1)) resource) (string=? (island-resource-resource2 (first list1)) resource)) (island-resource-island (first list1))] [else (look-up (rest list1) resource)] ) ) ;;Contract: look-up1: list string -> string ;;Purpose: To get the radio part on each Island that you will find. (define (look-up1 list1 island) (cond [(empty? list) 'NoSuchPart] [(string=? (radio-island (first list1)) island) (radio-part (first list1))] [else (look-up1 (rest list1) island)] ) ) ;;The drawing of the canoe. (define (canoe x) (and (start 400 400) (draw-solid-rect (make-posn 0 335) 400 100 'blue) (draw-solid-rect (make-posn 100 300) 180 45 'brown) (draw-solid-disk (make-posn 96 318) 25 'brown) (draw-solid-rect (make-posn 97 280) 35 20 'white) (draw-solid-disk (make-posn 283 318) 25 'brown) (draw-solid-rect (make-posn 250 280) 39 20 'white) (draw-solid-disk (make-posn 230 263) 15 'black) (draw-solid-line (make-posn 230 263) (make-posn 230 300) 'black) (draw-solid-line (make-posn 230 285) (make-posn 220 312) 'black) (draw-solid-rect (make-posn 209 310) 32 5 'tan) (draw-solid-rect (make-posn 241 307) 23 12 'tan) (draw-solid-disk (make-posn 80 60) 35 'yellow) (sleep-for-a-while 1) (stop))) ;;The drawing of the jetpack. (define (jetpack x) (and (start 400 400) (draw-solid-disk (make-posn 150 100) 20 'black) (draw-solid-line (make-posn 150 100) (make-posn 150 200) 'black) (draw-solid-line (make-posn 150 150) (make-posn 120 150) 'black) (draw-solid-line (make-posn 150 200) (make-posn 130 220) 'black) (draw-solid-line (make-posn 150 200) (make-posn 170 220) 'black) (draw-solid-rect (make-posn 151 125) 22 50 'blue) (draw-solid-disk (make-posn 157 179) 6 'red) (draw-solid-disk (make-posn 166 179) 6 'red) (draw-solid-line (make-posn 155 179) (make-posn 155 195) 'red) (draw-solid-line (make-posn 159 179) (make-posn 159 195) 'red) (draw-solid-line (make-posn 162 179) (make-posn 162 195) 'red) (draw-solid-line (make-posn 165 179) (make-posn 165 195) 'red) (draw-solid-line (make-posn 168 179) (make-posn 169 195) 'red) (draw-solid-rect (make-posn 0 350) 400 400 'green) (draw-solid-line (make-posn 100 350) (make-posn 75 300) 'tan) (draw-solid-line (make-posn 120 350) (make-posn 95 300) 'tan) (draw-solid-line (make-posn 194 350) (make-posn 235 300) 'tan) (draw-solid-line (make-posn 214 350) (make-posn 255 300) 'tan) (draw-solid-line (make-posn 234 350) (make-posn 275 300) 'tan) (draw-solid-line (make-posn 80 350) (make-posn 55 300) 'tan) (sleep-for-a-while 1) (stop))) ;;The airplane drawing. (define (airplane x) (and (start 500 500) (draw-solid-line (make-posn 100 240) (make-posn 350 240)) (draw-solid-line (make-posn 100 240) (make-posn 100 260)) (draw-solid-line (make-posn 350 240) (make-posn 350 260)) (draw-solid-line (make-posn 100 260) (make-posn 350 260)) (draw-solid-line (make-posn 250 240) (make-posn 200 200)) (draw-solid-line (make-posn 250 260) (make-posn 200 300)) (draw-solid-line (make-posn 200 200) (make-posn 200 240)) (draw-solid-line (make-posn 200 260) (make-posn 200 300)) (draw-solid-line (make-posn 100 240) (make-posn 100 200)) (draw-solid-line (make-posn 100 200) (make-posn 140 250)) (draw-solid-line (make-posn 350 240) (make-posn 360 250)) (draw-solid-line (make-posn 350 260) (make-posn 360 250)) (draw-solid-line (make-posn 140 250) (make-posn 100 250)) (sleep-for-a-while 1) (stop))) ;;The dolphin drawing. (define (dolphin x) (and (start 500 500) (draw-circle (make-posn 250 250) 100 'black) (draw-circle (make-posn 250 400) 200 'black) (draw-solid-rect (make-posn 0 225) 500 275 'white) (draw-solid-line (make-posn 250 150) (make-posn 225 125)) (draw-solid-line (make-posn 225 125) (make-posn 225 153.5)) (draw-solid-disk (make-posn 325 205) 5 'black) (sleep-for-a-while 1) (stop))) ;;The submarine drawing. (define (submarine x) (and (start 500 500) (draw-solid-rect (make-posn 0 250) 500 250 'blue) (draw-solid-disk (make-posn 100 400) 50 'red) (draw-solid-rect (make-posn 100 350) 300 100 'red) (draw-solid-disk (make-posn 400 400) 50 'red) (draw-solid-disk (make-posn 325 400) 25 'white) (draw-solid-disk (make-posn 175 400) 25 'white) (draw-solid-disk (make-posn 250 350) 25 'red) (draw-solid-disk (make-posn 250 350) 20 'white) (draw-solid-rect (make-posn 200 350) 140 25 'red) (draw-solid-disk (make-posn 75 75) 50 'yellow) (sleep-for-a-while 1) (stop))) ;;The cannon drawing. (define (cannon x) (and (start 400 400) (draw-solid-line (make-posn 100 200) (make-posn 300 100)) (draw-solid-line (make-posn 150 250) (make-posn 350 150)) (draw-solid-line (make-posn 100 200) (make-posn 150 250)) (draw-solid-line (make-posn 150 150) (make-posn 150 175)) (draw-solid-disk (make-posn 150 150) 5 'red) (draw-solid-disk (make-posn 175 225) 50 'brown) (draw-circle (make-posn 325 125) 34 'black) (sleep-for-a-while 1) (stop))) ;;Contract: draw-item: resource -> boolean ;;Purpose: To draw the given resource. (define (draw-item resource) (cond [(string=? resource "cannon") (cannon 1)] [(string=? resource "submarine") (submarine 1)] [(string=? resource "airplane") (airplane 1)] [(string=? resource "dolphin") (dolphin 1)] [(string=? resource "canoe") (canoe 1)] [(string=? resource "jetpack") (jetpack 1)] [else 'NoSuchResource] ) ) ;;A list that has your resource choice as its only element. (define resource-list1 (cons (get-choice "Choose your resource" resources) empty)) ;;Contract: acc-radio-list: list list string -> list ;;Purpose: To generate a list of the radio parts that you have collected. (define (acc-radio-list radio-list radio-list-rec radio-part) (cond [(empty? radio-list-rec) (append radio-list (list radio-part))] [(string=? radio-part (first radio-list-rec)) radio-list] [else (acc-radio-list radio-list (rest radio-list-rec) radio-part)] ) ) (define message19 (string-append character-name "has collected all the parts of the radio. The helicopter will now come and take you to Csci Island. You have WON the game ")) (define (win radio-list) (cond [(= (length radio-list) 3) (and (start 1500 200) (draw-solid-string (make-posn 20 20) message19) (sleep-for-a-while 3) (stop) (helicopter 1) (sleep-for-a-while 2) (exit))] [else false]) ) ;;To create a canvas that writes the item, Island and radio part that the play has collected. (define message1 (string-append character-name "has acquired the " (first resource-list1))) (draw-item (first resource-list1)) (start 700 300) (draw-solid-string (make-posn 20 20) message1) (define message2 (string-append character-name " is now moving to " (look-up master-list (first resource-list1)))) (define message3 (string-append character-name " has now collected the " (look-up1 radio-list (look-up master-list (first resource-list1))))) (draw-solid-string (make-posn 20 40) message2) (draw-solid-string (make-posn 20 60) message3) (sleep-for-a-while 5) (define radio1 (acc-radio-list empty empty (look-up1 radio-list (look-up master-list (first resource-list1))))) (stop) ;;Contract: new-list: list string -> list ;;Purpose: To eliminate the resource from the given list. (define (new-list list1 resource) (cond [(empty? list) list1] [(string=? resource (first list1)) (rest list1)] [else (append (list (first list1)) (new-list (rest list1) resource))] ) ) ;;To reset the list resources by taking out the already choosen resource. (set! resources (new-list resources (first resource-list1))) ;;To get the second resource that is selected and put it into a list. (define resource-list2 (cons (get-choice "Choose your resource" resources) empty)) ;;To create a canvas that writes the item, Island and radio part that the play has collected in their second choice. (draw-item (first resource-list2)) (start 700 300) (define message4 (string-append character-name "has acquired the " (first resource-list2))) (draw-solid-string (make-posn 20 20) message4) (define message5 (string-append character-name " is now moving to " (look-up master-list (first resource-list2)))) (define message6 (string-append character-name " has now collected the " (look-up1 radio-list (look-up master-list (first resource-list2))))) (draw-solid-string (make-posn 20 40) message5) (draw-solid-string (make-posn 20 60) message6) (sleep-for-a-while 5) (stop) (define radio2 (acc-radio-list radio1 radio1 (look-up1 radio-list (look-up master-list (first resource-list2))))) ;;To reset the list resources by taking out the already choosen resource. (set! resources (new-list resources (first resource-list2))) ;;To get the third resource that is selected and put it into a list. (define resource-list3 (cons (get-choice "Choose your resource" resources) empty)) ;;To create a canvas that writes the item, Island and radio part that the play has collected in their third choice. (define message7 (string-append character-name " has acquired the " (first resource-list3))) (draw-item (first resource-list3)) (start 700 300) (draw-solid-string (make-posn 20 20) message7) (define message8 (string-append character-name " is now moving to " (look-up master-list (first resource-list3)))) (define message9 (string-append character-name " has now collected the " (look-up1 radio-list (look-up master-list (first resource-list3))))) (draw-solid-string (make-posn 20 40) message8) (draw-solid-string (make-posn 20 60) message9) (sleep-for-a-while 5) (stop) (define radio3 (acc-radio-list radio2 radio2 (look-up1 radio-list (look-up master-list (first resource-list3))))) (win radio3) ;;To reset the list resources by taking out the already choosen resource. (set! resources (new-list resources (first resource-list3))) ;;A list that has your fourth resource choice as its only element. (define resource-list4 (cons (get-choice "Choose your resource" resources) empty)) ;;To create a canvas that writes the item, Island and radio part that the play has collected in their second choice. (define message10 (string-append character-name " has acquired the " (first resource-list4))) (draw-item (first resource-list4)) (start 700 300) (draw-solid-string (make-posn 20 20) message10) (define message11 (string-append character-name " is now moving to " (look-up master-list (first resource-list4)))) (define message12 (string-append character-name " has now collected the " (look-up1 radio-list (look-up master-list (first resource-list4))))) (draw-solid-string (make-posn 20 40) message11) (draw-solid-string (make-posn 20 60) message12) (sleep-for-a-while 5) (define radio4 (acc-radio-list radio3 radio3 (look-up1 radio-list (look-up master-list (first resource-list4))))) (win radio4) (stop) ;;To reset the list resources by taking out the already choosen resource. (set! resources (new-list resources (first resource-list4))) ;;A list that has your fifth resource choice as its only element. (define resource-list5 (cons (get-choice "Choose your resource" resources) empty)) ;;To create a canvas that writes the item, Island and radio part that the play has collected. (define message13 (string-append character-name "has acquired the " (first resource-list5))) (draw-item (first resource-list5)) (start 700 300) (draw-solid-string (make-posn 20 20) message13) (define message14 (string-append character-name " is now moving to " (look-up master-list (first resource-list5)))) (define message15 (string-append character-name " has now collected the " (look-up1 radio-list (look-up master-list (first resource-list5))))) (draw-solid-string (make-posn 20 40) message14) (draw-solid-string (make-posn 20 60) message15) (sleep-for-a-while 5) (define radio5 (acc-radio-list radio4 radio4 (look-up1 radio-list (look-up master-list (first resource-list5))))) (win radio5) (stop) ;;To reset the list resources by taking out the already choosen resource. (set! resources (new-list resources (first resource-list5))) ;;A list that has your sixth resource choice as its only element. (define resource-list6 (cons (get-choice "Choose your resource" resources) empty)) ;;To create a canvas that writes the item, Island and radio part that the play has collected. (define message16 (string-append character-name " has acquired the " (first resource-list6))) (draw-item (first resource-list6)) (start 700 300) (draw-solid-string (make-posn 20 20) message16) (define message17 (string-append character-name " is now moving to " (look-up master-list (first resource-list6)))) (define message18 (string-append character-name " has now collected the " (look-up1 radio-list (look-up master-list (first resource-list6))))) (draw-solid-string (make-posn 20 40) message17) (draw-solid-string (make-posn 20 60) message18) (sleep-for-a-while 5) (stop) (define radio6 (acc-radio-list radio5 radio5 (look-up1 radio-list (look-up master-list (first resource-list6))))) (win radio6) (stop)