1
0
Fork 0

yesterday progress - better level choice

This commit is contained in:
Lili (Tlapka) 2021-03-16 14:12:24 +01:00
parent c1803514dc
commit c8e17798bb
1 changed files with 41 additions and 15 deletions

View File

@ -84,8 +84,18 @@ class Game:
return True return True
return False return False
def next_level(self, next_branch=''): def next_level_branch_check(self, input_text):
"""Advance the game to next level with branch `next_branch`. next_level = "level" + str(self.level + 1)
if next_level + input_text in self.level_mapping[next_level]:
return input_text
if input_text in self.level_mapping[next_level]:
return input_text[6:]
raise NoLevelFoundError("No branch called {} found.".format(input_text))
def next_level(self, next_branch_input=''):
"""Advance the game to next level with branch `next_branch_input`.
Because next_branch_input can be supplied by user, performs check
if it is real first.
Throws NoLevelFoundError if there is no such level present. Throws NoLevelFoundError if there is no such level present.
next_branch == '' is understood as no branch selected, a level next_branch == '' is understood as no branch selected, a level
@ -96,11 +106,8 @@ class Game:
if (not self.next_level_exists()): if (not self.next_level_exists()):
raise NoLevelFoundError("No next level found! Perhaps you already finished the game?") raise NoLevelFoundError("No next level found! Perhaps you already finished the game?")
if (self.next_level_is_forked()): if (self.next_level_is_forked()):
next_level = "level" + str(self.level + 1) next_branch = self.next_level_branch_check(next_branch_input)
if next_level + next_branch in self.level_mapping[next_level]: # throws NoLevelFoundError
pass
else:
raise NoLevelFoundError("No branch called {} found.".format(next_branch))
elif (next_branch != ''): elif (next_branch != ''):
raise NoLevelFoundError("Next level has no branch, but branch was given.") raise NoLevelFoundError("Next level has no branch, but branch was given.")
self.solving_times.append(int(time.time() - self.level_start_time)) self.solving_times.append(int(time.time() - self.level_start_time))
@ -128,6 +135,14 @@ class Game:
self.level_start_time = 0 self.level_start_time = 0
# # # METHODS THAT OUTPUT INTO STDOUT # # # # # # METHODS THAT OUTPUT INTO STDOUT # # #
def print_next_level_fork_names(self):
next_level = "level" + str(self.level + 1)
print("Next level branches are:")
if next_level in self.level_mapping:
for branch in self.level_mapping[next_level]:
print(branch, end=" ")
print("")
def print_time(self, load_time, concise=False): def print_time(self, load_time, concise=False):
"""Print time in minutes and seconds. """Print time in minutes and seconds.
@ -286,17 +301,28 @@ def game_loop():
print("To start over, please run `abort` first.") print("To start over, please run `abort` first.")
elif ((command == "n") or (command == "next")): elif ((command == "n") or (command == "next")):
try: try:
print("Going to set up level {}".format(game.level + 1)) if game.level == 0:
if game.next_level_is_forked(): print("Can't continue, (S)tart the game first!")
print("Choose level's branch:") elif game.next_level_exists():
branch = input() print("Going to set up level {}".format(game.level + 1))
branch = branch.lower() # just lowered, no sanitization if game.next_level_is_forked():
game.next_level(branch) print("Next level is forked.")
game.print_next_level_fork_names()
print("Choose level's branch:")
branch = input()
branch = branch.lower() # just lowered, no sanitization
game.next_level(branch)
else:
game.next_level()
print("Level deployed. You can continue playing.")
if (game.level == 5):
print("This is the last level of the game.")
else: else:
game.next_level() print("No next levels found -- you finished the game!")
print("Level deployed. You can continue playing.") # print("Remember to save your gamefile idk")
except NoLevelFoundError as err: except NoLevelFoundError as err:
print("Error encountered: {}".format(err)) print("Error encountered: {}".format(err))
elif ((command == "i") or (command == "info")): elif ((command == "i") or (command == "info")):
game.print_info() game.print_info()
elif ((command == "h") or (command == "help")): elif ((command == "h") or (command == "help")):