better logging and aborting

This commit is contained in:
2021-03-24 17:53:56 +01:00
parent 678d59f856
commit 2a0a088998
3 changed files with 45 additions and 37 deletions
+1 -11
View File
@@ -147,17 +147,7 @@ class Game:
self.level_start_time = time.time()
def abort_game(self):
"""Abort game and reset attributes to their default state.
If a /logs subfolder exists, also logs the current game log
to a file before aborting."""
try:
if os.path.isdir("logs"):
self.log_to_file("logs/aborted_game" + str(time.time()))
except OSError as err:
# print("Failed to save game log.")
# print("Error number: {}, Error text: {}".format(err.errno, err.strerror))
pass
"""Abort game and reset attributes to their default state."""
subprocess.run(["vagrant", "destroy", "-f"], cwd=self.game_directory)
self.load_times = []
self.solving_times = []
+4
View File
@@ -34,6 +34,10 @@ class HintGiver:
return True
return False
def restart_game(self):
self.total_hints_taken = 0
self.hints_taken = {}
def log_to_file(self, filename):
with open(filename, 'a') as f:
yaml.dump(self, f)