def test_HandleEndGameEvent(self): e = UDPGameEngine() s = GameState() evt = EndGameEvent() evt.score_0 = 1 evt.score_1 = 534 evt.score_2 = -32 e.HandleEndGameEvent(s, evt) self.assertTrue(s.is_ended == True) self.assertTrue(s.scores[0] == evt.score_0) self.assertTrue(s.scores[1] == evt.score_1) self.assertTrue(s.scores[2] == evt.score_2)
def SendEndGameEvent(self, clients, s): '''Send the end of game event to each client. Arguments: clients -- The list of client EventSocket. s -- The game state. ''' evt = EndGameEvent() evt.score_0 = s.scores[0] evt.score_1 = s.scores[1] evt.score_2 = s.scores[2] for c in list(clients): try: c.WriteEvent(evt) except Exception as e: logger.exception(e) c.Close() clients.remove(c)
def test_ReadAndWriteEvent_EndGame_2(self): evt = EndGameEvent() evt.score_0 = 3 evt.score_1 = 484 evt.score_2 = 3478 self.template_ReadAndWriteEvent(evt)