Class: RTanque::Runner
- Inherits:
-
Object
- Object
- RTanque::Runner
- Defined in:
- lib/rtanque/runner.rb
Overview
Runner manages running an Match
Constant Summary collapse
- LoadError =
Class.new(::LoadError)
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
Returns the value of attribute match.
Instance Method Summary collapse
-
#add_brain_path(brain_path) ⇒ Object
Attempts to load given Bot::Brain given its path.
-
#initialize(width, height, *match_args) ⇒ Runner
constructor
A new instance of Runner.
-
#start(gui = true) ⇒ Object
Starts the match.
Constructor Details
#initialize(width, height, *match_args) ⇒ Runner
Returns a new instance of Runner.
15 16 17 |
# File 'lib/rtanque/runner.rb', line 15 def initialize(width, height, *match_args) @match = RTanque::Match.new(RTanque::Arena.new(width, height), *match_args) end |
Instance Attribute Details
#match ⇒ Object (readonly)
Returns the value of attribute match.
10 11 12 |
# File 'lib/rtanque/runner.rb', line 10 def match @match end |
Instance Method Details
#add_brain_path(brain_path) ⇒ Object
Attempts to load given Bot::Brain given its path
22 23 24 25 26 |
# File 'lib/rtanque/runner.rb', line 22 def add_brain_path(brain_path) parsed_path = self.parse_brain_path(brain_path) bots = parsed_path.multiplier.times.map { self.new_bots_from_brain_path(parsed_path.path) }.flatten self.match.add_bots(bots) end |
#start(gui = true) ⇒ Object
Starts the match
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rtanque/runner.rb', line 30 def start(gui = true) if gui require 'rtanque/gui' window = RTanque::Gui::Window.new(self.match) trap(:INT) { window.close } window.show else trap(:INT) { self.match.stop } self.match.start end end |