Class: Rubygoal::Game
- Inherits:
-
Object
- Object
- Rubygoal::Game
- Defined in:
- lib/rubygoal/game.rb
Instance Attribute Summary collapse
-
#ball ⇒ Object
readonly
Returns the value of attribute ball.
-
#coach_away ⇒ Object
readonly
Returns the value of attribute coach_away.
-
#coach_home ⇒ Object
readonly
Returns the value of attribute coach_home.
-
#goal ⇒ Object
readonly
Returns the value of attribute goal.
-
#recorder ⇒ Object
readonly
Returns the value of attribute recorder.
-
#score_away ⇒ Object
readonly
Returns the value of attribute score_away.
-
#score_home ⇒ Object
readonly
Returns the value of attribute score_home.
-
#team_away ⇒ Object
readonly
Returns the value of attribute team_away.
-
#team_home ⇒ Object
readonly
Returns the value of attribute team_home.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #away_players_positions ⇒ Object
- #ball_position ⇒ Object
- #celebrating_goal? ⇒ Boolean
- #ended? ⇒ Boolean
- #home_players_positions ⇒ Object
-
#initialize(coach_home, coach_away) ⇒ Game
constructor
A new instance of Game.
- #players ⇒ Object
- #recorded_game ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(coach_home, coach_away) ⇒ Game
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubygoal/game.rb', line 15 def initialize(coach_home, coach_away) @coach_home = coach_home @coach_away = coach_away if debug_output? puts "Home coach: #{@coach_home.name}" puts "Away coach: #{@coach_away.name}" end @recorder = Recorder.new(self) if record_game? @ball = Ball.new @team_home = HomeTeam.new(self, coach_home) @team_away = AwayTeam.new(self, coach_away) @goal = Goal.new @state = :playing @time = Rubygoal.configuration.game_time @score_home = 0 @score_away = 0 reinitialize_players end |
Instance Attribute Details
#ball ⇒ Object (readonly)
Returns the value of attribute ball.
10 11 12 |
# File 'lib/rubygoal/game.rb', line 10 def ball @ball end |
#coach_away ⇒ Object (readonly)
Returns the value of attribute coach_away.
10 11 12 |
# File 'lib/rubygoal/game.rb', line 10 def coach_away @coach_away end |
#coach_home ⇒ Object (readonly)
Returns the value of attribute coach_home.
10 11 12 |
# File 'lib/rubygoal/game.rb', line 10 def coach_home @coach_home end |
#goal ⇒ Object (readonly)
Returns the value of attribute goal.
10 11 12 |
# File 'lib/rubygoal/game.rb', line 10 def goal @goal end |
#recorder ⇒ Object (readonly)
Returns the value of attribute recorder.
10 11 12 |
# File 'lib/rubygoal/game.rb', line 10 def recorder @recorder end |
#score_away ⇒ Object
Returns the value of attribute score_away.
10 11 12 |
# File 'lib/rubygoal/game.rb', line 10 def score_away @score_away end |
#score_home ⇒ Object
Returns the value of attribute score_home.
10 11 12 |
# File 'lib/rubygoal/game.rb', line 10 def score_home @score_home end |
#team_away ⇒ Object (readonly)
Returns the value of attribute team_away.
10 11 12 |
# File 'lib/rubygoal/game.rb', line 10 def team_away @team_away end |
#team_home ⇒ Object (readonly)
Returns the value of attribute team_home.
10 11 12 |
# File 'lib/rubygoal/game.rb', line 10 def team_home @team_home end |
#time ⇒ Object
Returns the value of attribute time.
10 11 12 |
# File 'lib/rubygoal/game.rb', line 10 def time @time end |
Instance Method Details
#away_players_positions ⇒ Object
73 74 75 |
# File 'lib/rubygoal/game.rb', line 73 def away_players_positions team_away.players_position end |
#ball_position ⇒ Object
77 78 79 |
# File 'lib/rubygoal/game.rb', line 77 def ball_position ball.position end |
#celebrating_goal? ⇒ Boolean
65 66 67 |
# File 'lib/rubygoal/game.rb', line 65 def goal. end |
#ended? ⇒ Boolean
85 86 87 |
# File 'lib/rubygoal/game.rb', line 85 def ended? state == :ended end |
#home_players_positions ⇒ Object
69 70 71 |
# File 'lib/rubygoal/game.rb', line 69 def home_players_positions team_home.players_position end |
#players ⇒ Object
61 62 63 |
# File 'lib/rubygoal/game.rb', line 61 def players teams.map(&:players_list).flatten end |
#recorded_game ⇒ Object
81 82 83 |
# File 'lib/rubygoal/game.rb', line 81 def recorded_game recorder.to_hash if record_game? end |
#update ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubygoal/game.rb', line 42 def update return if ended? update_elapsed_time if update_goal else update_remaining_time team_home.update(elapsed_time) team_away.update(elapsed_time) update_ball end recorder.update if record_game? end_match! if time <= 0 end |