;; 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 AndresAlec) (read-case-sensitive #t) (teachpacks ((lib "guess-gui.ss" "teachpack" "htdp") (lib "master.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "guess-gui.ss" "teachpack" "htdp") (lib "master.ss" "teachpack" "htdp") (lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))))) ;;This program was brought to you by Alec Mohn, Andres Branstetter, and the Number 4! (start 500 500) ;;helper function that draws walls (define (wall left-bottom right-bottom h color) (cond [(= h 0) (draw-solid-rect (make-posn (posn-x left-bottom) 0) (posn-x right-bottom) (max (posn-y right-bottom) (posn-y left-bottom)) 'brown)] [else (and (draw-solid-line left-bottom right-bottom color) (wall (make-posn (posn-x left-bottom) (- (posn-y left-bottom) 1)) (make-posn (posn-x right-bottom) (- (posn-y right-bottom) 1)) (- h 1) color))])) ;;Hallway (define (hallway x) (and (wall (make-posn 0 300) (make-posn 200 150) 150 'brown) (draw-solid-rect (make-posn 200 0) 150 150 'black) (wall (make-posn 350 150) (make-posn 500 300) 150 'brown))) ;;Door (define (door x) (and (wall (make-posn 0 300) (make-posn 200 150) 150 'brown) (draw-solid-rect (make-posn 200 0) 150 150 'brown) (wall (make-posn 350 150) (make-posn 500 300) 150 'brown) (draw-solid-line (make-posn 200 0) (make-posn 200 150) 'black) (draw-solid-line (make-posn 350 0) (make-posn 350 150) 'black) (draw-solid-rect (make-posn 200 10) 150 20 'black) (draw-solid-disk (make-posn 320 75) 10 'black) (draw-solid-rect (make-posn 200 120) 150 20 'black))) ;;Hallway with brick (define (hallway-b x)(and (wall (make-posn 0 300) (make-posn 200 150) 150 'brown) (draw-solid-rect (make-posn 200 0) 150 150 'black) (wall (make-posn 350 150) (make-posn 500 300) 150 'brown) (draw-solid-rect (make-posn 250 200) 10 20 'red))) ;;deadend hallway (define (deadend x) (and (wall (make-posn 0 300) (make-posn 200 150) 150 'brown) (draw-solid-rect (make-posn 200 0) 150 150 'brown) (wall (make-posn 350 150) (make-posn 500 300) 150 'brown) (draw-solid-line (make-posn 200 0) (make-posn 200 150) 'black) (draw-solid-line (make-posn 350 0) (make-posn 350 150) 'black))) ;;4 way intersecting hall (define (int-hall x) (and (wall (make-posn 100 150) (make-posn 200 75) 75 'brown) (draw-solid-rect (make-posn 200 0) 150 75 'black) (wall (make-posn 350 75) (make-posn 400 150) 75 'brown) (wall (make-posn 0 300) (make-posn 75 225) 75 'brown) (wall (make-posn 425 225) (make-posn 500 300) 75 'brown) (draw-solid-rect (make-posn 0 0) 100 150 'brown) (draw-solid-rect (make-posn 400 0) 100 150 'brown) (draw-solid-line (make-posn 100 0) (make-posn 100 150) 'black) (draw-solid-line (make-posn 400 0) (make-posn 400 150) 'black))) ;;Choice box from site (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))]))) ;;Clear Canvas help function (define (clear-canvas x) (clear-solid-rect (make-posn 0 0) 500 500)) ;;chest (define (chest x) (and (draw-solid-rect (make-posn 220 200) 100 75 'brown) (draw-solid-line (make-posn 220 200) (make-posn 320 200) 'black) (draw-solid-line (make-posn 220 275) (make-posn 320 275) 'black) (draw-solid-line (make-posn 220 200) (make-posn 220 275) 'black) (draw-solid-line (make-posn 320 200) (make-posn 320 275) 'black) (draw-solid-disk (make-posn 270 215) 10 'black) (draw-solid-rect (make-posn 265 215) 10 20 'black))) ;;slime (define (slime x) (and (draw-solid-disk (make-posn 250 250) 30 'blue) (clear-solid-rect (make-posn 220 250) 60 30))) ;;item list (define item-list (list "sword" "key1" "key2" "key3" "the treasure")) ;;add item to list (define (add-item item next-action) (append item-list (list item))) ;;list=? helper function (define (list=? list1 list2) (cond [(and (empty? list1) (empty? list2)) true] [(string=? (first list1) (first list2)) (list=? (rest list1) (rest list2))] [else false])) ;;key check function (define (key-check item check-list) (cond [(empty? check-list) (get-choice "Missing Key! Choose another direction." (list "north" "west" "south" "east"))] [(string=? item (first check-list)) true] [else (key-check item (rest check-list))])) ;;item check function (define (item-check item check-list) (cond [(empty? check-list) false] [(string=? item (first check-list)) true] [else (item-check item (rest check-list))])) ;;starts game (define game-start (local ( ;;Hit/Miss helper function for player (define (p-hit-miss ehp) (cond [(and (item-check "sword" item-list) (> (random 4) 1)) (- ehp 20)] [(and (item-check "brick" item-list) (> (random 4) 1)) (- ehp 10)] [(= (random 4) 1) ehp] [(> (random 4) 1) (- ehp 5)] [else (p-hit-miss ehp)])) ;;hit/miss helper fuction for enemy (define (e-hit-miss php) (cond [(= (random 2) 1) php] [else (- php 10)])) ;;Fight (define (fight action php ehp after-fight) (cond [(= php 0) (and (string=? "Be a corpse!..." (get-choice "You Die!" (list "Be a corpse!..."))) (hallway 4) ((beginning (hallway 4) (get-choice "Which direction do you travel?" (list "south")))))] [(= ehp 0) after-fight] [(string=? action "fight") (fight "fight" (e-hit-miss php) (p-hit-miss ehp) after-fight)] [else true])) ;;Start location (define (beginning drawing direction) (cond [(string=? direction "south") (and (clear-canvas 4) (int-hall 4) (1-3 (get-choice "You have found a sword, and a key! Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (beginning (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) ;;Locations (define (1-1 direction) (cond [(string=? direction "east") (and (clear-canvas 4) (hallway 4) (1-2 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (1-1 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (1-2 direction) (cond [(string=? direction "west") (and (1-2 (item-check "key1" item-list)) (clear-canvas 4) (deadend 4) (slime 4) (fight (get-choice "A slime!" (list "fight")) 100 75 (1-1 (get-choice "You Survive! Which direction do you travel?" (list "north" "west" "south" "east")))))] [(string=? direction "east") (and (clear-canvas 4) (int-hall 4) (1-3 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (1-2 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (1-3 direction) (cond [(string=? direction "north") (and (clear-canvas 4) (hallway 4) (beginning (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "west") (and (clear-canvas 4) (door 4) (1-2 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "south") (and (clear-canvas 4) (door 4) (2-1 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "east") (and (clear-canvas 4) (hallway 4) (1-4 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (1-3 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (1-4 direction) (cond [(string=? direction "west") (and (clear-canvas 4) (int-hall 4) (1-3 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "east") (and (clear-canvas 4) (hallway-b 4) (1-5 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (1-4 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (1-5 direction) (cond [(string=? direction "look for item") (append item-list (list "brick"))] [(string=? direction "west") (and (clear-canvas 4) (hallway 4) (1-4 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "east") (and (clear-canvas 4) (deadend 4) (fight (get-choice "A bat!" (list "fight")) 100 50 (1-6 (get-choice "You Survive! Which direction do you travel?" (list "north" "west" "south" "east")))))] [else (1-5 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (1-6 direction) (cond [(string=? direction "west") (and (clear-canvas 4) (hallway-b 4) (item-check "key1" item-list) (1-5 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (1-6 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (2-1 direction) (cond [(string=? direction "north") (and (clear-canvas 4) (int-hall 4) (1-3 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "south") (and (clear-canvas 4) (int-hall 4) (3-3 (get-choice "You have found a key! Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (2-1 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (2-2 direction) (cond [(string=? direction "south") (and (clear-canvas 4) (int-hall 4) (3-6 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (2-2 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (3-1 direction) (cond [(string=? direction "west") (and (clear-canvas 4) (hallway 4) (3-2 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (3-1 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (3-2 direction) (cond [(string=? direction "west") (and (clear-canvas 4) (deadend 4) (chest 4) (fight (get-choice "A bat!" (list "fight")) 100 50 (3-1 (get-choice "You Survive! Which direction do you travel?" (list "north" "west" "south" "east")))))] [(string=? direction "east") (and (clear-canvas 4) (int-hall 4) (3-3 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (3-2 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (3-3 direction) (cond [(string=? direction "north") (and (clear-canvas 4) (hallway 4) (2-1 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "west") (and (clear-canvas 4) (hallway 4) (3-2 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "south") (and (clear-canvas 4) (hallway 4) (4-1 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "east") (and (clear-canvas 4) (hallway 4) (3-4 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (3-3 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (3-4 direction) (cond [(string=? direction "west") (and (clear-canvas 4) (int-hall 4) (3-3 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "east") (and (clear-canvas 4) (hallway 4) (3-5 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (3-4 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (3-5 direction) (cond [(string=? direction "west") (and (clear-canvas 4) (hallway 4) (3-4 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "east") (and (clear-canvas 4) (int-hall 4) (3-6 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (3-5 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (3-6 direction) (cond [(string=? direction "north") (and (clear-canvas 4) (deadend 4) (slime 4) (fight (get-choice "A slime!" (list "fight")) 100 75 (2-2 (get-choice "You Survive! Which direction do you travel?" (list "north" "west" "south" "east")))))] [(string=? direction "west") (and (clear-canvas 4) (hallway 4) (3-5 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "south") (and (clear-canvas 4) (deadend 4) (slime 4) (fight (get-choice "A slime!" (list "fight")) 100 75 (4-2 (get-choice "You Survive! Which direction do you travel?" (list "north" "west" "south" "east")))))] [(string=? direction "east") (and (clear-canvas 4) (deadend 4) (3-7 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (3-6 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (3-7 direction) (cond [(string=? direction "west") (and (clear-canvas 4) (int-hall 4) (3-6 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (3-7 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (4-1 direction) (cond [(string=? direction "north") (and (clear-canvas 4) (int-hall 4) (3-3 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "south") (and (clear-canvas 4) (hallway 4) (slime 4) (fight (get-choice "A slime!" (list "fight")) 100 75 (5-1 (get-choice "You Survive! Which direction do you travel?" (list "north" "west" "south" "east")))))] [else (4-1 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (4-2 direction) (cond [(string=? direction "north") (and (clear-canvas 4) (int-hall 4) (3-6 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (4-2 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (5-1 direction) (cond [(string=? direction "north") (and (clear-canvas 4) (hallway 4) (4-1 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "south") (and (clear-canvas 4) (int-hall 4) (6-2 (get-choice "You have found a key! Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (5-1 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (6-1 direction) (cond [(string=? direction "east") (and (clear-canvas 4) (int-hall 4) (6-2 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (6-1 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (6-2 direction) (cond [(string=? direction "north") (and (clear-canvas 4) (hallway 4) (slime 4) (fight (get-choice "A slime!" (list "fight")) 100 75 (5-1 (get-choice "You Survive! Which direction do you travel?" (list "north" "west" "south" "east")))))] [(string=? direction "west") (and (clear-canvas 4) (deadend 4) (6-1 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "south") (and (clear-canvas 4) (deadend 4) (7-1 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "east") (and (clear-canvas 4) (hallway 4) (6-3 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (6-2 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (6-3 direction) (cond [(string=? direction "west") (and (clear-canvas 4) (int-hall 4) (6-2 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [(string=? direction "east") (and (clear-canvas 4) (deadend 4) (chest 4) (item-check "key3" item-list) (6-4 (get-choice "You have found the treasure" (list "start over?"))))] [else (6-3 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (6-4 direction) (cond [(string=? direction "start over?") (and (clear-canvas 4) (hallway 4) (beginning (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (6-4 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))])) (define (7-1 direction) (cond [(string=? direction "north") (and (clear-canvas 4) (int-hall 4) (6-2 (get-choice "Which direction do you travel?" (list "north" "west" "south" "east"))))] [else (7-1 (get-choice "There is a wall! Choose another direction." (list "north" "west" "south" "east")))]))) ;;ends the define portion of local (beginning (hallway 4) (get-choice "Which direction do you travel?" (list "south"))) )) ;;end of local (game-start)