This repository has been archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiskvorky3x3.py
116 lines (98 loc) · 3.46 KB
/
piskvorky3x3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
line0 = ["0","1","2","3"]
line1 = ["1"," "," "," "]
line2 = ["2"," "," "," "]
line3 = ["3"," "," "," "]
all_sets = [line0, line1, line2, line3]
def hrac1():
print(f"Hraje {player1}:")
while True:
num1 = input("Zadej hodnotu x (řada): ")
try:
num1 = int(num1)
except ValueError:
print ("Špatná volba, musíš zadat číslo 1-3.")
else:
break
while True:
num2 = input("Zadej hodnotu y (sloupec): ")
try:
num2 = int(num2)
except ValueError:
print ("Špatná volba, musíš zadat číslo 1-3.")
else:
break
if all_sets[num1][num2] != " ":
print("Špatná volba, zvol znovu")
hrac1()
else:
all_sets[num1][num2] = "X"
def hrac2():
print(f"Hraje {player2}:")
while True:
num3 = input("Zadej hodnotu x (řada): ")
try:
num3 = int(num3)
except ValueError:
print ("Špatná volba, musíš zadat číslo 1-3.")
else:
break
while True:
num4 = input("Zadej hodnotu y (sloupec): ")
try:
num4 = int(num4)
except ValueError:
print ("Špatná volba, musíš zadat číslo 1-3.")
else:
break
if all_sets[num3][num4] != " ":
print("Špatná volba, zvol znovu")
hrac2()
else:
all_sets[num3][num4] = "O"
print("Vítejte ve hře Piškvorky junior.")
player1 = input("Jak se jmenuje první hráč?\n")
player2 = input("A jak se jmenuje protivník?\n")
print("Těší mě! Pojďme hrát!")
print("-" * 50)
while True:
hrac1()
print(f"{line0}\n{line1}\n{line2}\n{line3}")
if all_sets[1][1] == "X" and all_sets[1][2] == "X" and all_sets[1][3] == "X":
print(f"Vyhrál hráč {player1}")
break
elif all_sets[2][1] == "X" and all_sets[2][2] == "X" and all_sets[2][3] == "X":
print(f"Vyhrál hráč {player1}")
break
elif all_sets[3][1] == "X" and all_sets[3][2] == "X" and all_sets[3][3] == "X":
print(f"Vyhrál hráč {player1}")
break
elif all_sets[1][1] == "X" and all_sets[2][2] == "X" and all_sets[3][3] == "X":
print(f"Vyhrál hráč {player1}")
break
elif all_sets[3][1] == "X" and all_sets[2][2] == "X" and all_sets[1][3] == "X":
print(f"Vyhrál hráč {player1}")
break
elif all_sets[1][3] == "X" and all_sets[2][3] == "X" and all_sets[3][3] == "X":
print(f"Vyhrál hráč {player1}")
break
hrac2()
print(f"{line0}\n{line1}\n{line2}\n{line3}")
if all_sets[1][1] == "O" and all_sets[1][2] == "O" and all_sets[1][3] == "O":
print(f"Vyhrál hráč {player2}")
break
elif all_sets[2][1] == "O" and all_sets[2][2] == "O" and all_sets[2][3] == "O":
print(f"Vyhrál hráč {player2}")
break
elif all_sets[3][1] == "O" and all_sets[3][2] == "O" and all_sets[3][3] == "O":
print(f"Vyhrál hráč {player2}")
break
elif all_sets[1][1] == "O" and all_sets[2][2] == "O" and all_sets[3][3] == "O":
print(f"Vyhrál hráč {player2}")
break
elif all_sets[3][1] == "O" and all_sets[2][2] == "O" and all_sets[1][3] == "O":
print(f"Vyhrál hráč {player2}")
break
elif all_sets[1][3] == "O" and all_sets[2][3] == "O" and all_sets[3][3] == "O":
print(f"Vyhrál hráč {player2}")
break
print("Díky za hru!")