def __call__(self, event): if isinstance(event, e.EndTurnEvent): # print event.player, event.time_left, event.name # print "isinstance(event, e.EndTurnEvent) and self.model.players_order.current_player == event.player", # isinstance(event, e.EndTurnEvent) and self.model.players_order.current_player == event.player print event, "current player", self.model.players_order.current_player, "event player", event.player if isinstance( event, e.EndTurnEvent ) and self.model.players_order.current_player == event.player: if event.time_left <= 0.0: player_score = self.model.scores[event.player] print "*****ROUND OVER*****" self.model.scores[event.player] = player_score - 1 print self.model.scores self.game_stack.post(e.EndRoundEvent(str(self.model.scores))) else: time_left = event.time_left if time_left < 5.0: time_left = 5.0 next_player = self.model.players_order.get_next() word = self.model.word_order.get_next() new_turn_event = e.BeginTurnEvent( next_player, self.model.nicknames[next_player], time_left, word) self.game_stack.post(new_turn_event) elif isinstance(event, e.EndRoundEvent): self.game_stack.pop()
def __call__(self, event): if isinstance( event, e.EndTurnEvent ) and self.model.players_order.current_item == event.player: if event.time_left <= 0.0: self.model.scores[event.player][ 0] -= 1 # scores is {client_id: [score, nickname]} self.model.time_left = self.round_time self.game_stack.post( e.EndRoundEvent(str(self.model.scores.values()))) else: time_left = event.time_left if time_left < self.leeway_time and time_left > 0: time_left = self.leeway_time self.model.time_left = time_left next_player = self.model.players_order.get_next() word = self.model.word_order.get_next() new_turn_event = e.BeginTurnEvent( next_player, self.model.nicknames[next_player], time_left, word) self.game_stack.post(new_turn_event) elif isinstance(event, e.SkipWordEvent): word = self.model.word_order.get_next() player = self.model.players_order.current_item new_turn_event = e.BeginTurnEvent(player, self.model.nicknames[player], event.time_left, word) self.game_stack.post(new_turn_event) elif isinstance(event, e.EndRoundEvent): self.game_stack.pop()