Beispiel #1
0
        private void StartListenServer()
        {
            while (gameInProcess)
            {
                var serverUpdate = (ServerUpdate)Network.ReceivePacket(serverConnection);
                if (serverUpdate == null)
                {
                    continue;
                }
                if (serverUpdate.Animations.Contains(null))
                {
                    throw new Exception();
                }
                if (playerIsRed && serverUpdate.SideColorIsRed || !playerIsRed && !serverUpdate.SideColorIsRed)
                {
                    lock (bottomSideState)
                    {
                        bottomSideState.UpdateStateInAct(serverUpdate.Animations);
                        lock (GameForm.BottomSideHUD)
                        {
                            GameForm.BottomSideHUD.Clear();
                            if (!bottomSideState.GameOver)
                            {
                                Visual.UpdatePlayerHUD(GameForm.BottomSideHUD, bottomSideState.PlayerEntity, GameForm.ClientSize, true);
                            }
                        }
                    }
                }
                else
                {
                    lock (topSideState)
                    {
                        topSideState.UpdateStateInAct(serverUpdate.Animations);

                        lock (GameForm.TopSideHUD)
                        {
                            GameForm.TopSideHUD.Clear();
                            if (!topSideState.GameOver)
                            {
                                Visual.UpdatePlayerHUD(GameForm.TopSideHUD, topSideState.PlayerEntity, GameForm.ClientSize,
                                                       false);
                            }
                        }
                    }
                }
            }
            //server.Close();
            //server.Dispose();
        }
Beispiel #2
0
        public bool ConnectToServer(IPEndPoint serverAddress, bool playerIsRed, string playerName)
        {
            var clientHello = new ClientHello(playerIsRed, playerName);

            server = new TcpClient();
            server.Connect(serverAddress);
            serverConnection = server.GetStream();
            Network.SendPacket(clientHello, serverConnection);
            var serverHello = (ServerHello)Network.ReceivePacket(serverConnection);

            this.playerName  = playerName;
            this.playerIsRed = serverHello.ColorIsRed;
            if (serverHello.EnemyName == null)
            {
                return(false);
            }
            enemyName = serverHello.EnemyName;
            return(true);
        }
Beispiel #3
0
        public void WaitForEnemy()
        {
            var serverHello = (ServerHello)Network.ReceivePacket(serverConnection);

            enemyName = serverHello.EnemyName;
        }