Files
kostky/main.py
T

72 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from random import randint
from os import system, name
import re
def throw(count):
count = int(count)
new_throw = []
for dice in range(count):
new_throw.append(str(randint(1, 6)))
return new_throw
def show_throw(throw):
pretty_list = ", ".join(throw)
pretty_list += "\n"
for i in range(1, len(throw) + 1):
pretty_list += "^ "
pretty_list += "\n"
for i in range(1, len(throw) + 1):
pretty_list += f"{i} "
return pretty_list
def clear():
if name == 'nt':
_ = system('cls')
else:
_ = system('clear')
def evaluate(inp, count):
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:
for x in inp:
if int(x) > count:
if count == 1:
range = "1"
else:
range = f"1{count}"
data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({range}):", count)
return data
count = len(inp)
data = ("count", count)
return data
def game(data: tuple):
if data[0] == "count":
count = data[1]
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)
game(data)
elif data[0] == "msg":
if data[1] == "ER01" or data[1] == "ER02":
msg = data[2]
count = data[3]
inp = input(msg)
data = evaluate(inp, count)
game(data)
def main():
print("Vítejte ve hře v kostky!")
input("Prosím, stiskněte enter pro první hod:")
data = ("count", 6)
game(data)
if __name__ == "__main__":
main()