Created
May 21, 2016 19:26
-
-
Save angelxmoreno/6821f54f2a28d59af2527175a5f5108e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tic_tac_toe_cn' | |
game = Tic_Tac_Toe.new | |
board = Array.new(3) {Array.new(3)} | |
game.initBoard(board) | |
puts "Starting Tic Tac Toe" | |
puts "Player 1 choose X or O" | |
playerOne = gets.chomp.upcase | |
if playerOne == "X" | |
playerTwo = "O" | |
else | |
playerOne = "O" | |
playerTwo = "X" | |
end | |
puts "Player 1: ##{playerOne}" | |
puts "Player 2: ##{playerTwo}" | |
puts "Who will go first? Type ##{playerOne} for Player 1 and ##{playerTwo} for Player 2" | |
player = gets.chomp.upcase | |
game.displayBoard(board) | |
gameOver = false | |
# main game loop | |
begin | |
# turnPlayed = false | |
begin | |
puts "Player ##{player}, choose a space" | |
##note: the player chooses between 1 and 9 but the computer counts from 0 to 8 | |
playerChoice = (gets.chomp.to_i) - 1 | |
turnPlayed = game.turnPlayed(board,player,playerChoice) | |
game.displayBoard(board) | |
end until turnPlayed | |
if game.winningRows(board) || game.winningCols(board) || game.winningDiagonals(board) | |
puts "Player ##{player} wins!" | |
gameOver = true | |
elsif game.fullBoard(board) | |
puts "It's a Draw!!" | |
gameOver = true | |
else | |
if player == playerOne | |
player = playerTwo | |
else | |
player = playerOne | |
end | |
end | |
end until gameOver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment