Skip to content

Instantly share code, notes, and snippets.

@bramleyjl
Created June 3, 2017 12:06
Show Gist options
  • Save bramleyjl/e66305a66961e5c674060d0f420c344e to your computer and use it in GitHub Desktop.
Save bramleyjl/e66305a66961e5c674060d0f420c344e to your computer and use it in GitHub Desktop.
Tic Tac Toe Game
class GameActions
def initialize
@board = {1 => 1, 2 => 2, 3=> 3, 4=> 4, 5=> 5, 6=> 6, 7=> 7, 8=> 8, 9=> 9}
@player_switch = false
end
def display()
print @board[1], @board[2], @board[3], "\n"
print @board[4], @board[5], @board[6], "\n"
print @board[7], @board[8], @board[9], "\n"
if @player_switch == false
print "Turn: X", "\n"
else
print "Turn: O" "\n"
end
end
def choose_tile(number)
if @board.has_key?(number) == true && @board[number] == number
if @player_switch == false
@board[number] = "X"
@player_switch = true
self.display()
else
@board[number] = "O"
@player_switch = false
self.display()
end
else
puts "Please choose an unchosen tile [1-9]."
end
end
end
new_game = GameActions.new
new_game.display
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment