-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpokemon.rb
65 lines (46 loc) · 1019 Bytes
/
pokemon.rb
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
module PokeSky
class Type
attr :prim, :sec
def initialize(prim, sec)
@prim = prim
@sec = sec
end
end
class Pokemon
MAX_LEVEL = 100
XP_RATE = 500
MOVES_SIZE = 4
attr_accessor :owner, :id, :name, :xp, :moves, :type
def initialize(owner, id, name, xp, moves, type)
@owner = owner
@id = id
@name = name
@xp = xp
raise "# of moves is not #{MOVES_SIZE}!" if moves.length != MOVES_SIZE
@moves = moves
@type = type
end
def level
Pokemon.level_for_xp(@xp)
end
def self.cap_level(lv)
lv > MAX_LEVEL ? MAX_LEVEL : lv
end
def self.xp_for_level(lv)
cap_level(lv) * XP_RATE
end
def self.level_for_xp(xp)
cap_level((xp.to_f / XP_RATE).floor)
end
end
class BattlePokemon < Pokemon
attr_accessor :health
def initialize(owner, id, name, xp, moves, type)
super
@health = max_health
end
def max_health
level * 4
end
end
end