Class: Mine
- Inherits:
-
Object
- Object
- Mine
- Defined in:
- lib/mines.rb
Instance Attribute Summary collapse
-
#dead ⇒ Object
Returns the value of attribute dead.
-
#energy ⇒ Object
Returns the value of attribute energy.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#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
- #destroy ⇒ Object
-
#initialize(bf, x, y, energy, origin) ⇒ Mine
constructor
A new instance of Mine.
- #state ⇒ Object
- #tick ⇒ Object
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
#dead ⇒ Object
Returns the value of attribute dead.
5 6 7 |
# File 'lib/mines.rb', line 5 def dead @dead end |
#energy ⇒ Object
Returns the value of attribute energy.
6 7 8 |
# File 'lib/mines.rb', line 6 def energy @energy end |
#origin ⇒ Object
Returns the value of attribute origin.
7 8 9 |
# File 'lib/mines.rb', line 7 def origin @origin end |
#t ⇒ Object
Returns the value of attribute t.
4 5 6 |
# File 'lib/mines.rb', line 4 def t @t end |
#x ⇒ Object
Returns the value of attribute x.
2 3 4 |
# File 'lib/mines.rb', line 2 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/mines.rb', line 3 def y @y end |
Instance Method Details
#destroy ⇒ Object
32 33 34 |
# File 'lib/mines.rb', line 32 def destroy @dead = true end |
#state ⇒ Object
14 15 16 |
# File 'lib/mines.rb', line 14 def state {:x=>x, :y=>y, :energy=>energy} end |
#tick ⇒ Object
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 |