Class: Tictactoe

Inherits:
Object
  • Object
show all
Defined in:
lib/tictactoe.rb

Instance Method Summary collapse

Constructor Details

#initializeTictactoe

Returns a new instance of Tictactoe.



5
6
7
8
9
10
11
# File 'lib/tictactoe.rb', line 5

def initialize
  @moves = (0..8).to_a
  @computer_move = 4
  @playing = true
  @message = "Please enter your move".blue
  @continue = true
end

Instance Method Details

#play_gameObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tictactoe.rb', line 13

def play_game
  play_tictactoe
  if play_until_win
    who_won = winner.first == 'X' ? 'Computer' : 'You'
    puts '********************'
    display_board
    puts "#{who_won} Won".neon
  elsif play_until_draw
    puts '********************'
    display_board
    puts "It's a draw".neon
  end
end