Class: Toolbox
- Inherits:
-
Object
- Object
- Toolbox
- Defined in:
- lib/toolboxes.rb
Instance Attribute Summary collapse
-
#dead ⇒ Object
Returns the value of attribute dead.
-
#energy ⇒ Object
Returns the value of attribute energy.
-
#t ⇒ Object
Returns the value of attribute t.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(bf, x, y, t, energy) ⇒ Toolbox
constructor
A new instance of Toolbox.
- #state ⇒ Object
- #tick ⇒ Object
Constructor Details
#initialize(bf, x, y, t, energy) ⇒ Toolbox
Returns a new instance of Toolbox.
8 9 10 11 |
# File 'lib/toolboxes.rb', line 8 def initialize bf, x, y, t, energy @x, @y, @t = x, y, t @battlefield, @energy, @dead = bf, energy, false end |
Instance Attribute Details
#dead ⇒ Object
Returns the value of attribute dead.
5 6 7 |
# File 'lib/toolboxes.rb', line 5 def dead @dead end |
#energy ⇒ Object
Returns the value of attribute energy.
6 7 8 |
# File 'lib/toolboxes.rb', line 6 def energy @energy end |
#t ⇒ Object
Returns the value of attribute t.
4 5 6 |
# File 'lib/toolboxes.rb', line 4 def t @t end |
#x ⇒ Object
Returns the value of attribute x.
2 3 4 |
# File 'lib/toolboxes.rb', line 2 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/toolboxes.rb', line 3 def y @y end |
Instance Method Details
#state ⇒ Object
13 14 15 |
# File 'lib/toolboxes.rb', line 13 def state {:x=>x, :y=>y, :energy=>energy} end |
#tick ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/toolboxes.rb', line 17 def tick @t += 1 @dead ||= t > @battlefield.config.toolboxes[:life_time] @battlefield.robots.each do |robot| if Math.hypot(@y - robot.y, robot.x - @x) < 20 && (!robot.dead) healing = robot.heal(self) @dead = true end end end |