def run_server(self, GameState): player = GameState.get_player(self.source_player_id) if player.lockdown_timer > 0: message = "Player \"{}\" tried to cheat by sending an answer during lockdown" message = message.format(player.name) print(message) return is_correct = self.data["answer"] == GameState.correct_answer_index if is_correct: data = { "winner_id": self.source_player_id, "points": POINTS_GUESSER_CORRECT } action = Action_CorrectAnswer(data, target_id=self.source_player_id) else: data = { "lockdown_time": GUESSER_TIME_PENALTY, "points": POINTS_GUESSER_WRONG } action = Action_WrongAnswer(data, target_id=self.source_player_id) player.lockdown_timer = GUESSER_TIME_PENALTY GameState.run_action(action)
def run(self, GameState): if not GameState.is_current_active_player(): # Inactive player can't draw self.network_command = False return GameState.main_pad.update(**self.data)
def run_server(self, GameState): id = GameState.addPlayer(self.data["player_name"]) data = {"id": id} GameState.run_action(Action_Connect_Ack(data, target_id=id)) GameState.run_action(Action_GameState_Sync(target_id=id)) GameState.run_action(Action_Send_Canvas(target_id=id)) # Action_Connect is the only packet that returns a value return id
def run_server(self, GameState): GameState.someone_correctly_guessed = True winning_player = GameState.get_player(self.data["winner_id"]) drawing_player = GameState.get_player(GameState.active_player) # send the player how many points they receive self.data["points"] = POINTS_GUESSER_CORRECT data = { "winner_name": winning_player.name, "drawer_name": drawing_player.name, "answer": GameState.drawing_answer, "wait_time": TIME_BETWEEN_ROUNDS, "drawer_points": POINTS_DRAWER_CORRECTLY_GUESS } for player in GameState.players.values(): if player == winning_player: continue action = Action_CorrectAnswerBroadcast(data, target_id=player.id) GameState.run_action(action) GameState.timer = TIME_BETWEEN_ROUNDS # update points for drawer and winning guesser data = {"id": self.target_id, "points_delta": POINTS_GUESSER_CORRECT} action = Action_Update_Points(data) GameState.run_action(action) data = { "id": drawing_player.id, "points_delta": POINTS_DRAWER_CORRECTLY_GUESS } action = Action_Update_Points(data) GameState.run_action(action)
def run_server(self, GameState): self.data["timer"] = GameState.timer if GameState.timer < 0: GameState.run_action(Action_Init_Game()) GameState.timer = TIME_BETWEEN_ROUNDS
def run_server(self, GameState): if GameState.active_player != self.source_player_id: return GameState.main_pad.update(**self.data) GameState.run_action(Action_Draw_Broadcast(self.data))
def run_server(self, GameState): player = GameState.get_player(self.data["id"]) player.points += self.data["points_delta"] self.data = {"points": player.points} self.target_id = player.id
def run_server(self, GameState): data = {"id": self.target_id, "points_delta": POINTS_GUESSER_WRONG} action = Action_Update_Points(data) GameState.run_action(action)
def run_server(self, GameState): GameState.initialize_game() GameState.run_action(Action_GameState_Sync())