class RubyArena::Game

Attributes

arena[R]
level[R]

Public Class Methods

new(args) click to toggle source
# File lib/ruby_arena/game.rb, line 5
def initialize(args)
  @arena = Arena.new
  @robot_files = args[:robot_files]
  @level = Level.new(args[:options][:level]) if args[:options][:level]
  add_robots_to_arena
end

Public Instance Methods

game_over?() click to toggle source
# File lib/ruby_arena/game.rb, line 16
def game_over?
  arena.game_over?
end
run() click to toggle source
# File lib/ruby_arena/game.rb, line 12
def run
  gui.show
end

Private Instance Methods

add_cpu_robots() click to toggle source
# File lib/ruby_arena/game.rb, line 51
def add_cpu_robots
  options_for_user_robots.each do |options|
    options.merge!({ arena: arena })
    add_robot(Robot.new(options))
  end
end
add_robot(robot) click to toggle source
# File lib/ruby_arena/game.rb, line 62
def add_robot(robot)
  arena.add_robot(robot)
end
add_robots_to_arena() click to toggle source
# File lib/ruby_arena/game.rb, line 26
def add_robots_to_arena
  add_user_robots
  add_cpu_robots if level
end
add_user_robots() click to toggle source
# File lib/ruby_arena/game.rb, line 31
def add_user_robots
  user_robots.each do |robot|
    add_robot(robot)
  end
end
gui() click to toggle source
# File lib/ruby_arena/game.rb, line 22
def gui
  Gui.new(arena)
end
load_class_from_file(file) click to toggle source
# File lib/ruby_arena/game.rb, line 66
def load_class_from_file(file)
  ClassLoader.new("#{pwd}/#{file}").get_class
end
options_for_user_robot(ai_class) click to toggle source
# File lib/ruby_arena/game.rb, line 45
def options_for_user_robot(ai_class)
  options = { arena: arena, ai: ai_class }
  options.merge!(level.options_for_user_robot) if level
  options
end
options_for_user_robots() click to toggle source
# File lib/ruby_arena/game.rb, line 58
def options_for_user_robots
  level.options_for_cpu_robots
end
pwd() click to toggle source
# File lib/ruby_arena/game.rb, line 70
def pwd
  Dir.getwd
end
user_robots() click to toggle source
# File lib/ruby_arena/game.rb, line 37
def user_robots
  @robot_files.map do |file|
    ai_class = load_class_from_file(file)

    Robot.new(options_for_user_robot(ai_class))
  end
end