aboutsummaryrefslogtreecommitdiffstats
path: root/main.rb
diff options
context:
space:
mode:
authorTeddy Wing2015-04-16 02:13:04 -0400
committerTeddy Wing2015-04-16 02:13:04 -0400
commit6984fc31370564332ceab60c203cd6f1e695d61a (patch)
treea53d6b3ecf3c1ba4f35fcd245c30757e1a266e11 /main.rb
parentfa951e520b7637d9e67c31a0a8b61733e253f90b (diff)
parent93351518faf3bb4f63b4a3cc1ef28f5c06e09f01 (diff)
downloadtic-tac-toe-master.tar.bz2
Merge branch 'rspec-style'HEADmaster
Diffstat (limited to 'main.rb')
-rw-r--r--main.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/main.rb b/main.rb
new file mode 100644
index 0000000..835d6c5
--- /dev/null
+++ b/main.rb
@@ -0,0 +1,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