diff --git a/main.py b/main.py index 7ff30e6..b413e39 100644 --- a/main.py +++ b/main.py @@ -25,33 +25,43 @@ def clear(): else: _ = system('clear') -def evaluate(inp, count): +def evaluate(inp, count, throw): inp = str(inp) if re.search("^\d+$", inp): if len(inp) > count: data = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count) return data - else: + else: for x in inp: - if int(x) > count: + x = int(x) + if x > count: if count == 1: - range = "1" + ran = "1" else: - range = f"1–{count}" - data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({range}):", count) + ran = f"1–{count}" + data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}):", count) return data + old_throw = [] + for y in range(count): + if str(y) in inp: + old_throw.append(throw[y]) + count = len(inp) - data = ("count", count) + data = ("count", count, old_throw) return data def game(data: tuple): if data[0] == "count": count = data[1] + old_throw = data[2] new_throw = throw(count) clear() print(show_throw(new_throw)) - inp = input("Vyberte, kterými kostkami chcete hodit znovu (např. 135):") - data = evaluate(inp, count) + msg = "Vyberte, kterými kostkami chcete hodit znovu (např. 135):" + if old_throw != "": + msg += f"\nHodnoty odložených kostek: {old_throw}" + inp = input(msg) + data = evaluate(inp, count, new_throw) game(data) elif data[0] == "msg": if data[1] == "ER01" or data[1] == "ER02": @@ -60,11 +70,14 @@ def game(data: tuple): inp = input(msg) data = evaluate(inp, count) game(data) + else: + msg = data[1] + print(msg) def main(): print("Vítejte ve hře v kostky!") input("Prosím, stiskněte enter pro první hod:") - data = ("count", 6) + data = ("count", 6, "") game(data) if __name__ == "__main__":