Exemple #1
0
        public override RoShamBo GenerateRoShamBo()
        {
            Console.Write("\nRock, Paper, Scissors. Please pick your selection: ");
            RoShamBo choice = Enum.Parse <RoShamBo>(Validator(Console.ReadLine().ToLower()));

            return(choice);
        }
Exemple #2
0
        public void RockBeatsScissorsTest()
        {
            //Arrange
            RoShamBo roShamBo  = new RoShamBo();
            var      playerOne = "Rock";
            var      playerTwo = "Scissors";
            var      expected  = "Rock beats Scissors";

            //Act
            var actual = roShamBo.Play(playerOne, playerTwo);

            //Assert
            Assert.Equal(expected, actual);
        }
Exemple #3
0
        public void ReturnsATieTest()
        {
            //Arrange
            RoShamBo roShamBo  = new RoShamBo();
            var      playerOne = "Paper";
            var      playerTwo = "Paper";
            var      expected  = "Both players played the same. It's a tie.";

            //Act
            var actual = roShamBo.Play(playerOne, playerTwo);

            //Assert
            Assert.Equal(expected, actual);
        }
Exemple #4
0
        public void PaperBeatsRockTest()
        {
            //Arrange
            RoShamBo roShamBo  = new RoShamBo();
            var      playerOne = "Paper";
            var      playerTwo = "Rock";
            var      expected  = "Paper beats Rock";

            //Act
            var actual = roShamBo.Play(playerOne, playerTwo);

            //Assert
            Assert.Equal(expected, actual);
        }
        private int CountOfChoice(RoShamBo ro)
        {
            //returns the number of times the passed in choice has been
            //used in the list of prior choices
            int count = 0;

            foreach (RoShamBo bo in priorChoices)
            {
                if (ro == bo)
                {
                    count++;
                }
            }
            return(count);
        }
Exemple #6
0
 private Winner CalculateWinner(RoShamBo player1, RoShamBo player2)
 {
     if (player1 == player2)
     {
         return(Winner.tie);
     }
     else if (((RoShamBo)(((int)player1 - 1 + 3) % 3)) == player2) //basically asking if player1s RoShamBo is countered by player2
     {
         return(Winner.player2);
     }
     else if (((RoShamBo)(((int)player2 - 1 + 3) % 3)) == player1) //basically asking if player1s RoShamBo is countered by player2
     {
         return(Winner.player1);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
 public RoShamBo GenerateRoShamBo()
 {
     if (choiceNum >= 6)
     {
         //the prior choices array is filled.
         //make sure the player hasn't picked this choice in the last 6 tries 3 or more times.
         do
         {
             Choice = (RoShamBo)maker.Next(Enum.GetValues(typeof(RoShamBo)).Length);
         } while (CountOfChoice(Choice) >= 3);
     }
     else
     {
         //first six choices are not using any logic to ensure they are spread out
         Choice = (RoShamBo)maker.Next(Enum.GetValues(typeof(RoShamBo)).Length);
     }
     //overwite the array members to make the array a fixed size, only the prior six matter
     priorChoices[choiceNum % 6] = Choice;
     //iterate the choice number so it fills the next space in the array on the next call
     choiceNum++;
     return(Choice);
 }
Exemple #8
0
 public Round(RoShamBo player1RoShamBo, RoShamBo player2RoShamBo)
 {
     this.player1RoShamBo = player1RoShamBo;
     this.player2RoShamBo = player2RoShamBo;
     winner = CalculateWinner(Player1RoShamBo, Player2RoShamBo);
 }
 public RoShamBo GenerateRoShamBo()
 {
     Choice = validator.GetRoShamBo();
     return(Choice);
 }
Exemple #10
0
 public RoShamBo GenerateRoShamBo()
 {
     Choice = RoShamBo.Rock;
     return(Choice);
 }
Exemple #11
0
        public override RoShamBo GenerateRoShamBo()
        {
            RoShamBo rock = RoShamBo.rock;

            return(rock);
        }