Beispiel #1
0
 async def start(self, player1: Player, player2: Player):
     if not await Messages.askIfReady(player1):
         await player1.sendMessageSafe("KICKED:AFK")
         await player1.disconnect()
         raise PlayerKickedException(player1, "Not ready for battle")
     
     if not await Messages.askIfReady(player2):
         await player2.sendMessageSafe("KICKED:AFK")
         await player2.disconnect()
         raise PlayerKickedException(player2, "Not ready for battle")
     
     p1 = Phase1(player1, player2)
     logger.debug("Game #{}: phase 1 begins.".format(self.__ID))
     await p1.start()
     
     base1 = p1.getPlayer1Base()
     base2 = p1.getPlayer2Base()
     
     p2 = Phase2(player1, player2, base1, base2)
     logger.debug("Game #{}: phase 2 begins.".format(self.__ID))
     await p2.start()
     
     attackBase1 = p2.getAttackBase1()
     attackBase2 = p2.getAttackBase2()
     
     finalBase1 = self.__mergeBase(attackBase2, base1)
     finalBase2 = self.__mergeBase(attackBase1, base2)
     
     p3 = Phase3(player1, player2, finalBase1, finalBase2)
     logger.debug("Game #{}: phase 3 begins.".format(self.__ID))
     await p3.start()
     
     self.__winner = p3.getWinner()
Beispiel #2
0
    async def getBase(player: Player):

        player.clearMessages()
        await player.sendMessage("GET_BASE")

        for _ in range(5):
            msg = player.getMessageIfReceived()
            if msg == "OK":
                return
            await player.ping()
            await asyncio.sleep(1)

        logger.error("{} received a GET_BASE signal but didn't respond!".format(player.getAddress()))
        await player.sendMessageSafe("KICKED:NO_RESPONSE")
        await player.disconnect()
        raise PlayerKickedException(player, "No response")
Beispiel #3
0
 async def __kick(player):
     logger.error("{} stopped responding during base getting!".format(
         player.getAddress()))
     await player.sendMessageSafe("KICKED:NO_RESPONSE")
     await player.disconnect()
     raise PlayerKickedException(player, "No response")