-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.coffee
117 lines (87 loc) · 1.81 KB
/
classes.coffee
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
class @Item
constructor:() ->
use: () ->
class @Die
constructor: (@numberOfDice, @numberOfSides, @constant) ->
roll: ->
sum = @constant
for i in [1..@numberOfDice]
sum += Math.random() * @numberOfSides
return Math.floor(Math.max(sum, 0))
toString: ->
@numberOfDice + "d" + @numberOfSides + "+" + @constant
###
Weapon class
###
class @Weapon extends Item #this means that a weapon IS an item
constructor: (@die, @name, @price) ->
roll: ->
@die.roll()
toString: ->
@name.toString() + ": " + @die.toString() + " (" + @price.toString() + "gp)"
###
Monster class
All monsters should be instances of this class.
Make a monster with "new Monster(<parameters in here>)"
###
class @Monster
constructor: (name, @hp, @weapon, @gp, @xp) ->
@name = randomAdjective() + " " + name
roll: ->
@weapon.roll()
hit: (damage) ->
@hp -= damage
isDead: ->
@hp <= 0
toString: ->
@name
###
Potions
###
class @Potion extends Item
constructor: () ->
class @HealthPotion extends Potion
constructor: () ->
###
Drinks the potion
###
use: ->
hp += 10
index = inventory.indexOf @
inventory.splice index, 1
toString: ->
return "Health Potion"
class @EvasionPotion extends Potion
constructor: () ->
###
Drinks the potion
Temporarially boosts the player's Evasion
###
use: ->
#TODO implement this
toString: ->
return "Evasion Potion"
class @BlockPotion extends Potion
constructor: () ->
###
Drinks the potion
Temporarially boosts the player's block
###
use: ->
#TODO implement this
toString: ->
return "Block Potion"
###
Scrolls
###
class Scroll extends Item
constructor: () ->
class DamageCurseScroll extends Scroll
constructor: () ->
use: ->
enemies[0].damage = 0
toString: ->
return "Damage-curse scroll"
class PoisonScroll extends Scroll
constructor: () ->
use: ->