refactor: převod rekurze na smyčky v game() a add_players() #12
@@ -148,41 +148,46 @@ def check_value(throw: str) -> bool:
|
|||||||
|
|
||||||
return hodnota
|
return hodnota
|
||||||
|
|
||||||
def add_players(iter=False):
|
def add_players():
|
||||||
global players
|
global pointer, first, final_score
|
||||||
global pointer
|
|
||||||
global first
|
|
||||||
global final_score
|
|
||||||
|
|
||||||
if not iter:
|
while True:
|
||||||
var = "prvního hráče"
|
inp = input("Zadejte jméno prvního hráče: ")
|
||||||
else:
|
if inp == "":
|
||||||
var = "dalšího hráče nebo [x] pro ukončení zadávání hráčů"
|
print("Jméno nemůže být prázdné.")
|
||||||
|
else:
|
||||||
inp = input(f"Zadejte jméno {var}: ")
|
players[inp] = []
|
||||||
|
aggr[inp] = 0
|
||||||
|
pointer = inp
|
||||||
|
first = inp
|
||||||
|
print(f"Do seznamu přidáno jméno {inp}.")
|
||||||
|
break
|
||||||
|
|
||||||
if inp == "x":
|
while True:
|
||||||
if not iter:
|
inp = input("Zadejte jméno dalšího hráče nebo [x] pro ukončení zadávání hráčů: ")
|
||||||
add_players()
|
if inp == "":
|
||||||
inp = input("Zadejte finální skóre (nechte prázdné pro výchozích 10 000): ")
|
print("Jméno nemůže být prázdné.")
|
||||||
if inp != "":
|
elif inp == "x":
|
||||||
inp = int(inp)
|
break
|
||||||
final_score = inp
|
elif inp in players:
|
||||||
|
|
||||||
elif inp == "":
|
|
||||||
print("Jméno nemůže být prázdné.")
|
|
||||||
add_players(iter)
|
|
||||||
else:
|
|
||||||
if inp in players:
|
|
||||||
print("Zadávejte, prosím, unikátní jména.")
|
print("Zadávejte, prosím, unikátní jména.")
|
||||||
else:
|
else:
|
||||||
players[inp] = []
|
players[inp] = []
|
||||||
aggr[inp] = 0
|
aggr[inp] = 0
|
||||||
print(f"Do seznamu přidáno jméno {inp}.")
|
print(f"Do seznamu přidáno jméno {inp}.")
|
||||||
if not iter:
|
|
||||||
pointer = inp
|
while True:
|
||||||
first = inp
|
inp = input("Zadejte finální skóre (nechte prázdné pro výchozích 10 000): ")
|
||||||
add_players(True)
|
if inp != "":
|
||||||
|
try:
|
||||||
|
inp = int(inp)
|
||||||
|
final_score = inp
|
||||||
|
except ValueError:
|
||||||
|
print("Zadejte prosím platnou číselnou hodnotu.")
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
def check_win() -> str:
|
def check_win() -> str:
|
||||||
over_limit = {}
|
over_limit = {}
|
||||||
@@ -209,53 +214,53 @@ def check_win() -> str:
|
|||||||
return winner
|
return winner
|
||||||
|
|
||||||
def game(data: tuple):
|
def game(data: tuple):
|
||||||
if data[0] == "count":
|
while True:
|
||||||
count = data[1]
|
if data[0] == "count":
|
||||||
th = data[2]
|
count = data[1]
|
||||||
if(th == ""):
|
th = data[2]
|
||||||
th = throw(count)
|
if(th == ""):
|
||||||
clear()
|
th = throw(count)
|
||||||
print(f"Vítězné skóre: {final_score}.")
|
|
||||||
print(f"Na tahu je {pointer} ({aggr[pointer]}).")
|
|
||||||
print(show_throw(th))
|
|
||||||
if not check_value(th) and data[2] == "" and count != 0:
|
|
||||||
global score
|
|
||||||
score = 0
|
|
||||||
input("Oh no... anyway.")
|
|
||||||
data = evaluate("k", count, th)
|
|
||||||
game(data)
|
|
||||||
else:
|
|
||||||
if count == 0:
|
|
||||||
count = 6
|
|
||||||
msg = ("Jakou akci chcete provést?\n"
|
|
||||||
" - Zadejte kombinaci kostek k ponechání (dojde k jejich vyhodnocení): [pozice kostek] (např. 1 nebo 34 nebo 123456).\n"
|
|
||||||
" - Hodit znovu: [h].\n"
|
|
||||||
f" - Ukončit hod a ponechat si skóre z tohoto hodu ({score}): [k].\n"
|
|
||||||
)
|
|
||||||
inp = input(msg)
|
|
||||||
data = evaluate(inp, count, th)
|
|
||||||
game(data)
|
|
||||||
|
|
||||||
elif data[0] == "msg":
|
|
||||||
if data[1] == "ER01" or data[1] == "ER02" or data[1] == "ER03":
|
|
||||||
msg = data[2]
|
|
||||||
count = data[3]
|
|
||||||
th = data[4]
|
|
||||||
clear()
|
clear()
|
||||||
inp = input(msg)
|
print(f"Vítězné skóre: {final_score}.")
|
||||||
data = evaluate(inp, count, th)
|
print(f"Na tahu je {pointer} ({aggr[pointer]}).")
|
||||||
game(data)
|
print(show_throw(th))
|
||||||
else:
|
if not check_value(th) and data[2] == "" and count != 0:
|
||||||
msg = data[1]
|
global score
|
||||||
print(msg)
|
score = 0
|
||||||
|
input("Oh no... anyway.")
|
||||||
elif data[0] == "win":
|
data = evaluate("k", count, th)
|
||||||
winner = data[1]
|
else:
|
||||||
score = data[2]
|
if count == 0:
|
||||||
|
count = 6
|
||||||
|
msg = ("Jakou akci chcete provést?\n"
|
||||||
|
" - Zadejte kombinaci kostek k ponechání (dojde k jejich vyhodnocení): [pozice kostek] (např. 1 nebo 34 nebo 123456).\n"
|
||||||
|
" - Hodit znovu: [h].\n"
|
||||||
|
f" - Ukončit hod a ponechat si skóre z tohoto hodu ({score}): [k].\n"
|
||||||
|
)
|
||||||
|
inp = input(msg)
|
||||||
|
data = evaluate(inp, count, th)
|
||||||
|
|
||||||
clear()
|
elif data[0] == "msg":
|
||||||
print(f"Vítězem se stává {winner} s {score} body!")
|
if data[1] == "ER01" or data[1] == "ER02" or data[1] == "ER03":
|
||||||
print("Díky za hru a zase příště.")
|
msg = data[2]
|
||||||
|
count = data[3]
|
||||||
|
th = data[4]
|
||||||
|
clear()
|
||||||
|
inp = input(msg)
|
||||||
|
data = evaluate(inp, count, th)
|
||||||
|
else:
|
||||||
|
msg = data[1]
|
||||||
|
print(msg)
|
||||||
|
break
|
||||||
|
|
||||||
|
elif data[0] == "win":
|
||||||
|
winner = data[1]
|
||||||
|
score = data[2]
|
||||||
|
|
||||||
|
clear()
|
||||||
|
print(f"Vítězem se stává {winner} s {score} body!")
|
||||||
|
print("Díky za hru a zase příště.")
|
||||||
|
break
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
clear()
|
clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user