Class: Game
- Inherits:
-
Object
- Object
- Game
- Defined in:
- lib/ttt_malisa/game.rb
Instance Attribute Summary collapse
-
#player_one ⇒ Object
readonly
Returns the value of attribute player_one.
-
#player_two ⇒ Object
readonly
Returns the value of attribute player_two.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #game_over_message ⇒ Object
-
#initialize(display, rules, player_one, player_two) ⇒ Game
constructor
A new instance of Game.
- #play ⇒ Object
- #start ⇒ Object
- #turn ⇒ Object
Constructor Details
#initialize(display, rules, player_one, player_two) ⇒ Game
Returns a new instance of Game.
8 9 10 11 12 13 14 |
# File 'lib/ttt_malisa/game.rb', line 8 def initialize(display, rules, player_one, player_two) @rules = rules @display = display @player_one = player_one @player_two = player_two @current_player = @player_one end |
Instance Attribute Details
#player_one ⇒ Object (readonly)
Returns the value of attribute player_one.
6 7 8 |
# File 'lib/ttt_malisa/game.rb', line 6 def player_one @player_one end |
#player_two ⇒ Object (readonly)
Returns the value of attribute player_two.
6 7 8 |
# File 'lib/ttt_malisa/game.rb', line 6 def player_two @player_two end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
6 7 8 |
# File 'lib/ttt_malisa/game.rb', line 6 def rules @rules end |
Instance Method Details
#game_over_message ⇒ Object
34 35 36 |
# File 'lib/ttt_malisa/game.rb', line 34 def winner ? @display.(@current_player.mark) : @display. end |
#play ⇒ Object
28 29 30 31 32 |
# File 'lib/ttt_malisa/game.rb', line 28 def play @display.board turn until rules.game_over? end |
#start ⇒ Object
16 17 18 19 |
# File 'lib/ttt_malisa/game.rb', line 16 def start @display.welcome play end |
#turn ⇒ Object
21 22 23 24 25 26 |
# File 'lib/ttt_malisa/game.rb', line 21 def turn @display.alert_current_player(@current_player) @current_player.move @display.board switch_players end |