-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.rb
More file actions
126 lines (101 loc) · 2.08 KB
/
token.rb
File metadata and controls
126 lines (101 loc) · 2.08 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
class Token
def initialize(game)
@game = game
end
def to_s
self.class::TITLE
end
end
class ShipToken < Token
end
class Viper < ShipToken
attr_reader :damaged
TITLE = "Viper"
def initialize(game, player = nil)
super(game)
@damaged = false
@player = player
end
def to_s
pilot = manned? ? @player.to_s : 'unmanned'
self.class::TITLE + ' (' + pilot + ')'
end
def manned?
@player.nil? ? false : true
end
def damage!
@damaged = true
end
def repair!
@damaged = false
end
end
class Raptor < ShipToken
TITLE = "Raptor"
end
class Raider < ShipToken
TITLE = "Raider"
end
class HeavyRaider < ShipToken
TITLE = "Heavy Raider"
end
class Centurion < ShipToken
TITLE = "Centurion"
end
class Basestar < ShipToken
attr_reader \
:damage_tokens, \
:can_launch_ships, \
:can_attack_galactica, \
:structural_damage
TITLE = "Basestar"
def initialize(game)
super(game)
@damage_tokens = []
@can_launch_ships = true
@can_attack_galactica = true
@structural_damage = false
end
def damage
damage = @damage_tokens.count
if @damage_tokens.any? { |token| token.to_damage_class == :critical_hit }
damage += 1
end
damage
end
def damaged?
damage > 0
end
def should_be_destroyed?
damage >= 3
end
def damage_with_token!(damage_token)
@damage_tokens.push(damage_token)
case damage_token.to_damage_class
when :critical_hit
# Counts as extra damage
when :disabled_hangar
@can_launch_ships = false
when :disabled_weapons
@can_attack_galactica = false
when :structural_damage
@structural_damage = true
end
end
end
class DamageToken < Token
attr_reader :to_damage_class
def initialize(game, to_damage_class)
super(game)
@to_damage_class = to_damage_class
end
end
class GalacticaDamageToken < DamageToken
TITLE = "Galactica Damage Token"
end
class CivilianShip < DamageToken
TITLE = "Civilian Ship"
end
class BasestarDamageToken < DamageToken
TITLE = "Basestar Damage Token"
end