Class: Mine

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bf, x, y, energy, origin) ⇒ Mine

Returns a new instance of Mine.



9
10
11
12
# File 'lib/mines.rb', line 9

def initialize bf, x, y, energy, origin
  @x, @y, @origin = x, y, origin
  @battlefield, @energy, @dead = bf, energy, false
end

Instance Attribute Details

#deadObject

Returns the value of attribute dead.



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

def dead
  @dead
end

#energyObject

Returns the value of attribute energy.



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

def energy
  @energy
end

#originObject

Returns the value of attribute origin.



7
8
9
# File 'lib/mines.rb', line 7

def origin
  @origin
end

#tObject

Returns the value of attribute t.



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

def t
  @t
end

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#destroyObject



32
33
34
# File 'lib/mines.rb', line 32

def destroy
  @dead = true
end

#stateObject



14
15
16
# File 'lib/mines.rb', line 14

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

#tickObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mines.rb', line 18

def tick
  @battlefield.robots.each do |robot|
    if (robot != origin) && (Math.hypot(@y - robot.y, robot.x - @x) < 40) && (!robot.dead)
      explosion = Explosion.new(@battlefield, robot.x, robot.y)
      @battlefield << explosion
      damage = robot.hit(self)
      origin.damage_given += damage
      origin.kills += 1 if robot.dead
      robot.trigged_mines += 1
      @dead = true
    end
  end
end