Beispiel #1
0
        public Communicator(Settings settings, Battlefield battlefield, GameStateClient gameState, out RealCharacter player)
        {
            _battlefield = battlefield;
            _gameState = gameState;
            // подключаемся к серверу
            ServerConnectionPacket connMsg = Connect(settings, ref _clientPort);
            if (connMsg == null)
            {
                _battlefield.Game.Exit();
            }
            _messenger = new UdpMessenger(settings.ServerAddress, settings.ServerPort, _clientPort, _receiveTimeout);
            _gameState.SetLevel((Level)connMsg.Level);
            // обновление состояния игрока
            _gameState.CreateCharacter(connMsg.PlayerId);
            player = _gameState.Players[connMsg.PlayerId];
            player.Position = (Vector2)connMsg.PlayerPosition;
            player.Health = connMsg.Health;
            player.Speed = connMsg.Speed;
            player.MoveBehavior = new PlayerMove1(player);
            _gameState.Player = player;

            _gameState.NetPlayer = new NetPlayer(_messenger, player);
            new Thread(StartReceiving).Start();
            new Thread(StartSending).Start();
        }
Beispiel #2
0
        protected override void Initialize()
        {
            GameStateClient gameState = new GameStateClient();
            battlefield = new Battlefield(this, settings, gameState);
            Components.Add(battlefield);
            Components.Add(new GameConsole(this, gameState));

            base.Initialize();
        }