/// This method is called when the Play button has been pressed /// The game ui model is bound to the form so arrives with data from the UI /// This method runs GameEngine to display the winner public IActionResult Index(GameUIModel gameUIModel) { Game game = new Game(new Player("Player1"), new Player("Player2")); gameUIModel.GameResult = game.Play((int)gameUIModel.Player1Move, (int)gameUIModel.Player2Move); return(View(gameUIModel)); }
public IActionResult Index() { //Default selection is Computer vs Computer GameUIModel gameModel = new GameUIModel { Player1Move = MoveChoice.RANDOM, //This will prevent invalid null move submission Player2Move = MoveChoice.RANDOM, //This will prevent invalid null move submission GameResult = string.Empty }; return(View(gameModel)); }
public void IndexPostRender_PaperBeatsRock() { HomeController controller = new HomeController(logger); var userInput = new GameUIModel() { Player1Move = MoveChoice.PAPER, Player2Move = MoveChoice.ROCK }; ViewResult result = controller.Index(userInput) as ViewResult; var uiModel = (GameUIModel)result.Model; Assert.AreEqual(uiModel.GameResult, "(Paper/Rock): Player 1 won!"); }
public void IndexPostRender_PaperLosesToScissors() { HomeController controller = new HomeController(logger); var userInput = new GameUIModel() { Player1Move = MoveChoice.PAPER, Player2Move = MoveChoice.SCISSORS }; ViewResult result = controller.Index(userInput) as ViewResult; var uiModel = (GameUIModel)result.Model; Assert.AreEqual(uiModel.GameResult, "(Paper/Scissor): Player 1 lost."); }
public void IndexPostRender_PaperTiesPaper() { HomeController controller = new HomeController(logger); var userInput = new GameUIModel() { Player1Move = MoveChoice.PAPER, Player2Move = MoveChoice.PAPER }; ViewResult result = controller.Index(userInput) as ViewResult; var uiModel = (GameUIModel)result.Model; Assert.AreEqual(uiModel.GameResult, "(Paper/Paper): The game is a tie."); }