def endgame(self): if self._state == GameStateEnum.LOST: for player in self.players: with open(PROFILES, mode='r+', encoding='utf-8') as file: temp = json.load(file) file.seek(0) file.truncate() for user in temp: if user['_nickname'] == player.nickname: losses = user['_losses'] user['_losses'] = losses + 1 json.dump(temp, file) player.status = PlayerStatusEnum.NOT_READY EventQueue.block() EventQueue.post(CustomEvent(ChangeSceneEnum.LOSESCENE)) else: for player in self.players: with open(PROFILES, mode='r+', encoding='utf-8') as file: temp = json.load(file) file.seek(0) file.truncate() for user in temp: if user['_nickname'] == player.nickname: wins = user['_wins'] user['_wins'] = wins + 1 json.dump(temp, file) player.status = PlayerStatusEnum.NOT_READY EventQueue.block() EventQueue.post(CustomEvent(ChangeSceneEnum.WINSCENE))
def execute(self): logging.info("Executing StartGameEvent.") GameStateModel.instance().state = GameStateEnum.PLACING_PLAYERS EventQueue.block() EventQueue.post(CustomEvent(ChangeSceneEnum.GAMEBOARDSCENE))