► |  | Games: Fun Examples

1 | Bundled Games
2 | Implementing New Games
3 | Showing Scribbled Help
4 | Showing Text Help

► | 1 | Bundled Games

1.1 | Aces — Solitaire Card Game
1.2 | Go Fish — Kid’s Card Game
1.3 | Crazy 8s — Card Game
1.4 | Blackjack — 21 Card Game
1.5 | Rummy — Card Game
1.6 | Spider — Solitaire Card Game
1.7 | Memory — Kid’s Game
1.8 | Slidey — Picture Puzzle
1.9 | Same — Dot-Removing Game
1.10 | Minesweeper — Logic Game
1.11 | Paint By Numbers — Logic Game
1.12 | Lights Out — Logic Game
1.13 | Pousse — Tic-Tac-Toe-like Game
1.14 | Gobblet — Strategy Game
1.15 | Jewel — 3-D Skill Game
1.16 | Parcheesi — Board Game
1.17 | Checkers — Board Game
1.18 | Chat Noir — Puzzle Game
1.19 | Tally Maze — Maze Enumeration Game
1.20 | GCalc — Visual λ-Calculus

▼ | 1.18 | Chat Noir — Puzzle Game

1.18.1 | Overview
1.18.2 | The World
1.18.3 | Breadth-first Search
1.18.4 | Board to Graph
1.18.5 | The Cat’s Path
1.18.6 | Drawing the Cat
1.18.7 | Drawing the World
1.18.8 | Handling Input
1.18.9 | Tests
1.18.10 | Run, program, run

On this page:

<drawing-the-cat>

top ← prev up next →

##### 1.18.6`` Drawing the Cat

This code is three large, similar constants, bundled up into the cat function. The thinking-cat is the one that is visible when the game is being played. It differs from the others in that it does not have a mouth. The mad-cat is the one that you see when the cat loses. It differs from the others in that its pinks turn pink. Finally, the happy-cat shows up when the cat wins and it is just like the thinking-cat except it has a smile.

<drawing-the-cat> ::=

> (define/contract (cat mode)
> (-> (or/c 'mad 'happy 'thinking) image?)
> (define face-width 36)
> (define face-height 22)
> (define face-color
> (cond
> [(eq? mode 'mad) 'pink]
> [else 'lightgray]))
> (define left-ear
> (rotate 34 (regular-polygon 8 3 'solid 'black)))
> (define right-ear
> (rotate -34 (regular-polygon 8 3 'solid 'black)))
> (define ear-x-offset 14)
> (define ear-y-offset -8)
> (define eye (underlay (ellipse 12 8 'solid 'black)
> (ellipse 6 4 'solid 'limegreen)))
> (define eye-x-offset 8)
> (define eye-y-offset -3)
> (define nose
> (regular-polygon 5 3 'solid 'black))
> (define mouth-happy
> (overlay/align "center" "bottom"
> (rectangle 0 8 'solid 'black)
> (crop -1/2 4 9 5 (ellipse 8 8 'outline 'black))))
> (define mouth-no-expression
> (overlay/align "center" "bottom"
> (rectangle 0 6 'solid 'black)
> (rectangle 8 1 'solid 'black)))
> (define mouth
> (cond
> [(eq? mode 'happy) mouth-happy]
> [else mouth-no-expression]))
> (define mouth-x-offset 0)
> (define mouth-y-offset 5)
> (define (whiskers img)
> (define img-with-space
> (overlay img (rectangle (+ (image-width img) 20)
> (image-height img)
> "outline" "transparent")))
> (define whisker-start-y 17)
> (define whisker-start-right-x 32)
> (define whisker-start-left-x 24)
> (define whisker-width 23)
> (define whisker-y-delta 5)
> (add-line
> (add-line
> (add-line
> (add-line
> (add-line
> (add-line
> img-with-space
> whisker-start-left-x whisker-start-y
> (- whisker-start-left-x whisker-width)
> (- whisker-start-y whisker-y-delta) 'black)
> whisker-start-left-x whisker-start-y
> (- whisker-start-left-x whisker-width) whisker-start-y 'black)
> whisker-start-left-x whisker-start-y
> (- whisker-start-left-x whisker-width) (+ whisker-start-y whisker-y-delta) 'black)
> whisker-start-right-x whisker-start-y
> (+ whisker-start-right-x whisker-width) (- whisker-start-y whisker-y-delta) 'black)
> whisker-start-right-x whisker-start-y
> (+ whisker-start-right-x whisker-width) whisker-start-y 'black)
> whisker-start-right-x whisker-start-y
> (+ whisker-start-right-x whisker-width) (+ whisker-start-y whisker-y-delta) 'black))
> (whiskers
> (underlay/offset
> (underlay/offset
> (underlay/offset
> (underlay/offset
> (underlay/offset
> (underlay/offset
> (ellipse face-width face-height 'solid face-color)
> mouth-x-offset mouth-y-offset mouth)
> 0 0 nose)
> (- eye-x-offset) eye-y-offset eye)
> eye-x-offset eye-y-offset eye)
> ear-x-offset ear-y-offset right-ear)
> (- ear-x-offset) ear-y-offset left-ear)))
> (define thinking-cat (cat 'thinking))
> (define happy-cat (cat 'happy))
> (define mad-cat (cat 'mad))

top ← prev up next →