Sha256: 6c60b397f9bd2e3e5a1dcedabd1cfcd9b9206b7a995e0165cb6d46dac9e03431

Contents?: true

Size: 810 Bytes

Versions: 2

Compression:

Stored size: 810 Bytes

Contents

class Mine
  attr_accessor :x
  attr_accessor :y
  attr_accessor :t
  attr_accessor :dead
  attr_accessor :energy
  attr_accessor :origin

  def initialize bf, x, y, energy, origin
    @x, @y, @origin = x, y, origin
    @battlefield, @energy, @dead = bf, energy, false
  end
  
  def state
    {:x=>x, :y=>y, :energy=>energy}
  end

  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
  
  def destroy
    @dead = true
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
UG_RRobots-2.2 lib/mines.rb
UG_RRobots-2.1 lib/mines.rb