Created
April 29, 2013 22:08
-
-
Save daryo918/5485193 to your computer and use it in GitHub Desktop.
triqui en consola
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/python | |
# triqui version 1.0 | |
import os | |
import time | |
# comprobar si es linux para el comando clear o cls windows | |
if os.name == "posix": | |
clear = "clear" | |
else: | |
clear = "cls" | |
os.system("title by daryo") | |
os.system("color f1") | |
n = [] | |
for a in range(9): | |
a+=1 | |
a = "%i" % a | |
n.append(a) | |
def pantalla(): | |
os.system(clear) | |
print """ | |
------------------------------ | |
| tres en linea :) | | |
------------------------------ | |
""" | |
print "%s|%s|%s" % (n[0],n[1],n[2]) | |
print "-----" | |
print "%s|%s|%s" % (n[3],n[4],n[5]) | |
print "-----" | |
print "%s|%s|%s" % (n[6],n[7],n[8]) | |
def gana(): | |
jugadores = ["o","x"] | |
for jug in jugadores: | |
# estas son las horizontales | |
if n[0] == jug and n[1] == jug and n[2] == jug: | |
gano(jug) | |
elif n[3] == jug and n[4] == jug and n[5] == jug: | |
gano(jug) | |
elif n[6] == jug and n[7] == jug and n[8] == jug: | |
gano(jug) | |
# estas son las verticales | |
elif n[0] == jug and n[3] == jug and n[6] == jug: | |
gano(jug) | |
elif n[1] == jug and n[4] == jug and n[7] == jug: | |
gano(jug) | |
elif n[2] == jug and n[5] == jug and n[8] == jug: | |
gano(jug) | |
# estas son las diagonales | |
elif n[0] == jug and n[4] == jug and n[8] == jug: | |
gano(jug) | |
elif n[6] == jug and n[4] == jug and n[2] == jug: | |
gano(jug) | |
else: | |
pass | |
def gano(jug): | |
os.system(clear) | |
print "ganaron las %s!" % jug | |
time.sleep(3) | |
exit() | |
while True: | |
while True: | |
pantalla() | |
print "jugador uno su turno" | |
z = input("ponga el numero de la casilla > ") | |
try: | |
z-=1 | |
if n[z] != "o" and n[z] != "x": | |
n[z]="o" | |
gana() | |
pantalla() | |
break | |
else: | |
print "posicion invalida" | |
time.sleep(2) | |
except: | |
time.sleep(2) | |
pantalla() | |
while True: | |
pantalla() | |
print "jugador dos su turno" | |
h = input("ponga el numero de la casilla>") | |
try: | |
h-=1 | |
if n[h] != "o" and n[h] != "x": | |
n[h]="x" | |
gana() | |
pantalla() | |
break | |
else: | |
print "posicion invalida" | |
time.sleep(2) | |
except: | |
time.sleep(2) | |
pantalla() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment