release: v0.2.0 #28
+4
-1
@@ -1,2 +1,5 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
*.egg-info/
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
from kostky.kostky import main
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
+35
-25
@@ -1,9 +1,11 @@
|
|||||||
from typing import Any
|
|
||||||
from random import randint
|
|
||||||
from os import system, name
|
|
||||||
import re
|
|
||||||
import csv
|
import csv
|
||||||
|
import re
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
from importlib.resources import files
|
||||||
|
from os import name, system
|
||||||
|
from random import randint
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
||||||
score: int = 0
|
score: int = 0
|
||||||
@@ -15,19 +17,19 @@ h_bool: bool = True
|
|||||||
aggr: dict[str, int] = {}
|
aggr: dict[str, int] = {}
|
||||||
final_score: int = 10000
|
final_score: int = 10000
|
||||||
|
|
||||||
with open("hodnoty.csv", "r") as csv_file:
|
csv_text = files(__package__).joinpath("hodnoty.csv").read_text(encoding="utf-8")
|
||||||
csv_reader = csv.reader(csv_file)
|
csv_reader = csv.reader(csv_text.splitlines())
|
||||||
|
|
||||||
for row in csv_reader:
|
for row in csv_reader:
|
||||||
key = str(row[0])
|
key = str(row[0])
|
||||||
value = int(row[1])
|
value = int(row[1])
|
||||||
|
|
||||||
hodnoty[key] = value
|
hodnoty[key] = value
|
||||||
|
|
||||||
def throw(count: int) -> str:
|
def throw(count: int) -> str:
|
||||||
count = int(count)
|
count = int(count)
|
||||||
new_throw: list[str] = []
|
new_throw: list[str] = []
|
||||||
for dice in range(count):
|
for _dice in range(count):
|
||||||
new_throw.append(str(randint(1, 6)))
|
new_throw.append(str(randint(1, 6)))
|
||||||
new_throw_str: str = "".join(new_throw)
|
new_throw_str: str = "".join(new_throw)
|
||||||
return new_throw_str
|
return new_throw_str
|
||||||
@@ -39,7 +41,7 @@ def show_throw(throw: str) -> str:
|
|||||||
|
|
||||||
pretty_list: str = ", ".join(throw_temp)
|
pretty_list: str = ", ".join(throw_temp)
|
||||||
pretty_list += "\n"
|
pretty_list += "\n"
|
||||||
for i in range(1, len(throw_temp) + 1):
|
for _i in range(1, len(throw_temp) + 1):
|
||||||
pretty_list += "^ "
|
pretty_list += "^ "
|
||||||
pretty_list += "\n"
|
pretty_list += "\n"
|
||||||
for i in range(1, len(throw_temp) + 1):
|
for i in range(1, len(throw_temp) + 1):
|
||||||
@@ -47,10 +49,7 @@ def show_throw(throw: str) -> str:
|
|||||||
return pretty_list
|
return pretty_list
|
||||||
|
|
||||||
def clear() -> None:
|
def clear() -> None:
|
||||||
if name == 'nt':
|
_ = system('cls') if name == 'nt' else system('clear')
|
||||||
_ = system('cls')
|
|
||||||
else:
|
|
||||||
_ = system('clear')
|
|
||||||
|
|
||||||
def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]:
|
def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]:
|
||||||
|
|
||||||
@@ -78,16 +77,25 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]:
|
|||||||
inp = str(inp)
|
inp = str(inp)
|
||||||
if re.search(r"^\d+$", inp):
|
if re.search(r"^\d+$", inp):
|
||||||
if len(inp) > count:
|
if len(inp) > count:
|
||||||
data: tuple[Any, ...] = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu: ", count, throw)
|
data: tuple[Any, ...] = (
|
||||||
|
"msg",
|
||||||
|
"ER01",
|
||||||
|
"Tolika kostkami nemůžete hodit. Zkuste to znovu: ",
|
||||||
|
count,
|
||||||
|
throw
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
for x in inp:
|
for x in inp:
|
||||||
x = int(x)
|
x = int(x)
|
||||||
if x > count:
|
if x > count:
|
||||||
if count == 1:
|
ran = "1" if count == 1 else f"1–{count}"
|
||||||
ran = "1"
|
data = (
|
||||||
else:
|
"msg",
|
||||||
ran = f"1–{count}"
|
"ER02",
|
||||||
data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}): ", count, throw)
|
f"Zvolte prosím kostky v platném rozsahu ({ran}): ",
|
||||||
|
count,
|
||||||
|
throw
|
||||||
|
)
|
||||||
return data
|
return data
|
||||||
old_throw: list[str] = []
|
old_throw: list[str] = []
|
||||||
pick: list[str] = []
|
pick: list[str] = []
|
||||||
@@ -203,8 +211,9 @@ def add_players() -> None:
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
def to_sorted_tuple(d: dict[str, int], s: bool = True) -> tuple[list[tuple[int, str, int]], dict[str, int]]:
|
def to_sorted_tuple(d: dict[str, int], s: bool = True) -> tuple[list[tuple[int, str, int]],
|
||||||
L: list[tuple[str, int]] = []
|
dict[str, int]]:
|
||||||
|
L: list[tuple[int, str, int]] = []
|
||||||
|
|
||||||
if s:
|
if s:
|
||||||
d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True))
|
d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True))
|
||||||
@@ -276,7 +285,8 @@ def game(data: tuple) -> None:
|
|||||||
if count == 0:
|
if count == 0:
|
||||||
count = 6
|
count = 6
|
||||||
msg: str = ("Jakou akci chcete provést?\n"
|
msg: str = ("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"
|
" - Zadejte kombinaci kostek k ponechání (dojde k jejich vyhodnocení): "
|
||||||
|
"[pozice kostek] (např. 1 nebo 34 nebo 123456).\n"
|
||||||
" - Hodit znovu: [h].\n"
|
" - Hodit znovu: [h].\n"
|
||||||
f" - Ukončit hod a ponechat si skóre z tohoto hodu ({score}): [k].\n"
|
f" - Ukončit hod a ponechat si skóre z tohoto hodu ({score}): [k].\n"
|
||||||
" - Ukončit hru: [exit].\n"
|
" - Ukončit hru: [exit].\n"
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["hatchling", "hatch-vcs"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "kostky"
|
||||||
|
dynamic = ["version"]
|
||||||
|
description = "Textová hra v kostky."
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.9"
|
||||||
|
license = "GPL-3.0-or-later"
|
||||||
|
license-files = ["LICENSE"]
|
||||||
|
authors = [{ name = "David Spáčil" }]
|
||||||
|
keywords = ["hra", "kostky", "cli"]
|
||||||
|
classifiers = [
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Environment :: Console",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Topic :: Games/Entertainment",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"tabulate",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
dev = ["mypy", "ruff", "types-tabulate"]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Repository = "https://gitea.spacilovi.eu/david/kostky"
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
kostky = "kostky.kostky:main"
|
||||||
|
|
||||||
|
[tool.hatch.version]
|
||||||
|
source = "vcs"
|
||||||
|
|
||||||
|
[tool.hatch.build.targets.wheel]
|
||||||
|
packages = ["kostky"]
|
||||||
|
|
||||||
|
[tool.mypy]
|
||||||
|
python_version = "3.9"
|
||||||
|
strict = true
|
||||||
|
files = ["kostky"]
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
target-version = "py39"
|
||||||
|
line-length = 100
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = ["E", "F", "I", "UP", "B", "SIM"]
|
||||||
Reference in New Issue
Block a user