Class: GameEngine::GameState
- Inherits:
-
Object
- Object
- GameEngine::GameState
- Defined in:
- lib/smack_engine/game_state.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#phase ⇒ Object
Returns the value of attribute phase.
-
#player_one ⇒ Object
readonly
Returns the value of attribute player_one.
-
#player_two ⇒ Object
readonly
Returns the value of attribute player_two.
-
#round ⇒ Object
Returns the value of attribute round.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
-
#initialize(game_data) ⇒ GameState
constructor
A new instance of GameState.
- #target_player(player_id) ⇒ Object
- #winner ⇒ Object
- #won? ⇒ Boolean
Constructor Details
#initialize(game_data) ⇒ GameState
Returns a new instance of GameState.
6 7 8 9 10 11 12 13 |
# File 'lib/smack_engine/game_state.rb', line 6 def initialize(game_data) @id = game_data.id @player_one = GameEngine::Player.new(game_data.player_one) @player_two = GameEngine::Player.new(game_data.player_two) @round = 0 @phase = :setup @time = Time.now end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/smack_engine/game_state.rb', line 3 def id @id end |
#phase ⇒ Object
Returns the value of attribute phase.
4 5 6 |
# File 'lib/smack_engine/game_state.rb', line 4 def phase @phase end |
#player_one ⇒ Object (readonly)
Returns the value of attribute player_one.
3 4 5 |
# File 'lib/smack_engine/game_state.rb', line 3 def player_one @player_one end |
#player_two ⇒ Object (readonly)
Returns the value of attribute player_two.
3 4 5 |
# File 'lib/smack_engine/game_state.rb', line 3 def player_two @player_two end |
#round ⇒ Object
Returns the value of attribute round.
4 5 6 |
# File 'lib/smack_engine/game_state.rb', line 4 def round @round end |
#time ⇒ Object
Returns the value of attribute time.
4 5 6 |
# File 'lib/smack_engine/game_state.rb', line 4 def time @time end |
Instance Method Details
#target_player(player_id) ⇒ Object
15 16 17 18 19 |
# File 'lib/smack_engine/game_state.rb', line 15 def target_player(player_id) return player_one if player_one.id.to_i == player_id.to_i return player_two if player_two.id.to_i == player_id.to_i raise ArgumentError.new("No player found with id = #{player_id}") end |
#winner ⇒ Object
21 22 23 24 |
# File 'lib/smack_engine/game_state.rb', line 21 def winner return player_one if player_one.points > 0 && player_two.points <= 0 return player_two if player_two.points > 0 && player_one.points <= 0 end |
#won? ⇒ Boolean
26 27 28 |
# File 'lib/smack_engine/game_state.rb', line 26 def won? winner != nil end |