winner add 2 if's for names the winner
This commit is contained in:
parent
05b66c6514
commit
fb15ab05c9
48
main.py
48
main.py
@ -71,45 +71,21 @@ if name_players():
|
|||||||
|
|
||||||
def check_win(): # Prüfung ob 3 Felder mit X oder O hintereinander (Horizontal, Waagerecht, Diagonal) belegt sind.
|
def check_win(): # Prüfung ob 3 Felder mit X oder O hintereinander (Horizontal, Waagerecht, Diagonal) belegt sind.
|
||||||
if field[1] == field[2] == field[3]:
|
if field[1] == field[2] == field[3]:
|
||||||
if field[1] == '\x1b[1;34m' "X" '\x1b[1;0m':
|
return field[1]
|
||||||
return name_player1
|
|
||||||
elif field[1] == '\x1b[1;31m' "O" '\x1b[1;0m':
|
|
||||||
return name_player2
|
|
||||||
if field[4] == field[5] == field[6]:
|
if field[4] == field[5] == field[6]:
|
||||||
if field[4] == '\x1b[1;34m' "X" '\x1b[1;0m':
|
return field[4]
|
||||||
return name_player1
|
|
||||||
elif field[4] == '\x1b[1;31m' "O" '\x1b[1;0m':
|
|
||||||
return name_player2
|
|
||||||
if field[7] == field[8] == field[9]:
|
if field[7] == field[8] == field[9]:
|
||||||
if field[7] == '\x1b[1;34m' "X" '\x1b[1;0m':
|
return field[7]
|
||||||
return name_player1
|
|
||||||
elif field[7] == '\x1b[1;31m' "O" '\x1b[1;0m':
|
|
||||||
return name_player2
|
|
||||||
if field[1] == field[4] == field[7]:
|
if field[1] == field[4] == field[7]:
|
||||||
if field[1] == '\x1b[1;34m' "X" '\x1b[1;0m':
|
return field[1]
|
||||||
return name_player1
|
|
||||||
elif field[1] == '\x1b[1;31m' "O" '\x1b[1;0m':
|
|
||||||
return name_player2
|
|
||||||
if field[2] == field[5] == field[8]:
|
if field[2] == field[5] == field[8]:
|
||||||
if field[2] == '\x1b[1;34m' "X" '\x1b[1;0m':
|
return field[2]
|
||||||
return name_player1
|
|
||||||
elif field[2] == '\x1b[1;31m' "O" '\x1b[1;0m':
|
|
||||||
return name_player2
|
|
||||||
if field[3] == field[6] == field[9]:
|
if field[3] == field[6] == field[9]:
|
||||||
if field[3] == '\x1b[1;34m' "X" '\x1b[1;0m':
|
return field[3]
|
||||||
return name_player1
|
|
||||||
elif field[3] == '\x1b[1;31m' "O" '\x1b[1;0m':
|
|
||||||
return name_player2
|
|
||||||
if field[1] == field[5] == field[9]:
|
if field[1] == field[5] == field[9]:
|
||||||
if field[1] == '\x1b[1;34m' "X" '\x1b[1;0m':
|
return field[1]
|
||||||
return name_player1
|
|
||||||
elif field[1] == '\x1b[1;31m' "O" '\x1b[1;0m':
|
|
||||||
return name_player2
|
|
||||||
if field[3] == field[5] == field[7]:
|
if field[3] == field[5] == field[7]:
|
||||||
if field[3] == '\x1b[1;34m' "X" '\x1b[1;0m':
|
return field[3]
|
||||||
return name_player1
|
|
||||||
elif field[3] == '\x1b[1;31m' "O" '\x1b[1;0m':
|
|
||||||
return name_player2
|
|
||||||
|
|
||||||
|
|
||||||
def draw_game(): # Diese funktion prüft das Spielfeld auf X oder O also, ob keine Zahlen mehr vorhanden sind.
|
def draw_game(): # Diese funktion prüft das Spielfeld auf X oder O also, ob keine Zahlen mehr vorhanden sind.
|
||||||
@ -127,8 +103,12 @@ while run: # Das ist die Gameloop. Die Schleife wurde hier mit run auf True ges
|
|||||||
field[sel_field] = player
|
field[sel_field] = player
|
||||||
winner = check_win()
|
winner = check_win()
|
||||||
if winner:
|
if winner:
|
||||||
print("Spieler " + winner + " hat gewonnen!")
|
if winner == '\x1b[1;34m' "X" '\x1b[1;0m':
|
||||||
run = False
|
print("Spieler " + name_player1 + " hat gewonnen.")
|
||||||
|
run = False
|
||||||
|
if winner == '\x1b[1;31m' "0" '\x1b[1;0m':
|
||||||
|
print("Spieler " + name_player2 + " hat gewonnen.")
|
||||||
|
run = False
|
||||||
else:
|
else:
|
||||||
if draw_game():
|
if draw_game():
|
||||||
print("Spiel ist unentschieden...")
|
print("Spiel ist unentschieden...")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user