aboutsummaryrefslogtreecommitdiffstats
path: root/main.rb
blob: 835d6c5471f0be805fb9ca2995affcb82bc8a09b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require_relative 'board'
require_relative 'player'

board = Board.new
player_1 = Player.new(Player::INSIGNIAS[:x], board)
player_2 = Player.new(Player::INSIGNIAS[:o], board)
board.current_player = player_1
winner = nil

begin
  until winner
    puts board.render
    puts
    
    print "Player #{board.current_player.insignia} move - " \
      "Enter coordinates (e.g. 0,2): "
    
    coordinates = gets.chomp
    coordinates = board.transform_coordinates(coordinates)
    
    board.current_player.move(coordinates)
    
    board.current_player = board.current_player == player_1 ? player_2 : player_1
    
    puts '----'
    
    winner = board.winner?
    if winner
      puts board.render
      puts "Player #{winner} wins"
    end
  end
rescue Interrupt
  puts
end