added game over condition
This commit is contained in:
parent
5b09ea5b56
commit
4cc483caee
11
tik.rb
11
tik.rb
@ -22,21 +22,28 @@ def checkWin(board, x, o)
|
|||||||
if board[line[0]] == "X" and board[line[1]] == "X" and board[line[2]] == "X"
|
if board[line[0]] == "X" and board[line[1]] == "X" and board[line[2]] == "X"
|
||||||
puts "X WINS!!!!!!"
|
puts "X WINS!!!!!!"
|
||||||
exit
|
exit
|
||||||
elsif board[line[0]] == "X" and board[line[1]] == "X" and board[line[2]] == "X"
|
elsif board[line[0]] == "O" and board[line[1]] == "O" and board[line[2]] == "O"
|
||||||
puts "O WINS!!!!!!"
|
puts "O WINS!!!!!!"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def isBoardFull(board)
|
||||||
|
if not board.any?(0..9)
|
||||||
|
puts "GAME OVER"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
player = "X"
|
player = "X"
|
||||||
x = Array.new
|
x = Array.new
|
||||||
o = Array.new
|
o = Array.new
|
||||||
def play(board, player, x, o)
|
def play(board, player, x, o)
|
||||||
|
isBoardFull(board)
|
||||||
printBoard(board)
|
printBoard(board)
|
||||||
print "Place an #{player} "
|
print "Place an #{player} "
|
||||||
input = gets.to_i
|
input = gets.to_i
|
||||||
p input
|
|
||||||
if board.include?(input)
|
if board.include?(input)
|
||||||
else
|
else
|
||||||
puts "Bad input, pick a valid position"
|
puts "Bad input, pick a valid position"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user