|
@@ -0,0 +1,127 @@
|
|
1
|
+(defmodule game
|
|
2
|
+ (export all))
|
|
3
|
+
|
|
4
|
+;; Creates:
|
|
5
|
+;; make-exit
|
|
6
|
+;; exit-direction
|
|
7
|
+;; exit-object
|
|
8
|
+;; exit-destination
|
|
9
|
+;; set-exit
|
|
10
|
+;; set-exit-direction
|
|
11
|
+;; set-exit-object
|
|
12
|
+;; set-exit-destination
|
|
13
|
+;; match-exit
|
|
14
|
+;; ...
|
|
15
|
+(defrecord exit
|
|
16
|
+ direction
|
|
17
|
+ object
|
|
18
|
+ destination)
|
|
19
|
+
|
|
20
|
+(defrecord place
|
|
21
|
+ name
|
|
22
|
+ description
|
|
23
|
+ exits)
|
|
24
|
+
|
|
25
|
+(defrecord object
|
|
26
|
+ name
|
|
27
|
+ location)
|
|
28
|
+
|
|
29
|
+(defrecord goal
|
|
30
|
+ name
|
|
31
|
+ achieved?)
|
|
32
|
+
|
|
33
|
+(defrecord state
|
|
34
|
+ objects
|
|
35
|
+ places
|
|
36
|
+ player-location
|
|
37
|
+ goals)
|
|
38
|
+
|
|
39
|
+(set objects
|
|
40
|
+ (list (make-object name 'whiskey-bottle location 'living-room)
|
|
41
|
+ (make-object name 'bucket location 'living-room)
|
|
42
|
+ (make-object name 'frog location 'garden)
|
|
43
|
+ (make-object name 'chain location 'garden)))
|
|
44
|
+
|
|
45
|
+(set living-room
|
|
46
|
+ (make-place
|
|
47
|
+ name 'living-room
|
|
48
|
+ description (++ "You are in the living-room of a wizard's house. "
|
|
49
|
+ "There is a wizard snoring loudly on the couch.")
|
|
50
|
+ exits (list
|
|
51
|
+ (make-exit
|
|
52
|
+ direction "west"
|
|
53
|
+ object "door"
|
|
54
|
+ destination 'garden)
|
|
55
|
+ (make-exit
|
|
56
|
+ direction "upstairs"
|
|
57
|
+ object "stairway"
|
|
58
|
+ destination 'attic))))
|
|
59
|
+
|
|
60
|
+(set garden
|
|
61
|
+ (make-place
|
|
62
|
+ name 'garden
|
|
63
|
+ description (++ "You are in a beautiful garden. "
|
|
64
|
+ "There is a well in front of you.")
|
|
65
|
+ exits (list
|
|
66
|
+ (make-exit
|
|
67
|
+ direction "east"
|
|
68
|
+ object "door"
|
|
69
|
+ destination 'living-room))))
|
|
70
|
+
|
|
71
|
+(set attic
|
|
72
|
+ (make-place
|
|
73
|
+ name 'attic
|
|
74
|
+ description (++ "You are in the attic of the wizard's house. "
|
|
75
|
+ "There is a giant welding torch in the corner.")
|
|
76
|
+ exits (list
|
|
77
|
+ (make-exit
|
|
78
|
+ direction "downstairs"
|
|
79
|
+ object "stairway"
|
|
80
|
+ destination 'living-room))))
|
|
81
|
+
|
|
82
|
+(set netherworld
|
|
83
|
+ (make-place
|
|
84
|
+ name 'netherworld
|
|
85
|
+ description (++ "Everything is misty and vague. "
|
|
86
|
+ "You seem to be in the netherworld.\n"
|
|
87
|
+ "There are no exits.\n"
|
|
88
|
+ "You could be here for a long, long time ...")
|
|
89
|
+ exits '()))
|
|
90
|
+
|
|
91
|
+(set goals
|
|
92
|
+ (list (make-goal name 'weld-chain achieved? 'false)
|
|
93
|
+ (make-goal name 'dunk-bucket achieved? 'false)
|
|
94
|
+ (make-goal name 'splash-wizard achieved? 'false)))
|
|
95
|
+
|
|
96
|
+(set state (make-state
|
|
97
|
+ objects objects
|
|
98
|
+ places (list living-room garden attic netherworld)
|
|
99
|
+ player-location 'living-room
|
|
100
|
+ goals goals))
|
|
101
|
+
|
|
102
|
+(defun here?
|
|
103
|
+ ((loc (match-place name place-name)) (when (== loc place-name))
|
|
104
|
+ 'true)
|
|
105
|
+ ((_ _)
|
|
106
|
+ 'false))
|
|
107
|
+
|
|
108
|
+(defun get-here
|
|
109
|
+ (((match-state player-location player-loc places locs))
|
|
110
|
+ (car (lists:filter
|
|
111
|
+ (lambda (loc)
|
|
112
|
+ (here? player-loc loc))
|
|
113
|
+ locs))))
|
|
114
|
+
|
|
115
|
+(defun describe-location (game-state)
|
|
116
|
+ (++ (place-description (get-here game-state)) "\n"))
|
|
117
|
+
|
|
118
|
+(defun describe-exit
|
|
119
|
+ (((match-exit object obj direction dir))
|
|
120
|
+ (++ "There is a " obj " going " dir " from here.")))
|
|
121
|
+
|
|
122
|
+(defun describe-exits (game-state)
|
|
123
|
+ (string:join
|
|
124
|
+ (lists:map
|
|
125
|
+ #'describe-exit/1
|
|
126
|
+ (place-exits (get-here game-state)))
|
|
127
|
+ " "))
|