Пример #1
0
        public void PushTankGameLogic(object clientObj)
        {
            Client client = (Client)clientObj;

            GameInfoUpdate gameInfoUpdate = new GameInfoUpdate(clientGameTank);

            for (int i = 0; i < clientGameTank.Count; i++)
            {
                clientsList[i].UDPSend(gameInfoUpdate);
            }

            GameInfoSpriteUpdate gameInforSpriteUpdate = new GameInfoSpriteUpdate(tankSprite);

            for (int i = 0; i < tankSprite.Count; i++)
            {
                clientsList[i].UDPSend(gameInforSpriteUpdate);
            }

            GameInfoBombUpdate gameInfoBombUpdate = new GameInfoBombUpdate(clientBomb);

            for (int i = 0; i < clientBomb.Count; i++)
            {
                clientsList[i].UDPSend(gameInfoBombUpdate);
            }
            GameInfoBombSpriteUpdate gameInforBombSpriteUpdate = new GameInfoBombSpriteUpdate(bombSprie);

            for (int i = 0; i < bombSprie.Count; i++)
            {
                clientsList[i].UDPSend(gameInforBombSpriteUpdate);
            }
        }
Пример #2
0
        private void UDPServerResponse()
        {
            try
            {
                while (udpClientConnect)
                {
                    Packet udpReadPacket = UDPClientRead();
                    switch (udpReadPacket.type)
                    {
                    case PacketType.NICKNAMESCONNECTED:
                        ConnectedNicknames connectedNicknamePack = (ConnectedNicknames)udpReadPacket;
                        Console.WriteLine("Clients connected are " + connectedNicknamePack.nicknamesConnected);
                        messageForm.UpdateClientListBox(connectedNicknamePack.nicknamesConnected);
                        break;

                    case PacketType.GAMEINFORMATION:
                        GameInfoUpdate gameInfoUpdatePacket = (GameInfoUpdate)udpReadPacket;
                        mainGame.UpdateDictionaryInfo(gameInfoUpdatePacket.clientGameTankPacket);
                        mainGame.ForcePaint();
                        break;

                    case PacketType.GAMESPRITE:
                        GameInfoSpriteUpdate gameInfoSpriteUpdate = (GameInfoSpriteUpdate)udpReadPacket;
                        mainGame.UpdateSpriteInfo(gameInfoSpriteUpdate.cliengGameSpriteInfo);
                        break;

                    case PacketType.GAMEBOMBINFORMATION:
                        GameInfoBombUpdate gameInfoBombUpdatePacket = (GameInfoBombUpdate)udpReadPacket;
                        mainGame.UpdateBombDictionaryInfo(gameInfoBombUpdatePacket.clientGameBombPacket);
                        mainGame.ForcePaint();
                        break;

                    case PacketType.GAMEBOMBSPRITE:
                        GameInfoBombSpriteUpdate gameInfoBombSpriteUpdate = (GameInfoBombSpriteUpdate)udpReadPacket;
                        mainGame.UpdateBombSpriteInfo(gameInfoBombSpriteUpdate.cliengGameBombSpriteInfo);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
            }
        }