Fix not launching
This commit is contained in:
parent
0e6858f566
commit
6327aed543
3 changed files with 40 additions and 11 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -123,4 +123,4 @@ dmypy.json
|
||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.pyre/
|
||||||
|
|
||||||
.vscode
|
saves
|
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Start with example game",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceRoot}/__main__.py",
|
||||||
|
"args": ["./example.yml"],
|
||||||
|
"console": "integratedTerminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
33
lib/game.py
33
lib/game.py
|
@ -29,6 +29,15 @@ class Game: # the game class keeps information about the loaded game
|
||||||
print("1 - Start")
|
print("1 - Start")
|
||||||
print("2 - Options")
|
print("2 - Options")
|
||||||
print("0 - Quit")
|
print("0 - Quit")
|
||||||
|
selection = self.make_selection(3)
|
||||||
|
system("cls||clear")
|
||||||
|
if(selection == 1): # start new game
|
||||||
|
self.print_text()
|
||||||
|
elif(selection == 2):
|
||||||
|
self.settings_menu()
|
||||||
|
elif(selection == 0):
|
||||||
|
print("Quitting")
|
||||||
|
exit()
|
||||||
else: # Display continue
|
else: # Display continue
|
||||||
print(self.name)
|
print(self.name)
|
||||||
print(f"A game by {self.author}")
|
print(f"A game by {self.author}")
|
||||||
|
@ -45,7 +54,9 @@ class Game: # the game class keeps information about the loaded game
|
||||||
self.print_text()
|
self.print_text()
|
||||||
elif(selection == 2):
|
elif(selection == 2):
|
||||||
self.print_text()
|
self.print_text()
|
||||||
else:
|
elif(selection == 3):
|
||||||
|
self.settings_menu()
|
||||||
|
elif(selection == 0):
|
||||||
print("Quitting")
|
print("Quitting")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
@ -70,27 +81,29 @@ class Game: # the game class keeps information about the loaded game
|
||||||
with open("./saves/lang","w") as f:
|
with open("./saves/lang","w") as f:
|
||||||
f.write("cz")
|
f.write("cz")
|
||||||
self.settings_menu()
|
self.settings_menu()
|
||||||
pass
|
else:
|
||||||
|
self.main_menu()
|
||||||
|
|
||||||
def make_selection(self, length=0) -> int: # this method makes sure a valid selection is made and returns the selection as a number
|
def make_selection(self, length=0) -> int: # this method makes sure a valid selection is made and returns the selection as a number
|
||||||
l = length # sets the length
|
l = length # sets the length
|
||||||
if(l == 0): # if no length was set, we get it from nodes
|
if(l == 0): # if no length was set, we get it from nodes
|
||||||
l = len(self.nodes[self.current]["actions"])
|
l = len(self.nodes[self.current]["actions"])-1
|
||||||
y = False
|
y = False
|
||||||
selection = 0
|
selection = 0
|
||||||
# TODO: Check for "has_item"
|
# TODO: Check for "has_item"
|
||||||
while y == False:
|
while y == False: # while the selection is not correct
|
||||||
try:
|
try:
|
||||||
selection = int(input("Make a selection (number): "))
|
selection = int(input("Make a selection (number): ")) # ask for selection
|
||||||
except ValueError:
|
except ValueError: # handle wrong input type
|
||||||
print("Not a number selection")
|
print("Not a number selection")
|
||||||
if(selection >= len(self.nodes[self.current]["actions"]) or selection < 0):
|
if(selection > l or selection < 0): # if the number is bigger than the length or smaller than 0, print error
|
||||||
print("Invalid selection")
|
print("Invalid selection")
|
||||||
else:
|
else:
|
||||||
y = True
|
y = True # else return the selection
|
||||||
return selection
|
return selection
|
||||||
|
|
||||||
def print_text(self): # Prints out the current prompt
|
def print_text(self): # Prints out the current prompt
|
||||||
|
system("cls||clear")
|
||||||
animated = re.search(r"(?!{).+(?=})",self.nodes[self.current]["text"]) # find the animated text
|
animated = re.search(r"(?!{).+(?=})",self.nodes[self.current]["text"]) # find the animated text
|
||||||
if(animated != None):
|
if(animated != None):
|
||||||
self.print_animated(animated.group(0))
|
self.print_animated(animated.group(0))
|
||||||
|
@ -103,11 +116,11 @@ class Game: # the game class keeps information about the loaded game
|
||||||
ostring+=f"{i} - {self.nodes[option]['description']}\n"
|
ostring+=f"{i} - {self.nodes[option]['description']}\n"
|
||||||
print(ostring)
|
print(ostring)
|
||||||
sel = self.make_selection()
|
sel = self.make_selection()
|
||||||
if(self.nodes[self.current]["add_inventory"] is not None):
|
if "add_item" in self.nodes[self.current]: # if there is an add_inventory key in the node,
|
||||||
# add item to inventory
|
# add item to inventory
|
||||||
self.inventory.append(self.nodes[self.current]["add_inventory"])
|
self.inventory.append(self.nodes[self.current]["add_inventory"])
|
||||||
self.current = self.nodes[self.current]["actions"][sel]
|
self.current = self.nodes[self.current]["actions"][sel]
|
||||||
self.save.currentPrompt = self.nodes[self.current]["actions"][sel] # save the current prompt
|
self.save.currentPrompt = self.current # save the current prompt
|
||||||
self.print_text()
|
self.print_text()
|
||||||
|
|
||||||
def print_animated(self,animid): # prinst the first found occurence of an ascii animation
|
def print_animated(self,animid): # prinst the first found occurence of an ascii animation
|
||||||
|
|
Reference in a new issue