-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProject.rkt
More file actions
375 lines (284 loc) · 12 KB
/
Copy pathProject.rkt
File metadata and controls
375 lines (284 loc) · 12 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#lang racket/gui
(require "DungeonAVL.rkt")
(define StarterMonsterHp 50)
(define BossHp 1000)
(define frame (new frame% [label "Welcome to Dungeon Hall Z"]
[min-width 625]
[min-height 300]
))
(define my-font (make-object font% 12 'modern))
(define text (new text-field%
[label "Player:"]
[min-height 50]
[min-width 700]
[parent frame]
[font my-font]
[stretchable-width #f]
[enabled #f]))
(define monster-font (make-object font% 12 'modern))
(define monster-text (new text-field%
[label "Monster:"]
[min-height 50]
[min-width 700]
[parent frame]
[font my-font]
[stretchable-width #f]
[enabled #f]))
;;turns into a string
;;credit to http://stackoverflow.com/questions/13313815/scheme-convert-boolean-to-string
(define (->string x)
(call-with-output-string
(lambda (out)
(display x out))))
(define potion-font (make-object font% 12 'modern))
(define potion-text (new text-field%
[label "Potions"]
[min-height 30]
[min-width 350]
[parent frame]
[font my-font]
[stretchable-width #f]
[enabled #f]))
(define editor (send text get-editor))
(define monster-editor (send monster-text get-editor))
(define potion-editor (send potion-text get-editor))
(define (clear-text)
(send editor delete 0 (string-length (send editor get-text))))
(define (monster-clear-text)
(send monster-editor delete 0 (string-length (send monster-editor get-text))))
(define (potion-clear-text)
(send potion-editor delete 0 (string-length (send potion-editor get-text))))
(send editor set-padding
0 ;left padding
0 ;top padding
0 ;right padding
0 ;bottom padding
)
(send monster-editor set-padding
0 ;left padding
0 ;top padding
0 ;right padding
0 ;bottom padding
)
(send potion-editor set-padding
0 ;left padding
0 ;top padding
0 ;right padding
0 ;bottom padding
)
(define msg (new message% [parent frame]
[label ""]))
(define (monster-dead)
(set! monster (nextEnemy))
"Enemy defeated")
(define player-dead "YOU DIED, WORTHLESS SCUM!")
(define (monster-attack-output HP damage)
(string-append "Monsters HP: " (->string HP) " Monster attacked for: " (->string damage) " damage" ))
(define (player-attack-output HP damage)
(string-append "Players HP: " (->string HP) " You attacked for: " (->string damage) " damage" ))
(define (player-heal-output HP damage)
(string-append "Players HP: " (->string HP) " You Healed for: " (->string "50") " health" ))
(define (nextPhase player-HP monster-HP player-damage-done monster-damage-done)
(send editor insert (player-attack-output player-HP player-damage-done))
(send monster-editor insert (monster-attack-output monster-HP monster-damage-done)))
(define (healPhase player-HP monster-HP player-healing-done monster-damage-done)
(send editor insert (player-heal-output player-HP monster-damage-done))
(send monster-editor insert (monster-attack-output monster-HP monster-damage-done)))
(define battle (new horizontal-panel% [parent frame]))
(new button% [parent battle]
[label "Attack"]
[min-width 130]
[min-height 100]
[callback (lambda (b e) (clear-text)
(monster-clear-text)
(define monster-damage-done (monster 'attack))
(define player-damage-done (Player1 'attack))
(define monster-damage-taken ((monster 'attacked) player-damage-done))
(define player-damage-taken ((Player1 'attacked) monster-damage-done))
(define player-HP (Player1 'getHealth))
(define monster-HP (monster 'getHealth))
(cond ((< player-HP 0)(send editor insert player-dead))
((< monster-HP 0)(send monster-editor insert (monster-dead))
(send editor insert (string-append "Players HP: " (->string (Player1 'getHealth)))))
(else(nextPhase player-HP monster-HP player-damage-done monster-damage-done)))
)])
(new button% [parent battle]
[label "Heal"]
[min-width 130]
[min-height 100]
[callback (lambda (b e) (clear-text)
(monster-clear-text)
(potion-clear-text)
(define monster-damage-done (monster 'attack))
(define player-healing-done (->string(Player1 'healed)) )
(define player-healing-taken(string-append "You healed for: " "50" " Health"))
(define player-damage-taken ((Player1 'attacked) monster-damage-done))
(define player-HP (Player1 'getHealth))
(define monster-HP (monster 'getHealth))
(send potion-editor insert player-healing-done)
(cond ((< player-HP 0)(send editor insert player-dead))
((< monster-HP 0)(send editor insert monster-dead))
(else(healPhase player-HP monster-HP player-healing-done monster-damage-done)))
)])
(new button%
[parent battle]
[label "Run"]
[min-width 130]
[min-height 100]
[callback (lambda (b e) (clear-text)
(monster-clear-text)
(define potions-left (->string ((Player1 'run)100)))
(define potion-output (string-append "You lost: " "1" " potion while running away"))
(define monster-damage-done (->string (monster 'attack)))
(define monster-attack-output(string-append "Monster attacked for: " monster-damage-done " damage" ))
(send editor insert potion-output)
(send monster-editor insert monster-damage-done))])
(define (special-goes-off damage)
((monster 'attacked) damage)
(string-append "Players HP: " (->string (Player1 'getHealth)) " Special: NovaCane Strike: 500"))
(new button% [parent battle]
[label "Special"]
[min-width 100]
[min-height 100]
[callback (lambda (b e) (clear-text)
(monster-clear-text)
(define special-use (Player1 'special))
(define special-output
(if (number? special-use);;if its a number then it means we can attack
(special-goes-off 500)
(string-append "Players HP: " (->string (Player1 'getHealth)) (->string special-use)))) ;;else we got the string "Cant use special yet!"
(send editor insert special-output)
(if (< (monster 'getHealth) 0)
(send monster-editor insert (monster-dead))
(send monster-editor insert (string-append (monster-attack-output (monster 'getHealth) (monster 'attack)))))
)])
(new button% [parent battle]
[label "Next Enemy"]
[min-width 130]
[min-height 100]
[callback (lambda (b e)
(clear-text)
(monster-clear-text)
(potion-clear-text)
(getHealed)
(define start-health(string-append "Players HP: " (->string (Player1 'getHealth))))
(define monster-start-health(string-append "Monster HP: " (->string (monster 'getHealth))))
(define start-potions (->string (Player1 'getPotion)))
(send editor insert start-health)
(send monster-editor insert monster-start-health)
(send potion-editor insert start-potions)
)])
(send frame show #t)
(define health 100)
(define (getHealth)
health)
;;Creation of Player
(define (Player health potions mana)
;defining miss chance
(define special-counter 0)
(define PlayerHP health)
(define PlayerPotion potions)
(define (useSpecial)
(set! special-counter (- special-counter 3))
500)
(define (special)
(if (> special-counter 3)
;;remove monster / damage boss to half
(useSpecial)
" Cant use special yet!"))
;Damage taken after attacking
;;change to monster health instead of player
(define (attack)
(define miss (random 100))
(define damage (random 30))
(set! special-counter (+ special-counter 1))
(if ( >= miss 30)
damage
0))
;;player gets attacked
(define (getAttacked damage)
(set! PlayerHP (- PlayerHP damage)))
(define (getHealed)
(set! PlayerHP (+ PlayerHP 50))
(set! PlayerPotion (- PlayerPotion 1))
PlayerPotion)
(define (setPotion value)
(set! PlayerPotion value)
PlayerPotion)
;When you run Away you
(define (run potion)
(define drop (random 100))
(if ( >= drop 80)
(if (> potion 0)
(begin (set! potion (- potion 1))
potion)
"You Stumbled as you ran")
"You got Away Safely"))
(define (setHealth health)
(set! PlayerHP health))
(define (dispatch m)
(cond ((eq? m 'attack) (attack))
((eq? m 'run) run)
((eq? m 'special) (special))
((eq? m 'getHealth) PlayerHP)
((eq? m 'setHealth) setHealth)
((eq? m 'attacked) getAttacked)
((eq? m 'getPotion) PlayerPotion)
((eq? m 'setPotion) setPotion)
((eq? m 'healed) (if (and (> PlayerPotion 0) (> PlayerHP 0)) (getHealed)"No Potions"))
;;Gave an error because dispatch requires an else
(else (error "Not a Command"
m))))
; return the dispatch
dispatch)
;;Creation of Monsters
(define (Monster health)
(define MonsterHP health)
;Damage taken after attacking
;;change to player health instead of monster
(define (attack)
(define miss (random 100))
(if (>= health 0)
(random 30)
0))
(define (getAttacked damage)
(set! MonsterHP (- MonsterHP damage)))
(define (dispatch m)
(cond ((eq? m 'attack) (attack))
((eq? m 'getHealth) MonsterHP)
((eq? m 'attacked) getAttacked)
;;Gave an error because dispatch requires an else
(else (error "Not a Command"
m))))
; return the dispatch
dispatch)
;;manipulate these when moving up and down the tree
;;If Tree level is lowest create player
(define Player1 (Player 100 11 100))
;;starting
;;(define player-start)
;;(Player 100 11 100)
(define (getHealed)
(Player 100 11 100))
;;Each time a new tree Level is hit create a monster
(define monster (Monster StarterMonsterHp))
;;Top level of Tree Create Boss
(define BOSS (Monster BossHp))
;;(define damage-done (->string ((Player1 'attack)100)))
(define monster1 (Monster StarterMonsterHp))
(define monster2 (Monster StarterMonsterHp))
(define monster3 (Monster StarterMonsterHp))
(define monster4 (Monster StarterMonsterHp))
(define monster5 (Monster StarterMonsterHp))
;;Create Dungeon
(addEnemy monster1)
(addEnemy monster2)
(addEnemy monster3)
(addEnemy monster4)
(addEnemy monster5)
(addEnemy BOSS)
(define (init)
(send editor insert (string-append "Players HP: " (->string (Player1 'getHealth)) ))
(send monster-editor insert (string-append "Monsters HP: " (->string (monster 'getHealth))))
(send potion-editor insert (->string (Player1 'getPotion))))
(init)