Class: Gembots::Arena

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/gembots/arena.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*bots) ⇒ Arena

Returns a new instance of Arena.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/gembots/arena.rb', line 5

def initialize *bots
  super 640, 480, false
  self.caption = "Gembots battle"
  @bots = []

  bots.each do |bot_class|
    bot = bot_class.new self
    bot.warp 320, 240
    @bots << bot
  end
end

Instance Attribute Details

#botsObject (readonly)

Returns the value of attribute bots.



4
5
6
# File 'lib/gembots/arena.rb', line 4

def bots
  @bots
end

Instance Method Details

#button_down(id) ⇒ Object



30
31
32
# File 'lib/gembots/arena.rb', line 30

def button_down id
  close if id == Gosu::KbEscape
end

#drawObject



17
18
19
# File 'lib/gembots/arena.rb', line 17

def draw
  @bots.each &:draw
end

#updateObject



21
22
23
24
25
26
27
28
# File 'lib/gembots/arena.rb', line 21

def update
  @bots.each &:update
  @bots.each do |bot|
    if bot.actions.empty?
      bot.on_idle
    end
  end
end