First release
This commit is contained in:
parent
15ba06b4aa
commit
71e430f61d
7 changed files with 41 additions and 21 deletions
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
|
@ -5,10 +5,11 @@
|
|||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Start main",
|
||||
"name": "Python: Start main (verbose)",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/__main__.py",
|
||||
"args": ["-v"],
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true,
|
||||
}
|
||||
|
|
|
@ -11,3 +11,6 @@ Ročníková práce
|
|||
|
||||
## Jak se s tím pracuje
|
||||
TODO
|
||||
|
||||
## Pozor
|
||||
Kvůli limitacím a/nebo bezpečnostním opatřením systému je na **MacOS** a **Linuxu** nutné spouštět jako sudo!
|
25
__main__.py
25
__main__.py
|
@ -1,4 +1,5 @@
|
|||
from genericpath import isdir
|
||||
import sys
|
||||
from lib.game import *
|
||||
from colorama import init, Back, Fore
|
||||
from os import mkdir, listdir, path
|
||||
|
@ -27,16 +28,24 @@ def main():
|
|||
games = []
|
||||
for file in listdir("./games"):
|
||||
if file.endswith("yml") or file.endswith("yaml"):
|
||||
# finds available games
|
||||
try:
|
||||
# try parsing
|
||||
# hledá hry
|
||||
if len(sys.argv) > 1 and (sys.argv[1] == "-v" or sys.argv[1] == "--verbose"): # nepoužívá try/except pro vypsání celé chybové hlášky (debugování)
|
||||
g = load(f"./games/{file}",l)
|
||||
games.append(g)
|
||||
except Exception as e:
|
||||
print(f"{Back.RED}{Fore.WHITE}{l['error_loading']} {file}{Fore.RESET}{Back.RESET}:")
|
||||
print(e)
|
||||
if g is not None:
|
||||
games.append(g)
|
||||
else:
|
||||
try:
|
||||
# parsuje
|
||||
g = load(f"./games/{file}",l)
|
||||
if g is not None:
|
||||
games.append(g)
|
||||
except Exception as e:
|
||||
print(f"{Back.RED}{Fore.WHITE}{l['error_loading']} {file}{Fore.RESET}{Back.RESET}:")
|
||||
print(e)
|
||||
print(l['enter'])
|
||||
input()
|
||||
|
||||
# PRINT OUT GAME SELECT
|
||||
# výpis menu
|
||||
if len(games) < 1:
|
||||
print(l['no_games'])
|
||||
else:
|
||||
|
|
|
@ -6,8 +6,14 @@ meta: # make sure every key is in lowercase
|
|||
- iron_sword:
|
||||
atk: 3
|
||||
starter: true
|
||||
name: "Iron Sword"
|
||||
- wood_sword:
|
||||
atk: 1
|
||||
starter: true
|
||||
name: "Wooden Sword"
|
||||
- chainmail:
|
||||
def: 2
|
||||
name: "Chainmail Armor"
|
||||
starter: true
|
||||
enemies:
|
||||
- john:
|
||||
|
|
23
lib/game.py
23
lib/game.py
|
@ -35,7 +35,7 @@ class Game: # Hlavní třída, uchovává údaje o hře
|
|||
self.equippable.append(Item(item[name]["name"],item[name]["atk"]))
|
||||
if("starter" in item[name].keys()): # Pokud je starter, přidáme hráčí na začátku do inventáře
|
||||
if item[name]["starter"]:
|
||||
i = next((x for x in self.equippable if x.name == list(item.keys())[0]))
|
||||
i = next((x for x in self.equippable if x.name == item[name]["name"])) # V případě, že nenalezne předmět, vrací None
|
||||
self.inventory.append(i)
|
||||
self.equipped[i.type] = i
|
||||
if "enemies" in data["meta"].keys():
|
||||
|
@ -180,22 +180,26 @@ class Game: # Hlavní třída, uchovává údaje o hře
|
|||
MenuManager([self.lang["return"]],f" {self.lang['inside_inv']} \n")
|
||||
else:
|
||||
s = ""
|
||||
op = [self.lang["return"]]
|
||||
op = []
|
||||
items = []
|
||||
for i,item in enumerate(self.inventory):
|
||||
if type(item) is Item: # Pokud je předmět třídy Item, zobrazit zda-li je vybaven nebo ne
|
||||
if self.equipped["weapon"] == item or self.equipped["armor"] == item:
|
||||
op.append(f"- {item.name} | {self.lang['equipped']}")
|
||||
else:
|
||||
op.append(f"- {item.name}")
|
||||
items.append(item)
|
||||
else:
|
||||
if(i == len(self.inventory)): # poslední, nepřidávat newline
|
||||
s += f"- {item}"
|
||||
else:
|
||||
s += f"- {item}\n"
|
||||
items.append(None)
|
||||
op.append(self.lang["return"])
|
||||
m = MenuManager(op,f" {self.lang['inside_inv']} \n{s}")
|
||||
if(m.selected != len(op)-1):
|
||||
# Vybavit
|
||||
i = op[m.selected]
|
||||
i = items[m.selected]
|
||||
self.equipped[i.type] = i
|
||||
self.print_text()
|
||||
|
||||
|
@ -211,12 +215,7 @@ class Game: # Hlavní třída, uchovává údaje o hře
|
|||
return newText
|
||||
|
||||
def load(file_path,lang): # Načte hru z YAML souboru
|
||||
try:
|
||||
with open(file_path) as f:
|
||||
data = yaml.load(f,Loader=SafeLoader)
|
||||
g = Game(data,lang)
|
||||
return g
|
||||
except Exception as e:
|
||||
print(f"{Back.RED}{Fore.WHITE}ERROR{Fore.RESET}{Back.RESET}")
|
||||
print(e)
|
||||
return None
|
||||
with open(file_path) as f:
|
||||
data = yaml.load(f,Loader=SafeLoader)
|
||||
g = Game(data,lang)
|
||||
return g
|
|
@ -1,5 +1,6 @@
|
|||
available: 'Dostupné hry:'
|
||||
no_games: 'Žádné hry nenalezeny'
|
||||
enter: 'Stiskněte Enter pro pokračování'
|
||||
|
||||
yaml_unspecified: 'Musíte specifikovat YAML soubor'
|
||||
game_by: 'Vytvořil $author'
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
available: 'Available games:'
|
||||
no_games: 'No games found'
|
||||
enter: 'Press Enter to continue'
|
||||
|
||||
yaml_unspecified: 'You need to specify a path to a YAML file'
|
||||
game_by: 'A game by $author'
|
||||
|
|
Reference in a new issue