当前位置: 首页 > 工具软件 > Alien Arena > 使用案例 >

***Alien_Invasion外星人入侵小游戏的最高分保存:***

花博厚
2023-12-01

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)
 类似资料: