Add language
This commit is contained in:
parent
a398bbd5dc
commit
5d87c3a221
1 changed files with 20 additions and 31 deletions
51
lib/game.py
51
lib/game.py
|
@ -24,11 +24,11 @@ class Game: # the game class keeps information about the loaded game
|
||||||
if not l:
|
if not l:
|
||||||
# New game
|
# New game
|
||||||
print(self.name)
|
print(self.name)
|
||||||
print(f"A game by {self.author}")
|
print(self.lang['game_by'].replace("$author",self.author))
|
||||||
print("")
|
print("")
|
||||||
print("1 - Start")
|
print(f"1 - {self.lang['start']}")
|
||||||
print("2 - Options")
|
print(f"2 - {self.lang['options']}")
|
||||||
print("0 - Quit")
|
print(f"0 - {self.lang['quit']}")
|
||||||
selection = self.make_selection(3)
|
selection = self.make_selection(3)
|
||||||
system("cls||clear")
|
system("cls||clear")
|
||||||
if(selection == 1): # start new game
|
if(selection == 1): # start new game
|
||||||
|
@ -36,16 +36,16 @@ class Game: # the game class keeps information about the loaded game
|
||||||
elif(selection == 2):
|
elif(selection == 2):
|
||||||
self.settings_menu()
|
self.settings_menu()
|
||||||
elif(selection == 0):
|
elif(selection == 0):
|
||||||
print("Quitting")
|
print(self.lang['quitting'])
|
||||||
exit()
|
exit()
|
||||||
else: # Display continue
|
else: # Display continue
|
||||||
print(self.name)
|
print(self.name)
|
||||||
print(f"A game by {self.author}")
|
print(self.lang['game_by'].replace("$author",self.author))
|
||||||
print("")
|
print("")
|
||||||
print("1 - Continue")
|
print(f"1 - {self.lang['continue']}")
|
||||||
print("2 - New game")
|
print(f"2 - {self.lang['new_name']}")
|
||||||
print("3 - Options")
|
print(f"3 - {self.lang['settings']}")
|
||||||
print("0 - Quit")
|
print(f"0 - {self.lang['quit']}")
|
||||||
selection = self.make_selection(3)
|
selection = self.make_selection(3)
|
||||||
system("cls||clear")
|
system("cls||clear")
|
||||||
if(selection == 1):
|
if(selection == 1):
|
||||||
|
@ -63,15 +63,15 @@ class Game: # the game class keeps information about the loaded game
|
||||||
def settings_menu(self): # displays the settings menu
|
def settings_menu(self): # displays the settings menu
|
||||||
print("Options")
|
print("Options")
|
||||||
print("")
|
print("")
|
||||||
print("1 - Language")
|
print(f"1 - {self.lang['lang']}")
|
||||||
print("0 - Back")
|
print("0 - Back")
|
||||||
selection = self.make_selection(1)
|
selection = self.make_selection(1)
|
||||||
if(selection == 1):
|
if(selection == 1):
|
||||||
print("Language")
|
print(self.lang['lang'])
|
||||||
print("")
|
print("")
|
||||||
print("1 - English")
|
print("1 - English")
|
||||||
print("2 - Czech")
|
print("2 - Česky")
|
||||||
print("0 - Back")
|
print(f"0 - {self.lang['back']}")
|
||||||
selection = self.make_selection(2)
|
selection = self.make_selection(2)
|
||||||
system("cls||clear")
|
system("cls||clear")
|
||||||
if(selection == 1):
|
if(selection == 1):
|
||||||
|
@ -94,11 +94,11 @@ class Game: # the game class keeps information about the loaded game
|
||||||
# TODO: Check for "has_item"
|
# TODO: Check for "has_item"
|
||||||
while y == False: # while the selection is not correct
|
while y == False: # while the selection is not correct
|
||||||
try:
|
try:
|
||||||
selection = int(input("Make a selection (number): ")) # ask for selection
|
selection = int(input(self.lang['selection'])) # ask for selection
|
||||||
except ValueError: # handle wrong input type
|
except ValueError: # handle wrong input type
|
||||||
print("Not a number selection")
|
print(self.lang['not_number'])
|
||||||
if(selection > l or selection < 0): # if the number is bigger than the length or smaller than 0, print error
|
if(selection > l or selection < 0): # if the number is bigger than the length or smaller than 0, print error
|
||||||
print("Invalid selection")
|
print(self.lang['invalid'])
|
||||||
else:
|
else:
|
||||||
y = True # else return the selection
|
y = True # else return the selection
|
||||||
return selection
|
return selection
|
||||||
|
@ -138,18 +138,7 @@ class Game: # the game class keeps information about the loaded game
|
||||||
newText += Fore.RESET # reset color at the end of the text
|
newText += Fore.RESET # reset color at the end of the text
|
||||||
return newText
|
return newText
|
||||||
|
|
||||||
|
def load(file_path,lang): # starts to load the game from YAML
|
||||||
def load(file_path): # starts to load the game from YAML
|
|
||||||
lang = "en"
|
|
||||||
if not (path.exists("./saves/lang")):
|
|
||||||
mkdir("./saves")
|
|
||||||
with open("./saves/lang","w") as f:
|
|
||||||
f.write("en")
|
|
||||||
else:
|
|
||||||
with open("./saves/lang","r") as f:
|
|
||||||
lang = f.read()
|
|
||||||
if lang == "cz":
|
|
||||||
lang = "cz"
|
|
||||||
try:
|
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)
|
||||||
|
@ -157,6 +146,6 @@ def load(file_path): # starts to load the game from YAML
|
||||||
g.lang = lang
|
g.lang = lang
|
||||||
return g
|
return g
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"{Back.RED}{Fore.WHITE}An exception has occured while loading the game from the YAML file:{Fore.RESET}{Back.RESET}")
|
print(f"{Back.RED}{Fore.WHITE}{g.lang['error_loading']}{Fore.RESET}{Back.RESET}")
|
||||||
print(e)
|
print(e)
|
||||||
return None
|
return None
|
||||||
|
|
Reference in a new issue