move pseudo crypt to tetrislogic

This commit is contained in:
Adrien MALINGREY 2019-10-01 11:55:08 +02:00
parent 58a7736d53
commit 11c6321f17
2 changed files with 12 additions and 13 deletions

View File

@ -54,7 +54,6 @@ else:
USER_PROFILE_DIR = os.environ.get("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
USER_PROFILE_DIR = os.path.join(USER_PROFILE_DIR, "TetrArcade")
HIGH_SCORE_PATH = os.path.join(USER_PROFILE_DIR, ".high_score")
CRYPT_KEY = 987943759387540938469837689379857347598347598379584857934579343
# Text
TEXT_COLOR = arcade.color.BUBBLES
@ -394,7 +393,7 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
try:
with open(HIGH_SCORE_PATH, "rb") as f:
crypted_high_score = pickle.load(f)
self.high_score = crypted_high_score ^ CRYPT_KEY
super().load_high_score(crypted_high_score)
except:
self.high_score = 0
@ -403,7 +402,7 @@ class TetrArcade(tetrislogic.TetrisLogic, arcade.Window):
if not os.path.exists(USER_PROFILE_DIR):
os.makedirs(USER_PROFILE_DIR)
with open(HIGH_SCORE_PATH, mode='wb') as f:
crypted_high_score = self.high_score ^ CRYPT_KEY
crypted_high_score = super().save_high_score()
pickle.dump(crypted_high_score, f, pickle.HIGHEST_PROTOCOL)
except Exception as e:
sys.exit(

View File

@ -12,6 +12,7 @@ from .consts import (
LINES_CLEAR_NAME = "LINES_CLEAR_NAME"
CRYPT_KEY = 987943759387540938469837689379857347598347598379584857934579343
class State:
@ -396,19 +397,18 @@ class TetrisLogic():
print(text)
raise Warning("TetrisLogic.show_text not implemented.")
def load_high_score(self):
self.high_score = 0
raise Warning(
"""TetrisLogic.load_high_score not implemented.
def load_high_score(self, crypted_high_score=None):
if crypted_high_score is None:
self.high_score = 0
raise Warning(
"""TetrisLogic.load_high_score not implemented.
High score is set to 0"""
)
)
else:
self.high_score = crypted_high_score ^ CRYPT_KEY
def save_high_score(self):
print("High score: {:n}".format(self.high_score))
raise Warning(
"""TetrisLogic.save_high_score not implemented.
High score is not saved"""
)
return self.high_score ^ CRYPT_KEY
def start(task, period):
raise Warning("TetrisLogic.start is not implemented.")