Class: Termfront::Weapon::Base
- Inherits:
-
Object
- Object
- Termfront::Weapon::Base
show all
- Defined in:
- lib/termfront/weapon/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ammo: nil) ⇒ Base
Returns a new instance of Base.
8
9
10
|
# File 'lib/termfront/weapon/base.rb', line 8
def initialize(ammo: nil)
@ammo = ammo.nil? ? max_ammo : ammo
end
|
Instance Attribute Details
#ammo ⇒ Object
Returns the value of attribute ammo.
6
7
8
|
# File 'lib/termfront/weapon/base.rb', line 6
def ammo
@ammo
end
|
Class Method Details
.build(type, ammo = nil) ⇒ Object
37
38
39
40
|
# File 'lib/termfront/weapon/base.rb', line 37
def build(type, ammo = nil)
klass = registry[type] || raise(ArgumentError, "Unknown weapon type: #{type}")
ammo ? klass.new(ammo: ammo) : klass.new
end
|
.register(type, klass) ⇒ Object
33
34
35
|
# File 'lib/termfront/weapon/base.rb', line 33
def register(type, klass)
registry[type] = klass
end
|
.registry ⇒ Object
29
30
31
|
# File 'lib/termfront/weapon/base.rb', line 29
def registry
@registry ||= {}
end
|
Instance Method Details
#can_fire?(last_fire, now) ⇒ Boolean
20
21
22
|
# File 'lib/termfront/weapon/base.rb', line 20
def can_fire?(last_fire, now)
(now - last_fire) > cooldown
end
|
#consume_ammo! ⇒ Object
24
25
26
|
# File 'lib/termfront/weapon/base.rb', line 24
def consume_ammo!
@ammo -= 1 if @ammo
end
|
#cooldown ⇒ Object
14
|
# File 'lib/termfront/weapon/base.rb', line 14
def cooldown = raise(NotImplementedError)
|
#hit_width ⇒ Object
15
|
# File 'lib/termfront/weapon/base.rb', line 15
def hit_width = raise(NotImplementedError)
|
#infinite_ammo? ⇒ Boolean
18
|
# File 'lib/termfront/weapon/base.rb', line 18
def infinite_ammo? = max_ammo.nil?
|
#max_ammo ⇒ Object
13
|
# File 'lib/termfront/weapon/base.rb', line 13
def max_ammo = raise(NotImplementedError)
|
#name ⇒ Object
12
|
# File 'lib/termfront/weapon/base.rb', line 12
def name = raise(NotImplementedError)
|
#type_id ⇒ Object
16
|
# File 'lib/termfront/weapon/base.rb', line 16
def type_id = raise(NotImplementedError)
|