///<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(); }
private async void OnDisable() { await delay; input.Stop(); await Task.Delay(10); udpSocketHolder.TryClose(); foreach (var cts in _cancellationTokenSources) { cts.Cancel(); } }