/// <summary> /// Handler for all keyboard input, actions taken depend on the Game State. /// </summary> private void HandleUserInput() { var currentGameState = _gameStateStateMachine.State; var input = _inputHandler.Listen(); // ReSharper disable once SwitchStatementMissingSomeCases, most inputs are not supported. switch (input) { case KeyCode.Space: if (currentGameState == GameState.None) { _gameStateStateMachine.Fire(GameStateTrigger.StartGame); _worldMapStateMachine.Fire(PlayerMovement.Forward); } break; case KeyCode.None: break; case KeyCode.UpArrow: if (currentGameState == GameState.Playing) { _worldMapStateMachine.Fire(PlayerMovement.Forward); } break; case KeyCode.DownArrow: if (currentGameState == GameState.Playing) { _worldMapStateMachine.Fire(PlayerMovement.Backward); } break; case KeyCode.LeftArrow: if (currentGameState == GameState.Playing) { _worldMapStateMachine.Fire(PlayerMovement.Left); } break; case KeyCode.RightArrow: if (currentGameState == GameState.Playing) { _worldMapStateMachine.Fire(PlayerMovement.Right); } break; default: var errorMessage = $"KeyCode: {input} is not supported."; throw new NotSupportedException(errorMessage); } }
public void CanTransitionStateMachineFromPayingToGameOver() { var displayHandler = MockDisplayHandler.Object; const GameState gameState = GameState.Playing; var stateMachine = new StateMachineGameState(gameState, displayHandler); stateMachine.Fire(GameStateTrigger.StopGame); const GameState expectedState = GameState.GameOver; var actualState = stateMachine.State; Assert.Equal(expectedState, actualState); MockDisplayHandler.Verify(mock => mock.DisplayMessage(It.IsAny <string>()), Times.Once); }