Skip to content

Instantly share code, notes, and snippets.

@slaxeea
Created August 9, 2020 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaxeea/3a198c3d91ce873e720e661f04fc534d to your computer and use it in GitHub Desktop.
Save slaxeea/3a198c3d91ce873e720e661f04fc534d to your computer and use it in GitHub Desktop.
spielerDran = 0
weiter="true"
win="false"
i=0
j=0
weiter="true"
feld= ["_","_","_","_","_","_","_","_","_"]
fill="|"
def spieler1():
cont(0)
def spieler2():
cont(1)
def gewonnen():
h=0
k="X"
while h<2:
horizontal(0,k)
horizontal(3,k)
horizontal(6,k)
vertikal(0,k)
vertikal(1,k)
vertikal(2,k)
diagonal(0,k)
k="O"
h+=1
def diagonal(valJ, z):
if feld[valJ]==z and feld[4]==z and feld[8]==z:
gewonnenMsg(feld[j])
if feld[valJ+2]==z and feld[4]==z and feld[6]==z:
gewonnenMsg(feld[j])
def horizontal(valJ, z):
if feld[valJ]==z and feld[valJ+1]==z and feld[valJ+2]==z:
gewonnenMsg(z)
def vertikal(valJ, z):
if feld[valJ]==z and feld[valJ+3]==z and feld[valJ+6]==z:
gewonnenMsg(z)
def gewonnenMsg(player):
print("Gratulation "+player+" hat gewonnen")
playagain()
def printfun():
row1=fill+feld[0]+fill+feld[1]+fill+feld[2]+fill+"\n"
row2=fill+feld[3]+fill+feld[4]+fill+feld[5]+fill+"\n"
row3=fill+feld[6]+fill+feld[7]+fill+feld[8]+fill+"\n"
output=row1+row2+row3
print(output)
def cont(player):
while weiter=="true":
try:
a=input()
inPut=int(a)
if inPut>-1 and inPut <10 and player==0 and feld[inPut]=="_":
feld[inPut]="X"
break
if inPut>-1 and inPut<10 and player==1 and feld[inPut]=="_":
feld[inPut]="O"
break
else:
falsch("Faulty input")
except:
falsch("Faulty input")
gewonnen()
def falsch(reason):
print("Something went wrong: "+reason)
def playagain():
print("So do you want to play again?")
d=input()
if d=="Yes":
return "true"
else:
print("Ok, hope you had fun!")
while weiter=="true":
printfun()
if spielerDran==0:
spielerDran=1
print("Spieler 1 isch dra")
spieler1()
else:
spielerDran=0
print("Spieler 2 isch dra")
spieler2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment