1
0
Fork 0

add function for finishing the game

This commit is contained in:
Lili (Tlapka) 2021-03-18 12:07:16 +01:00
parent e30dff4b50
commit bc8d679703
1 changed files with 38 additions and 19 deletions

View File

@ -79,9 +79,11 @@ class Game:
return True return True
def finish_game(self): def finish_game(self):
"""Mark game as not in progress and log end time, IF on the last level.""" """Mark game as not in progress and log end time, if on the last level.
if (not self.next_level_exists()): Return false if prerequisites were not met, true otherwise."""
if (not self.next_level_exists() and self.game_in_progress):
self.solving_times.append(int(time.time() - self.level_start_time)) self.solving_times.append(int(time.time() - self.level_start_time))
self.game_end_time = time.time() self.game_end_time = time.time()
self.game_in_progress = False self.game_in_progress = False
@ -235,6 +237,7 @@ def print_help():
print("(E)xit - aborts run, then exits the assistant.") print("(E)xit - aborts run, then exits the assistant.")
print("(S)tart - starts a new run of the adaptive game, if one isn't in progress.") print("(S)tart - starts a new run of the adaptive game, if one isn't in progress.")
print("(N)ext - advances to the next level. Asks for branch when applicable.") print("(N)ext - advances to the next level. Asks for branch when applicable.")
print("(F)inish - when on the last level, finishes the game and logs end time.")
print("(I)nfo - displays info about current run - Level number and name.") print("(I)nfo - displays info about current run - Level number and name.")
print("Helper functions:") print("Helper functions:")
print("(H)elp - explains all commands on the screen.") print("(H)elp - explains all commands on the screen.")
@ -311,6 +314,7 @@ def game_loop():
(E)xit - aborts run, then exits the assistant. (E)xit - aborts run, then exits the assistant.
(S)tart - starts a new run of the adaptive game, if one isn't in progress. (S)tart - starts a new run of the adaptive game, if one isn't in progress.
(N)ext - advances to the next level. Asks for branch when applicable. (N)ext - advances to the next level. Asks for branch when applicable.
(F)inish - when on the last level, finishes the game and logs end time.
(I)nfo - displays info about current run - Level number and name. (I)nfo - displays info about current run - Level number and name.
Helper functions: Helper functions:
(H)elp - explains all commands on the screen. (H)elp - explains all commands on the screen.
@ -364,12 +368,27 @@ def game_loop():
if (game.level == 5): if (game.level == 5):
print("This is the last level of the game.") print("This is the last level of the game.")
else: else:
print("No next levels found -- you finished the game!") print("No next levels found -- you probably finished the game!")
game.finish_game() print("Make sure to run (F)inish before exiting.")
# if (game.finish_game()):
# print("Game finished, total time logged!")
# print("You don't need to run (F)inish again.")
# elif (not game.game_in_progress)
# print("Game was already marked as finished earlier.")
# else:
# print("Could not finish game, but there are no other levelse either.")
# print("This situation should not happen.") # TODO: look at this again later
# print("Remember to save your gamefile idk") # 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 == "f") or (command == "finish")):
if (game.finish_game())
print("Game finished, total time logged!")
elif (not game.game_in_progress)
print("Game was already marked as finished earlier.")
else:
print("Could not finish game. Make sure you are on the last level!")
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")):