Exemple #1
0
        public void RockPaperScissorsRules_GetNextWinningMove_WinnerCorrect(int lastMove, int expectedResult)
        {
            //ARRANGE
            RockPaperScissorsRules ruleSet = new RockPaperScissorsRules();

            //ACT
            var winningMove = ruleSet.GetNextWinningMove(lastMove);

            //ASSERT
            Assert.AreEqual(expectedResult, winningMove);
        }
Exemple #2
0
        public void RockPaperScissorsRules_GetWinningMove_WinnerCorrect(int playerOneMove, int playerTwoMove, int expectedResult)
        {
            //ARRANGE
            RockPaperScissorsRules ruleSet = new RockPaperScissorsRules();

            //ACT
            var winningPlayer = ruleSet.GetWinningMove(playerOneMove, playerTwoMove);

            //ASSERT
            Assert.AreEqual(expectedResult, winningPlayer);
        }
Exemple #3
0
        public void ComputerPlayer_GetNextMove_NextMoveIsInsidePossibleMoves()
        {
            //ARRANGE
            IRules  rules  = new RockPaperScissorsRules();
            IPlayer player = new ComputerPlayer();

            //ACT
            int nextMove = player.GetNextMove(rules);

            //ASSERT
            Assert.That(nextMove, Is.InRange(1, 3));
        }
Exemple #4
0
        public void TacticalPlayer_GetNextMove_NextMoveIsCorrect(int lastMove, int expectedMove)
        {
            //ARRANGE
            IRules  rules  = new RockPaperScissorsRules();
            IPlayer player = new TacticalPlayer(lastMove);

            //ACT
            int nextMove = player.GetNextMove(rules);

            //ASSERT
            Assert.AreEqual(expectedMove, nextMove);
        }
Exemple #5
0
        public void HumanPlayer_GetNextMove_ThrowsAnExceptio()
        {
            //ARRANGE
            var     expectedExceptionText = "UI is responsible to get next move for this type of player";
            IRules  rules  = new RockPaperScissorsRules();
            IPlayer player = MockRepository.GenerateStub <HumanPlayer>();

            //ACT
            void testAction()
            {
                player.GetNextMove(rules);
            }

            //ASSERT
            Exception ex = Assert.Throws <Exception>(testAction);

            Assert.AreEqual(expectedExceptionText, ex.Message);
        }
Exemple #6
0
        static bool TryCreateGameRules(string type, out RuleList rules)
        {
            switch (type)
            {
            case "D":
                rules = new RockPaperScissorsRules();
                break;

            case "E":
                rules = new RockPaperScissorsLizardSpockRules();
                break;

            default:
                rules = null;
                break;
            }

            return(rules != null);
        }
Exemple #7
0
        public GameResult Play(string input)
        {
            Weapon computerWeapon = GetRandomWeapon();
            Weapon playerWeapon   = ConvertToWeapon(input);

            RockPaperScissorsRules game = new RockPaperScissorsRules();

            var winningWeapon = game.Fight(playerWeapon, computerWeapon);

            if (winningWeapon == Weapon.None)
            {
                return(GameResult.Draw);
            }
            else if (winningWeapon == computerWeapon)
            {
                ComputerScore++;
                return(GameResult.Lose);
            }
            else
            {
                PlayerScore++;
                return(GameResult.Win);
            }
        }
Exemple #8
0
 public RockPaperScissorsRulesTests()
 {
     this.subject = new RockPaperScissorsRules();
 }