1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.2-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
7 ;where s is a one-letter symbol ('a, 'b, ...) and '_, and w is a word.
9 ;reveal-list : word word symbol -> word
10 ;Given chosen (word), status (word), and guess (one-letter symbol), return the new status word. A status word represents the progress of the hangman game. If guess matches a letter in chosen, replace '_ in status with the letter. Otherwise, return the same status word.
11 ;ASSUMPTION: both chosen and status are the same length.
14 ;(reveal-list '(b r e a d) '(b r e _ _) 'a)
17 ;(reveal-list '(b r e a d) '(b r e _ _) 'x)
20 ;(reveal-list '(m o o n) '(_ _ _ n) 'o)
23 (define (reveal-list chosen status guess)
25 [(empty? chosen) empty]
28 [(symbol=? guess (first chosen))
29 (cons (first chosen) (reveal-list (rest chosen) (rest status) guess))]
30 [else (cons (first status) (reveal-list (rest chosen) (rest status) guess))])]))
32 ; Defines canvas width (CWIDTH) and canvas height (CHEIGHT)
33 ; Defines center of x-axis
36 (define XCENTER (/ CWIDTH 2))
37 (define COLORHEAD 'brown)
38 (define COLORBODY 'purple)
39 (define COLORARMS 'brown)
40 (define COLORLEGS 'red)
42 ; draw-noose : symbol -> boolean
43 ; Draws the corresponding part and returns true if evaluation succeeds, false
44 ; if the part to be drawn does not match this function.
46 (define (draw-noose part)
48 [(symbol=? part 'noose)
50 (draw-solid-line (make-posn 0 (/ CHEIGHT 10))
51 (make-posn XCENTER (/ CHEIGHT 10)))
52 (draw-solid-line (make-posn XCENTER (/ CHEIGHT 10))
53 (make-posn XCENTER (/ CHEIGHT 5))))]
56 ; draw-head : symbol -> boolean
58 (define (draw-head part)
60 [(symbol=? part 'head)
61 (draw-circle (make-posn XCENTER (/ CHEIGHT 3)) (* CHEIGHT 2/15) COLORHEAD)]
64 ; draw-body : symbol -> boolean
66 (define (draw-body part)
68 [(symbol=? part 'body)
69 (draw-solid-line (make-posn XCENTER (* 7/15 CHEIGHT))
70 (make-posn XCENTER (* CHEIGHT 3/4))
74 ; draw-right-arm : symbol -> boolean
75 (define (draw-right-arm part)
77 [(symbol=? part 'right-arm)
78 (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
79 (make-posn (* CWIDTH 3/4) (* CHEIGHT 7/15))
83 ; draw-left-arm : symbol -> boolean
84 (define (draw-left-arm part)
86 [(symbol=? part 'left-arm)
87 (draw-solid-line (make-posn XCENTER (* 3/5 CHEIGHT))
88 (make-posn (* CWIDTH 1/4) (* CHEIGHT 7/15))
92 ; draw-right-leg : symbol -> boolean
93 (define (draw-right-leg part)
95 [(symbol=? part 'right-leg)
96 (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
97 (make-posn (* CWIDTH 7/8) (* CHEIGHT 15/16))
101 ; draw-left-leg : symbol -> boolean
102 (define (draw-left-leg part)
104 [(symbol=? part 'left-leg)
105 (draw-solid-line (make-posn XCENTER (* 3/4 CHEIGHT))
106 (make-posn (* CWIDTH 1/8) (* CHEIGHT 15/16))
110 ; draw-next-part : symbol -> boolean
111 ; Draws the next part given the name of the part. Returns true if
112 ; drawing is successful.
114 (define (draw-next-part part)
116 [(symbol=? part 'noose) (draw-noose part)]
117 [(symbol=? part 'head) (draw-head part)]
118 [(symbol=? part 'body) (draw-body part)]
119 [(symbol=? part 'right-arm) (draw-right-arm part)]
120 [(symbol=? part 'left-arm) (draw-left-arm part)]
121 [(symbol=? part 'right-leg) (draw-right-leg part)]
122 [(symbol=? part 'left-leg) (draw-left-leg part)]))
124 (start CWIDTH CHEIGHT)
125 (hangman-list reveal-list draw-next-part)