number of minor fixes

This commit is contained in:
Vasiliy Horbachenko
2018-06-13 03:33:08 +03:00
parent 481a5922b4
commit 1c67a2e4cf
14 changed files with 104 additions and 46 deletions

View File

@@ -1,3 +1,4 @@
import typing
import pickle
import os
import shutil
@@ -17,14 +18,15 @@ def _save_file_exists() -> bool:
return os.path.exists(_save_file())
def restore_game() -> Game:
def restore_game() -> typing.Optional[Game]:
if not _save_file_exists():
return None
try:
with open(_save_file(), "rb") as f:
return pickle.load(f)
except:
except Exception as e:
print(e)
return None
@@ -32,7 +34,8 @@ def save_game(game: Game) -> bool:
try:
with open(_temporary_save_file(), "wb") as f:
pickle.dump(game, f)
shutil.copy(_temporary_save_file(), _save_file())
return True
except:
shutil.copy(_temporary_save_file(), _save_file())
return True
except Exception as e:
print(e)
return False