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",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Python: Start main",
|
"name": "Python: Start main (verbose)",
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/__main__.py",
|
"program": "${workspaceFolder}/__main__.py",
|
||||||
|
"args": ["-v"],
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"justMyCode": true,
|
"justMyCode": true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,3 +11,6 @@ Ročníková práce
|
||||||
|
|
||||||
## Jak se s tím pracuje
|
## Jak se s tím pracuje
|
||||||
TODO
|
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
|
from genericpath import isdir
|
||||||
|
import sys
|
||||||
from lib.game import *
|
from lib.game import *
|
||||||
from colorama import init, Back, Fore
|
from colorama import init, Back, Fore
|
||||||
from os import mkdir, listdir, path
|
from os import mkdir, listdir, path
|
||||||
|
@ -27,16 +28,24 @@ def main():
|
||||||
games = []
|
games = []
|
||||||
for file in listdir("./games"):
|
for file in listdir("./games"):
|
||||||
if file.endswith("yml") or file.endswith("yaml"):
|
if file.endswith("yml") or file.endswith("yaml"):
|
||||||
# finds available games
|
# hledá hry
|
||||||
try:
|
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í)
|
||||||
# try parsing
|
|
||||||
g = load(f"./games/{file}",l)
|
g = load(f"./games/{file}",l)
|
||||||
games.append(g)
|
if g is not None:
|
||||||
except Exception as e:
|
games.append(g)
|
||||||
print(f"{Back.RED}{Fore.WHITE}{l['error_loading']} {file}{Fore.RESET}{Back.RESET}:")
|
else:
|
||||||
print(e)
|
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:
|
if len(games) < 1:
|
||||||
print(l['no_games'])
|
print(l['no_games'])
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -6,8 +6,14 @@ meta: # make sure every key is in lowercase
|
||||||
- iron_sword:
|
- iron_sword:
|
||||||
atk: 3
|
atk: 3
|
||||||
starter: true
|
starter: true
|
||||||
|
name: "Iron Sword"
|
||||||
|
- wood_sword:
|
||||||
|
atk: 1
|
||||||
|
starter: true
|
||||||
|
name: "Wooden Sword"
|
||||||
- chainmail:
|
- chainmail:
|
||||||
def: 2
|
def: 2
|
||||||
|
name: "Chainmail Armor"
|
||||||
starter: true
|
starter: true
|
||||||
enemies:
|
enemies:
|
||||||
- john:
|
- 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"]))
|
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("starter" in item[name].keys()): # Pokud je starter, přidáme hráčí na začátku do inventáře
|
||||||
if item[name]["starter"]:
|
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.inventory.append(i)
|
||||||
self.equipped[i.type] = i
|
self.equipped[i.type] = i
|
||||||
if "enemies" in data["meta"].keys():
|
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")
|
MenuManager([self.lang["return"]],f" {self.lang['inside_inv']} \n")
|
||||||
else:
|
else:
|
||||||
s = ""
|
s = ""
|
||||||
op = [self.lang["return"]]
|
op = []
|
||||||
|
items = []
|
||||||
for i,item in enumerate(self.inventory):
|
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 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:
|
if self.equipped["weapon"] == item or self.equipped["armor"] == item:
|
||||||
op.append(f"- {item.name} | {self.lang['equipped']}")
|
op.append(f"- {item.name} | {self.lang['equipped']}")
|
||||||
else:
|
else:
|
||||||
op.append(f"- {item.name}")
|
op.append(f"- {item.name}")
|
||||||
|
items.append(item)
|
||||||
else:
|
else:
|
||||||
if(i == len(self.inventory)): # poslední, nepřidávat newline
|
if(i == len(self.inventory)): # poslední, nepřidávat newline
|
||||||
s += f"- {item}"
|
s += f"- {item}"
|
||||||
else:
|
else:
|
||||||
s += f"- {item}\n"
|
s += f"- {item}\n"
|
||||||
|
items.append(None)
|
||||||
|
op.append(self.lang["return"])
|
||||||
m = MenuManager(op,f" {self.lang['inside_inv']} \n{s}")
|
m = MenuManager(op,f" {self.lang['inside_inv']} \n{s}")
|
||||||
if(m.selected != len(op)-1):
|
if(m.selected != len(op)-1):
|
||||||
# Vybavit
|
# Vybavit
|
||||||
i = op[m.selected]
|
i = items[m.selected]
|
||||||
self.equipped[i.type] = i
|
self.equipped[i.type] = i
|
||||||
self.print_text()
|
self.print_text()
|
||||||
|
|
||||||
|
@ -211,12 +215,7 @@ class Game: # Hlavní třída, uchovává údaje o hře
|
||||||
return newText
|
return newText
|
||||||
|
|
||||||
def load(file_path,lang): # Načte hru z YAML souboru
|
def load(file_path,lang): # Načte hru z YAML souboru
|
||||||
try:
|
with open(file_path) as f:
|
||||||
with open(file_path) as f:
|
data = yaml.load(f,Loader=SafeLoader)
|
||||||
data = yaml.load(f,Loader=SafeLoader)
|
g = Game(data,lang)
|
||||||
g = Game(data,lang)
|
return g
|
||||||
return g
|
|
||||||
except Exception as e:
|
|
||||||
print(f"{Back.RED}{Fore.WHITE}ERROR{Fore.RESET}{Back.RESET}")
|
|
||||||
print(e)
|
|
||||||
return None
|
|
|
@ -1,5 +1,6 @@
|
||||||
available: 'Dostupné hry:'
|
available: 'Dostupné hry:'
|
||||||
no_games: 'Žádné hry nenalezeny'
|
no_games: 'Žádné hry nenalezeny'
|
||||||
|
enter: 'Stiskněte Enter pro pokračování'
|
||||||
|
|
||||||
yaml_unspecified: 'Musíte specifikovat YAML soubor'
|
yaml_unspecified: 'Musíte specifikovat YAML soubor'
|
||||||
game_by: 'Vytvořil $author'
|
game_by: 'Vytvořil $author'
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
available: 'Available games:'
|
available: 'Available games:'
|
||||||
no_games: 'No games found'
|
no_games: 'No games found'
|
||||||
|
enter: 'Press Enter to continue'
|
||||||
|
|
||||||
yaml_unspecified: 'You need to specify a path to a YAML file'
|
yaml_unspecified: 'You need to specify a path to a YAML file'
|
||||||
game_by: 'A game by $author'
|
game_by: 'A game by $author'
|
||||||
|
|
Reference in a new issue