Class: Rubots::Game
- Inherits:
-
Object
- Object
- Rubots::Game
- Defined in:
- lib/rubots/game.rb
Constant Summary collapse
- MAP_HEIGHT =
700- MAP_WIDTH =
1000- CELL_SIZE =
Positioning cell
40
Instance Attribute Summary collapse
-
#laser_beams ⇒ Object
readonly
Returns the value of attribute laser_beams.
-
#robots ⇒ Object
readonly
Returns the value of attribute robots.
Instance Method Summary collapse
-
#initialize(robots) ⇒ Game
constructor
A new instance of Game.
- #laser_fire(beam) ⇒ Object
- #map ⇒ Object
- #over? ⇒ Boolean
- #tick ⇒ Object
- #winner ⇒ Object
Constructor Details
Instance Attribute Details
#laser_beams ⇒ Object (readonly)
Returns the value of attribute laser_beams.
3 4 5 |
# File 'lib/rubots/game.rb', line 3 def laser_beams @laser_beams end |
#robots ⇒ Object (readonly)
Returns the value of attribute robots.
3 4 5 |
# File 'lib/rubots/game.rb', line 3 def robots @robots end |
Instance Method Details
#laser_fire(beam) ⇒ Object
26 27 28 |
# File 'lib/rubots/game.rb', line 26 def laser_fire(beam) @laser_beams << beam end |
#map ⇒ Object
22 23 24 |
# File 'lib/rubots/game.rb', line 22 def map OpenStruct.new width: MAP_WIDTH, height: MAP_HEIGHT end |
#over? ⇒ Boolean
30 31 32 |
# File 'lib/rubots/game.rb', line 30 def over? @robots.count <= 1 end |
#tick ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/rubots/game.rb', line 12 def tick @laser_beams = [] @robots.each { |robot| robot.process_command } @robots.each { |robot| robot.tick } check_collisions check_out_of_area check_beam_hits clean_up_bodies end |
#winner ⇒ Object
34 35 36 37 38 |
# File 'lib/rubots/game.rb', line 34 def winner return nil unless over? @robots.first || OpenStruct.new(name: "Nobody") end |