Пример #1
0
        public void InvokeState()
        {
            var playView = new ConsolePlayView();

            var level = client.Login(login, sessionId);

            if (level == null)
            {
                throw new ArgumentException("Login already exists.");
            }

            var inputLoop = new InputLoop();

            var playerMoveInteractor  = new NetworkPlayerMoveInteractor(level, playView);
            var mobMoveInteractor     = new NetworkMobMoveInteractor(level, playView);
            var exitGameInteractor    = new ExitGameInteractor(level);
            var inventoryInteractor   = new InventoryInteractor(level, playView);
            var spawnPlayerInteractor = new SpawnPlayerInteractor(level, playView);

            var moveProcessor      = new MoveProcessor(playerMoveInteractor);
            var exitGameProcessor  = new ExitGameProcessor(exitGameInteractor);
            var inventoryProcessor = new InventoryProcessor(inventoryInteractor);

            var keyboardController = new KeyboardController(level, login);

            keyboardController.AddInputProcessor(client);

            keyboardController.AddInputProcessor(exitGameProcessor);

            client.AddInputProcessor(moveProcessor);
            client.AddInputProcessor(exitGameProcessor);
            client.AddInputProcessor(inventoryProcessor);

            client.SetMobInteractor(mobMoveInteractor);
            client.SetPlayerMoveInteractor(playerMoveInteractor);
            client.SetSpawnPlayerInteractor(spawnPlayerInteractor);

            inputLoop.AddUpdatable(keyboardController);
            inputLoop.AddUpdatable(client);

            level.CurrentPlayer = level.GetPlayer(login);

            level.CurrentPlayer.OnDie += (sender, args) =>
            {
                inputLoop.Stop();
            };

            exitGameInteractor.OnExit += (sender, player) =>
            {
                inputLoop.Stop();
            };

            playView.Draw(level);
            inputLoop.Start();
        }
Пример #2
0
        public void NetworkMobMoveInteractorTest()
        {
            var playView          = new VoidView();
            var mobMoveInteractor = new NetworkMobMoveInteractor(level, playView);
            var cowardMob         = level.Mobs[0];

            var oldPosition = cowardMob.Position;

            mobMoveInteractor.IntentMove(cowardMob, 1, 0);
            var newPosition = cowardMob.Position;

            Assert.AreEqual(oldPosition.X, newPosition.X);
            Assert.AreEqual(oldPosition.Y, newPosition.Y);

            var aggressiveMob = level.Mobs[5];

            oldPosition = aggressiveMob.Position;
            mobMoveInteractor.IntentMove(aggressiveMob, 0, 1);
            newPosition = aggressiveMob.Position;

            Assert.AreEqual(oldPosition.X, newPosition.X);
            Assert.AreEqual(oldPosition.Y, newPosition.Y);
        }