class RubyArena::Arena

Constants

HEIGHT
WIDTH

Attributes

bullets[R]
robots[R]
time[R]
total_robots_count[R]

Public Class Methods

new() click to toggle source
# File lib/ruby_arena/arena.rb, line 8
def initialize
  @robots = []
  @bullets = []
  @time = 0
  @total_robots_count = 0
end

Public Instance Methods

add_bullet(bullet) click to toggle source
# File lib/ruby_arena/arena.rb, line 20
def add_bullet(bullet)
  @bullets << bullet
end
add_robot(robot) click to toggle source
# File lib/ruby_arena/arena.rb, line 15
def add_robot(robot)
  @robots << robot
  @total_robots_count += 1
end
game_over?() click to toggle source
# File lib/ruby_arena/arena.rb, line 33
def game_over?
  robots_count <= 1 and total_robots_count > 1
end
height() click to toggle source
# File lib/ruby_arena/arena.rb, line 45
def height
  HEIGHT
end
robots_count() click to toggle source
# File lib/ruby_arena/arena.rb, line 37
def robots_count
  robots.count
end
update() click to toggle source
# File lib/ruby_arena/arena.rb, line 24
def update
  send_tick_to_all_robots
  send_update_to_all_robots
  send_update_to_all_bullets
  remove_dead_robots
  remove_dead_bullets
  update_time
end
width() click to toggle source
# File lib/ruby_arena/arena.rb, line 41
def width
  WIDTH
end

Private Instance Methods

remove_dead_bullets() click to toggle source
# File lib/ruby_arena/arena.rb, line 67
def remove_dead_bullets
  bullets.delete_if { |bullet| bullet.dead? }
end
remove_dead_robots() click to toggle source
# File lib/ruby_arena/arena.rb, line 63
def remove_dead_robots
  robots.delete_if { |robot| robot.dead? }
end
send_tick_to_all_robots() click to toggle source
# File lib/ruby_arena/arena.rb, line 51
def send_tick_to_all_robots
  robots.each(&:tick)
end
send_update_to_all_bullets() click to toggle source
# File lib/ruby_arena/arena.rb, line 59
def send_update_to_all_bullets
  bullets.each(&:update)
end
send_update_to_all_robots() click to toggle source
# File lib/ruby_arena/arena.rb, line 55
def send_update_to_all_robots
  robots.each(&:update)
end
update_time() click to toggle source
# File lib/ruby_arena/arena.rb, line 71
def update_time
  @time += 1
end