///<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(); }
/// <summary> /// Reads data from the input buffer until a break key(s) is found. /// </summary> /// <returns></returns> public ReadRef Read() { return(InputLoop.ReadInput( new ReadOptions() { BackgroundColor = BackgroundColor, ForegroundColor = ForegroundColor })); }
/// <summary> /// Reads a single key from the input buffer until a break key(s) is found. /// </summary> /// <returns></returns> public ReadRef ReadKey() { return(InputLoop.ReadInput( new ReadOptions() { BackgroundColor = BackgroundColor, ForegroundColor = ForegroundColor, ReadLength = 1 })); }
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(TextReader reader, TextWriter writer) { using (new TextConsole(this.bus, reader, writer)) using (new SentenceParser(this.bus, this.words)) using (EndOfGame endOfGame = new EndOfGame(this.bus)) using (InputLoop loop = new InputLoop(this.bus, ">")) using (new Inventory(this.bus)) using (this.InitializeMap()) { loop.Run(endOfGame.Token); } }
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 UnsubscribesOnDispose() { MessageBus bus = new MessageBus(); InputLoop loop = new InputLoop(bus); loop.Dispose(); bool received = false; bus.Subscribe <InputEndedMessage>(_ => received = true); bus.Send(new InputEndedMessage()); received.Should().BeTrue(); }
public void RunCancelBeforeEnd() { MessageBus bus = new MessageBus(); using (CancellationTokenSource cts = new CancellationTokenSource()) { bus.Subscribe <InputRequestedMessage>(_ => cts.Cancel()); using (InputLoop loop = new InputLoop(bus)) { Action act = () => loop.Run(cts.Token); act.Should().NotThrow(); } } }
public void RunCancelImmediately() { MessageBus bus = new MessageBus(); bus.Subscribe <InputRequestedMessage>(_ => throw new InvalidOperationException("Should not have requested input.")); using (CancellationTokenSource cts = new CancellationTokenSource()) { cts.Cancel(); using (InputLoop loop = new InputLoop(bus)) { Action act = () => loop.Run(cts.Token); act.Should().NotThrow(); } } }
public void RunInputEnded() { MessageBus bus = new MessageBus(); string prompt = null; bus.Subscribe <InputRequestedMessage>(m => { prompt = m.Prompt; bus.Send(new InputEndedMessage()); }); using (InputLoop loop = new InputLoop(bus, "Yes?")) { loop.Run(CancellationToken.None); prompt.Should().Be("Yes?"); } }
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 RunReadTwoLines() { MessageBus bus = new MessageBus(); int linesRead = 0; bus.Subscribe <InputRequestedMessage>(_ => { if (++linesRead == 2) { bus.Send(new InputEndedMessage()); } }); using (InputLoop loop = new InputLoop(bus)) { loop.Run(CancellationToken.None); linesRead.Should().Be(2); } }
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(); }
internal static void RunNewInputLoop(ConsoleHost parent, bool isNested) { // creates an instance and adds it to the stack and starts it running. int stackCount = s_instanceStack.Count; if (stackCount == PSHost.MaximumNestedPromptLevel) { throw PSTraceSource.NewInvalidOperationException(ConsoleHostStrings.TooManyNestedPromptsError); } InputLoop il = new InputLoop(parent, isNested); s_instanceStack.Push(il); il.Run(s_instanceStack.Count > 1); // Once the loop has finished running, remove it from the instance stack. InputLoop il2 = s_instanceStack.Pop(); Dbg.Assert(il == il2, "top of instance stack does not correspond to the instance pushed"); }
/// <summary> /// Reads data from the input buffer until a break key(s) is found. /// </summary> /// <returns></returns> public ReadRef Read(ReadOptions options) { return(InputLoop.ReadInput(options)); }