Class: RubyArena::Arena
- Inherits:
-
Object
- Object
- RubyArena::Arena
- Defined in:
- lib/ruby_arena/arena.rb
Constant Summary collapse
- WIDTH =
800- HEIGHT =
600
Instance Attribute Summary collapse
-
#bullets ⇒ Object
readonly
Returns the value of attribute bullets.
-
#robots ⇒ Object
readonly
Returns the value of attribute robots.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#total_robots_count ⇒ Object
readonly
Returns the value of attribute total_robots_count.
Instance Method Summary collapse
- #add_bullet(bullet) ⇒ Object
- #add_robot(robot) ⇒ Object
- #game_over? ⇒ Boolean
- #height ⇒ Object
-
#initialize ⇒ Arena
constructor
A new instance of Arena.
- #robots_count ⇒ Object
- #update ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize ⇒ Arena
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
#bullets ⇒ Object (readonly)
Returns the value of attribute bullets.
6 7 8 |
# File 'lib/ruby_arena/arena.rb', line 6 def bullets @bullets end |
#robots ⇒ Object (readonly)
Returns the value of attribute robots.
6 7 8 |
# File 'lib/ruby_arena/arena.rb', line 6 def robots @robots end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
6 7 8 |
# File 'lib/ruby_arena/arena.rb', line 6 def time @time end |
#total_robots_count ⇒ Object (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
33 34 35 |
# File 'lib/ruby_arena/arena.rb', line 33 def game_over? robots_count <= 1 and total_robots_count > 1 end |
#height ⇒ Object
45 46 47 |
# File 'lib/ruby_arena/arena.rb', line 45 def height HEIGHT end |
#robots_count ⇒ Object
37 38 39 |
# File 'lib/ruby_arena/arena.rb', line 37 def robots_count robots.count end |
#update ⇒ Object
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 |
#width ⇒ Object
41 42 43 |
# File 'lib/ruby_arena/arena.rb', line 41 def width WIDTH end |