///<summary>
        /// Creates Input, View and Interaction components:
        /// Creates different move processors
        /// for each character on board, registers them in controllers.
        /// Creates interactors and passes created level and view to them.
        /// </summary>
        public void InvokeState()
        {
            var level     = levelFactory.CreateLevel();
            var inputLoop = new InputLoop();
            var playView  = new ConsolePlayView();

            var playerMoveInteractor = new PlayerMoveInteractor(level, playView);
            var mobMoveInteractor    = new MobMoveInteractor(level, playView);
            var saveGameInteractor   = new SaveGameInteractor(level);
            var exitGameInteractor   = new ExitGameInteractor(level);
            var inventoryInteractor  = new InventoryInteractor(level, playView);

            var moveProcessor            = new MoveProcessor(playerMoveInteractor);
            var saveAndExitGameProcessor = new SaveAndExitGameProcessor(exitGameInteractor, saveGameInteractor);
            var inventoryProcessor       = new InventoryProcessor(inventoryInteractor);

            var keyboardController = new KeyboardController(level, OfflinePlayerLogin);
            var tickController     = new TickController();

            keyboardController.AddInputProcessor(moveProcessor);
            keyboardController.AddInputProcessor(saveAndExitGameProcessor);
            keyboardController.AddInputProcessor(inventoryProcessor);

            inputLoop.AddUpdatable(keyboardController);
            inputLoop.AddFixedUpdatable(tickController);

            if (!level.ContainsPlayer(OfflinePlayerLogin))
            {
                level.AddPlayerAtEmpty(OfflinePlayerLogin);
            }

            level.CurrentPlayer = level.GetPlayer(OfflinePlayerLogin);

            var mobs = level.Mobs;

            foreach (var mob in mobs)
            {
                var mobMoveProcessor = new MobMoveProcessor(mob, mobMoveInteractor);
                tickController.AddTickProcessor(mobMoveProcessor);
                mob.OnDie += (sender, args) =>
                {
                    level.Mobs.Remove(mob);
                    tickController.RemoveTickProcessor(mobMoveProcessor);
                };
            }

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

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

            playView.Draw(level);
            inputLoop.Start();
        }
Esempio n. 2
0
        public void InvokeState()
        {
            var level     = levelFactory.CreateLevel();
            var inputLoop = new InputLoop();
            var playView  = new VoidView();

            var inputController = new ServerInputController(level, newSessionId, inputService);

            var exitGameInteractor   = new ExitGameInteractor(level, inputController);
            var playerMoveInteractor = new PlayerMoveInteractor(level, playView, inputController);
            var mobMoveInteractor    = new MobMoveInteractor(level, playView, inputController);
            var inventoryInteractor  = new InventoryInteractor(level, playView);

            levelFactory.SetPlayerFactory(new NetworkPlayerFactory(exitGameInteractor));

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

            var tickController = new TickController();

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

            inputLoop.AddFixedUpdatable(tickController);
            inputLoop.AddUpdatable(inputController);

            level.CurrentPlayer = new Player(DummyLogin, level, new Position(-1, -1));

            var mobs = level.Mobs;

            foreach (var mob in mobs)
            {
                var mobMoveProcessor = new MobMoveProcessor(mob, mobMoveInteractor);
                tickController.AddTickProcessor(mobMoveProcessor);
                mob.OnDie += (sender, args) =>
                {
                    level.Mobs.Remove(mob);
                    tickController.RemoveTickProcessor(mobMoveProcessor);
                };
            }

            inputLoop.Start();
        }