Last active
September 21, 2018 16:47
-
-
Save allisonburtch/53a1bf7b9c59fec88838e872a8296b3d to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
#create a board | |
def show_board(board) | |
puts " #{board[0]} | #{board[1]} | #{board[2]} " | |
puts "-----------" | |
puts " #{board[3]} | #{board[4]} | #{board[5]} " | |
puts "-----------" | |
puts " #{board[6]} | #{board[7]} | #{board[8]} " | |
end | |
board = [" ", " ", " ", " ", " ", " ", " ", " ", " "] | |
#create and name players | |
def name_players | |
puts "Player 1 what is your name?" | |
@player1 = gets.chomp.to_s | |
puts "Player 2 what is your name?" | |
@player2 = gets.chomp.to_s | |
end | |
name_players | |
#get the players move as a form of input | |
def take_turns | |
turn =0 | |
while turn <8 | |
puts "What grid number are you choosing?" | |
@entry = gets.chomp.to_i | |
turn += 1 | |
end | |
end | |
take_turns | |
show_board(board) | |
#board[@entry] | |
# if player1 | |
# puts "X" | |
# else | |
# puts "O" | |
# end | |
#check to make sure that their move is valid | |
#figure out how to check to see if the game has been won or came to a draw | |
#update board | |
WIN_COMBINATIONS = [ | |
[0,1,2], #top | |
[3,4,5], #middlehor | |
[6,7,8], #bottom | |
[0,3,6], #left | |
[1,4,7], #middlevert | |
[2,5,8], #right | |
[0,4,8], #diag1 | |
[2,4,6] #diag2 | |
] | |
#change players and let other player make a move | |
#repeat loop until the game is over |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment