-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwemthy_lisp.txt
179 lines (162 loc) · 4.52 KB
/
dwemthy_lisp.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
(defn wrap-obj (obj) (syn (s) (get obj s)))
(defn wrap-obj-from-fn (obj) (syn (s) ((fn-from (obj)) s)))
(defm -> (x) (` (fn () (, x))))
(defn partition (l) (i 0) (a []) (do
(while (< i (len l)) (do
(push a [(nth l i) (nth l (1+ i))])
(setq i (+ 2 i))
))
a
))
(defn transform-kv-pair ((x y)) [list [quote x] y])
(defn subtract-life (h x) (do
(defq new-life (- (h life) x))
(if (<= new-life 0)
(do
(puts (h name) " has died!")
((h life=) 0)
((h dead?=) t)
t
)
(do ((h life=) new-life) nil)
)
))
(defm defcreature (name (& props)) (` (def (quote (, name))
(let (h (hash
[\self (fn _ h)] [\name (quote (, name))] [\dead? nil]
(@, (map transform-kv-pair (partition props)))
)) (do
(each (fn (i) (def h (~ i \=) (fn (j) (set h i j)))) (keys h))
(wrap-obj h)
))
)))
(defn hit (self damage) (do
(defq p-up (randint (self charisma)))
(if (= (% p-up 9) 7) (do
((self life=) (+ (self life) (// p-up 4)))
(puts (self name) " magick powers up " p-up "!")
))
(subtract-life self damage)
))
(defn make-attack (c self enemy) (do
(defq self-hit ((get attacks c) self enemy))
(if self-hit (do
(set :self-hit (randint (+ self-hit (self strength))))
(puts "You hit with " self-hit " points of damage!")
(defq killed? (hit enemy self-hit))
(unless killed? (do
(defq enemy-hit (randint (+ (enemy strength) (enemy weapon))))
(puts "Your enemy hit with " enemy-hit " points of damage!")
(hit self enemy-hit)
))
killed?
) nil)
))
(defq attacks (hash
[\% (fn (self _) (do
(defq lettuce (randint (self charisma)))
(puts "Healthy lettuce gives you " lettuce " life points!")
((self life=) (+ (self life) lettuce))
0
))]
[\^ (fn _ 13)]
[\* (fn (self _) (if
(= (self bombs) 0)
(do (puts "UHN!! You're out of bombs!!") nil)
(do ((self bombs=) (1- (self bombs))) 86)
))]
[\/ (fn (_ enemy) (randint (+ 4 (** (% (enemy life) 10) 2))))]
))
(defn DwemthysArray creatures
(index 0)
(past-all-creatures? (-> (>= index (len creatures))))
(current-creature (-> (nth creatures index)))
(status (-> (cond
((past-all-creatures?) \all-dead)
(((current-creature) dead?) \dead)
(t \live)
)))
(wrap-obj-from-fn (-> (do
(while (= (status) \dead) (++ index))
(if (past-all-creatures?) AllDead (current-creature))
)))
)
(defs qw x (map ~ x))
(defq AllDead (syn (x) (if (= x :dead?) t (throw 'This is a bug!'))))
(defq *global* ((fn (x) (fn () x)) (current-scope)))
(defn init () (in-scope (*global*) (do
(each
(fn (x) (if (has? x) (del x)))
(qw Rabbit IndustrialRaverMonkey DwarvenAngel
AssistantViceTentacleAndOmbudsman TeethDeer
IntrepidDecomposedCyclist Dragon *enemy*
*self*)
)
(defcreature Rabbit
life 10
strength 2
charisma 44
weapon 4
bombs 3
)
(defcreature IndustrialRaverMonkey
life 46
strength 35
charisma 91
weapon 2
)
(defcreature DwarvenAngel
life 540
strength 6
charisma 144
weapon 50
)
(defcreature AssistantViceTentacleAndOmbudsman
life 320
strength 6
charisma 144
weapon 50
)
(defcreature TeethDeer
life 655
strength 192
charisma 19
weapon 109
)
(defcreature IntrepidDecomposedCyclist
life 901
strength 560
charisma 422
weapon 105
)
(defcreature Dragon
life 1340
strength 451
charisma 1020
weapon 939
)
(defq *enemy* (DwemthysArray
IndustrialRaverMonkey
DwarvenAngel
AssistantViceTentacleAndOmbudsman
TeethDeer
IntrepidDecomposedCyclist
Dragon
))
(defq *self* Rabbit)
)))
(init)
(defn prompt () '>>> ')
(defn main (c) (killed? nil) (do
(set :killed? nil)
(cond
((*self* dead?) (puts 'You are dead!'))
((*enemy* dead?) (puts 'Quit flogging my dead monsters!'))
((has? attacks c) (set :killed? (make-attack c *self* *enemy*)))
(t (puts "You can't do that. Use one of the attacks: " (join (keys attacks) ', ')))
)
(if killed? (if (*enemy* dead?)
(puts "Whoa. You decimated Dwemthy's Array.")
(puts "Get ready. " (*enemy* name) " has emerged.")
))
))