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 }
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; }