Created
December 5, 2015 20:29
-
-
Save sinclairtarget/0bd4f321615b7556c862 to your computer and use it in GitHub Desktop.
Tic Tac Toe Code Now
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 | |
puts "Starting Tic Tac Toe" | |
# part 1 | |
puts "Player 1, choose X or 0" | |
player_one = gets.chomp | |
if player_one == "x" or player_one == "X" | |
player_one = "X" | |
player_two = "O" | |
else | |
player_one = "O" | |
player_two = "X" | |
end | |
puts "Player 1, your symbol is: #{player_one}" | |
puts "Plyaer 2, your symbol is: #{player_two}" | |
# -------- | |
# part 2 | |
puts "Who will go first? Enter the symbol for the player you'd like to go first:" | |
player = gets.chomp | |
if player == "x" or player == "X" | |
player = player_one | |
else | |
player = player_two | |
end | |
# ---- | |
board = Array.new(3) { Array.new(3) } | |
game.initBoard(board) | |
game.displayBoard(board) | |
game_over = false | |
begin | |
begin | |
puts "Player ##{player}, choose a space:" | |
game.displayBoard(board) | |
choice = gets.chomp.to_i - 1 | |
turn_played = game.turnPlayed(board, player, choice) | |
end while not turn_played | |
if game.winningRows(board) || game.winningCols(board) || game.winningDiagonals(board) | |
puts "Player ##{player} wins!" | |
game_over = true | |
elsif game.fullBoard(board) | |
puts "It's a tie!" | |
game_over = true | |
else | |
if player == player_one | |
player = player_two | |
else | |
player = player_one | |
end | |
end | |
end while not game_over | |
game.displayBoard(board) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment