class Game
Attributes
player_one[R]
player_two[R]
rules[R]
Public Class Methods
new(display, rules, player_one, player_two)
click to toggle source
# 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
Public Instance Methods
game_over_message()
click to toggle source
# File lib/ttt_malisa/game.rb, line 34 def game_over_message winner ? @display.winner_message(@current_player.mark) : @display.draw_message end
play()
click to toggle source
# File lib/ttt_malisa/game.rb, line 28 def play @display.board turn until rules.game_over? game_over_message end
start()
click to toggle source
# File lib/ttt_malisa/game.rb, line 16 def start @display.welcome play end
turn()
click to toggle source
# File lib/ttt_malisa/game.rb, line 21 def turn @display.alert_current_player(@current_player) @current_player.move @display.board switch_players end
Private Instance Methods
switch_players()
click to toggle source
# File lib/ttt_malisa/game.rb, line 40 def switch_players if !rules.game_over? @current_player == @player_one ? @current_player = @player_two : @current_player = @player_one end end
winner()
click to toggle source
# File lib/ttt_malisa/game.rb, line 46 def winner @current_player if rules.winning_combination? end