Class: RubyArena::Arena

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_arena/arena.rb

Constant Summary collapse

WIDTH =
800
HEIGHT =
600

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArena

Returns a new instance of Arena.



8
9
10
11
12
13
# File 'lib/ruby_arena/arena.rb', line 8

def initialize
  @robots = []
  @bullets = []
  @time = 0
  @total_robots_count = 0
end

Instance Attribute Details

#bulletsObject (readonly)

Returns the value of attribute bullets.



6
7
8
# File 'lib/ruby_arena/arena.rb', line 6

def bullets
  @bullets
end

#robotsObject (readonly)

Returns the value of attribute robots.



6
7
8
# File 'lib/ruby_arena/arena.rb', line 6

def robots
  @robots
end

#timeObject (readonly)

Returns the value of attribute time.



6
7
8
# File 'lib/ruby_arena/arena.rb', line 6

def time
  @time
end

#total_robots_countObject (readonly)

Returns the value of attribute total_robots_count.



6
7
8
# File 'lib/ruby_arena/arena.rb', line 6

def total_robots_count
  @total_robots_count
end

Instance Method Details

#add_bullet(bullet) ⇒ Object



20
21
22
# File 'lib/ruby_arena/arena.rb', line 20

def add_bullet(bullet)
  @bullets << bullet
end

#add_robot(robot) ⇒ Object



15
16
17
18
# File 'lib/ruby_arena/arena.rb', line 15

def add_robot(robot)
  @robots << robot
  @total_robots_count += 1
end

#game_over?Boolean

Returns:



33
34
35
# File 'lib/ruby_arena/arena.rb', line 33

def game_over?
  robots_count <= 1 and total_robots_count > 1
end

#heightObject



45
46
47
# File 'lib/ruby_arena/arena.rb', line 45

def height
  HEIGHT
end

#robots_countObject



37
38
39
# File 'lib/ruby_arena/arena.rb', line 37

def robots_count
  robots.count
end

#updateObject



24
25
26
27
28
29
30
31
# 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

#widthObject



41
42
43
# File 'lib/ruby_arena/arena.rb', line 41

def width
  WIDTH
end