Alien_Invasion外星人入侵小游戏的最高分保存:
def _get_stored_high_score(self):
filename = 'score.json'
try:
with open(filename) as f:
stored_high_score = json.load(f)
except FileNotFoundError:
stored_high_score = 0
return stored_high_score
else:
return stored_high_score
def _store_high_score(self, high_score):
filename = 'score.json'
high_score = self.stats.high_score
with open(filename, 'w') as f:
json.dump(high_score, f)