Skip to content

Instantly share code, notes, and snippets.

@AnimaWish
Created February 9, 2012 04:38
Show Gist options
  • Save AnimaWish/1777339 to your computer and use it in GitHub Desktop.
Save AnimaWish/1777339 to your computer and use it in GitHub Desktop.
puts "Welcome to Super Tic-Tac-Toe. I wear shiny spandex."
#---opp CHOOSER
teamrand = rand(0..1)
if teamrand == 0
team = 'x'
opp = 'o'
puts "You're x, you go first."
elsif teamrand == 1
team = 'o'
opp = 'x'
puts "You're o, you go second."
end
#---GAME DATA ARRAYS
barray = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]]
carray = [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil]]
#---THE BOARD FOR VIEWING
def board(barray)
puts "%s|%s|%s" % barray[0]
puts "-----"
puts "%s|%s|%s" % barray[1]
puts "-----"
puts "%s|%s|%s" % barray[2]
end
#---WIN CHECK METHOD
def wincheck(barray, carray, team, opp)
if
(barray[0][0] == team and barray[0][1] == team and barray[0][2] == team) or
(barray[1][0] == team and barray[1][1] == team and barray[1][2] == team) or
(barray[2][0] == team and barray[2][1] == team and barray[2][2] == team) or
(barray[0][0] == team and barray[1][0] == team and barray[2][0] == team) or
(barray[0][1] == team and barray[1][1] == team and barray[2][1] == team) or
(barray[0][2] == team and barray[1][2] == team and barray[2][2] == team) or
(barray[0][0] == team and barray[1][1] == team and barray[2][2] == team) or
(barray[2][0] == team and barray[1][1] == team and barray[0][2] == team) or
puts "~~~~ YOU WIN ~~~~"
elsif
(barray[0][0] == opp and barray[0][1] == opp and barray[0][2] == opp) or
(barray[1][0] == opp and barray[1][1] == opp and barray[1][2] == opp) or
(barray[2][0] == opp and barray[2][1] == opp and barray[2][2] == opp) or
(barray[0][0] == opp and barray[1][0] == opp and barray[2][0] == opp) or
(barray[0][1] == opp and barray[1][1] == opp and barray[2][1] == opp) or
(barray[0][2] == opp and barray[1][2] == opp and barray[2][2] == opp) or
(barray[0][0] == opp and barray[1][1] == opp and barray[2][2] == opp) or
(barray[2][0] == opp and barray[1][1] == opp and barray[0][2] == opp) or
puts "____ YOU LOSE ____"
end
end
#---GAME LOOP
loop do
puts "Here's the board."
board(barray)
puts team
llama = gets.chomp.upcase
if llama == "Q"
break
end
wincheck(barray, carray, team, opp)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment