Beispiel #1
0
        public void MovePlayer(PlayerHeading direction)
        {
            if (AssignedPlayer == null)
            {
                return;
            }

            AssignedPlayer.Move(direction);
            NetworkPacketSerializer.WritePacket(new PlayerUpdatePacket(AssignedPlayer), Socket);
            //TODO: move/interact might be pulled into own interface implemented by Player and some kind of network-decorator for Player
        }
Beispiel #2
0
        public void Update()
        {
            if (State != NetworkClientState.Ready)
            {
                return;
            }

            while (Socket.Available > 0)
            {
                NetworkPacket packet = NetworkPacketSerializer.ReadPacket(Socket);
                ReceiveUpdate(packet);
            }
        }
Beispiel #3
0
        void OnConnectionEstablished(object sender, SocketAsyncEventArgs e)
        {
            if (e.SocketError != SocketError.Success)
            {
                State = NetworkClientState.Disconnected;
                return;
            }
            NetworkPacketSerializer.WritePacket(new JoinRequestPacket(), Socket);
            var packet  = NetworkPacketSerializer.ReadPacket(Socket);
            var welcome = packet as WelcomePacket;

            if (packet == null)
            {
                throw new Exception("Expected a welcome packet but received something else!");
            }
            Playground = new Playground(welcome.Map);
            RaiseMapChanged(welcome.Map);
            State = NetworkClientState.Ready;
        }