Class: Toolbox

Inherits:
Object
  • Object
show all
Defined in:
lib/toolboxes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#deadObject

Returns the value of attribute dead.



5
6
7
# File 'lib/toolboxes.rb', line 5

def dead
  @dead
end

#energyObject

Returns the value of attribute energy.



6
7
8
# File 'lib/toolboxes.rb', line 6

def energy
  @energy
end

#tObject

Returns the value of attribute t.



4
5
6
# File 'lib/toolboxes.rb', line 4

def t
  @t
end

#xObject

Returns the value of attribute x.



2
3
4
# File 'lib/toolboxes.rb', line 2

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/toolboxes.rb', line 3

def y
  @y
end

Instance Method Details

#stateObject



13
14
15
# File 'lib/toolboxes.rb', line 13

def state
  {:x=>x, :y=>y, :energy=>energy}
end

#tickObject



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