///<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(); }
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(); }
public void Run() { ColorLoader.Load(); Settings.LoadSettings(); Console.Clear(); var baseLoop = new InputLoop(this, GameCommands); InputLoops.Add(baseLoop); OnStart(this); baseLoop.Start(); OnClose(this); }
async Task OnEnable() { var scheduler = TaskScheduler.FromCurrentSynchronizationContext(); playerSpawner.TaskScheduler = scheduler; dataHolder.Initialize(); await delay; input = new InputLoop(udpSocketHolder.UdpClient, dataHolder, playerSpawner, 5); input.Start(); _statusCheckLoop = new StatusCheckLoop(dataHolder, 5000); _statusCheckLoop.Run(); _cancellationTokenSources.Add(_statusCheckLoop.Cts); }
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(); }
public void InvokeState() { var level = levelFactory.CreateLevel(); var inputLoop = new InputLoop(); var playView = new ConsolePlayView(); var moveInteractor = new MoveInteractor(level, playView); var exitGameInteractor = new ExitGameInteractor(inputLoop); var moveProcessor = new MoveProcessor(moveInteractor); var exitGameProcessor = new ExitGameProcessor(exitGameInteractor); var keyboardController = new KeyboardController(); keyboardController.AddInputProcessor(moveProcessor); keyboardController.AddInputProcessor(exitGameProcessor); inputLoop.AddUpdatable(keyboardController); playView.Draw(level); inputLoop.Start(); }