added game board and UI
This commit is contained in:
parent
ea98681d42
commit
7865ae49de
39
tik.rb
Normal file
39
tik.rb
Normal file
@ -0,0 +1,39 @@
|
||||
#tiktaktoe
|
||||
|
||||
|
||||
LINES = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
|
||||
|
||||
board = Array.new(9)
|
||||
9.times do |i|
|
||||
board[i] = i
|
||||
end
|
||||
|
||||
def printBoard(board)
|
||||
9.times do |i|
|
||||
if i % 3 == 0
|
||||
print "\n -------------\n | "
|
||||
end
|
||||
print "#{board[i]} | "
|
||||
end
|
||||
print "\n -------------\n"
|
||||
end
|
||||
|
||||
|
||||
#if x is in lines then x wins
|
||||
#if o is in lines then x wins
|
||||
#if no nums in board then game over
|
||||
|
||||
player = "X"
|
||||
loop do
|
||||
print "Place an #{player} "
|
||||
input = gets.to_i
|
||||
p input
|
||||
p board.include?(input)
|
||||
board[input] = player
|
||||
printBoard(board)
|
||||
if player == "X"
|
||||
player = "O"
|
||||
else
|
||||
player = "X"
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user