private void OnKeyPressed(OnKeyPressedEventArgs args) { if (_onKeyPressed != null) { _onKeyPressed(this, args); } }
private void UseKeyForAppQuit(object sender, OnKeyPressedEventArgs eventArgs) { if (eventArgs == null) { throw new ArgumentNullException(); } ConsoleKeyInfo cki = eventArgs.KeyInfo; if (cki.Key == ConsoleKey.J || cki.Key == ConsoleKey.N) { this.keyBoardWatcher.OnKeyPressed -= this.UseKeyForRestartAnswer; this.keyBoardWatcher.OnKeyPressed -= this.UseKeyForAppQuit; this.consoleSizeWatcher.OnSizeChanged -= RenewRestartQuestion; keyBoardWatcher.Stop(); consoleSizeWatcher.Stop(); if (cki.Key == ConsoleKey.J) { QuitApp = false; QuitGame = true; } else if (cki.Key == ConsoleKey.N) { QuitApp = true; QuitGame = true; } } }
private void UseKeyForGame(object sender, OnKeyPressedEventArgs eventArgs) { if (eventArgs == null) { throw new ArgumentNullException(); } Field cursorField = new Field(gamehandler.Cursor.Position.Left, gamehandler.Cursor.Position.Top); cursorField.Accept(renderer); ConsoleKeyInfo cki = eventArgs.KeyInfo; Position currentpos = cursorField.Position; ICommand gamecommand = null; switch (cki.Key) { case ConsoleKey.UpArrow: currentpos.Top--; gamecommand = new MoveCommand(currentpos.Left, currentpos.Top); break; case ConsoleKey.DownArrow: currentpos.Top++; gamecommand = new MoveCommand(currentpos.Left, currentpos.Top); break; case ConsoleKey.LeftArrow: currentpos.Left--; gamecommand = new MoveCommand(currentpos.Left, currentpos.Top); break; case ConsoleKey.RightArrow: currentpos.Left++; gamecommand = new MoveCommand(currentpos.Left, currentpos.Top); break; case ConsoleKey.Enter: gamecommand = new DiscoverFieldCommand(currentpos.Left, currentpos.Top); break; case ConsoleKey.X: gamecommand = new SetFlagCommand(currentpos.Left, currentpos.Top); break; case ConsoleKey.F12: gamecommand = new CheatModeCommand(); break; } if (gamecommand != null) { gamehandler.Accept(gamecommand); this.gamehandler.Accept(this.renderer); this.gamehandler.Cursor.Accept(this.renderer); this.IsGameFinished(); } }
private void UseKeyForInput(object sender, OnKeyPressedEventArgs eventArgs) { if (eventArgs == null) { throw new ArgumentNullException(); } ConsoleKeyInfo cki = eventArgs.KeyInfo; inputhandler.AcceptKey(cki); inputhandler.Accept(renderer); }
private void UseKeyForRestartAnswer(object sender, OnKeyPressedEventArgs eventArgs) { if (eventArgs == null) { throw new ArgumentNullException(); } ConsoleKeyInfo cki = eventArgs.KeyInfo; gameFinisher.AcceptKey(cki); gameFinisher.Accept(renderer); if (this.gameFinisher.IsGameFinishAccepted) { this.keyBoardWatcher.OnKeyPressed += this.UseKeyForAppQuit; } }