feature/hod: základy logiky pro vyhodnocování hodnoty kostek: načtení hodnot odložených

This commit is contained in:
2026-06-19 20:20:19 +02:00
parent a668a4d7b3
commit 6952c7c964
+23 -10
View File
@@ -25,33 +25,43 @@ def clear():
else: else:
_ = system('clear') _ = system('clear')
def evaluate(inp, count): def evaluate(inp, count, throw):
inp = str(inp) inp = str(inp)
if re.search("^\d+$", inp): if re.search("^\d+$", inp):
if len(inp) > count: if len(inp) > count:
data = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count) data = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count)
return data return data
else: else:
for x in inp: for x in inp:
if int(x) > count: x = int(x)
if x > count:
if count == 1: if count == 1:
range = "1" ran = "1"
else: else:
range = f"1{count}" ran = f"1{count}"
data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({range}):", count) data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}):", count)
return data return data
old_throw = []
for y in range(count):
if str(y) in inp:
old_throw.append(throw[y])
count = len(inp) count = len(inp)
data = ("count", count) data = ("count", count, old_throw)
return data return data
def game(data: tuple): def game(data: tuple):
if data[0] == "count": if data[0] == "count":
count = data[1] count = data[1]
old_throw = data[2]
new_throw = throw(count) new_throw = throw(count)
clear() clear()
print(show_throw(new_throw)) print(show_throw(new_throw))
inp = input("Vyberte, kterými kostkami chcete hodit znovu (např. 135):") msg = "Vyberte, kterými kostkami chcete hodit znovu (např. 135):"
data = evaluate(inp, count) if old_throw != "":
msg += f"\nHodnoty odložených kostek: {old_throw}"
inp = input(msg)
data = evaluate(inp, count, new_throw)
game(data) game(data)
elif data[0] == "msg": elif data[0] == "msg":
if data[1] == "ER01" or data[1] == "ER02": if data[1] == "ER01" or data[1] == "ER02":
@@ -60,11 +70,14 @@ def game(data: tuple):
inp = input(msg) inp = input(msg)
data = evaluate(inp, count) data = evaluate(inp, count)
game(data) game(data)
else:
msg = data[1]
print(msg)
def main(): def main():
print("Vítejte ve hře v kostky!") print("Vítejte ve hře v kostky!")
input("Prosím, stiskněte enter pro první hod:") input("Prosím, stiskněte enter pro první hod:")
data = ("count", 6) data = ("count", 6, "")
game(data) game(data)
if __name__ == "__main__": if __name__ == "__main__":