Example #1
0
        public void TestCompareThrows(RPSChoice a, RPSChoice b, int expected)
        {
            GameEngine engine = new GameEngine();
            int        actual = engine.CompareThrows(a, b);

            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public int CompareThrows(RPSChoice a, RPSChoice b)
        {
            // - a wins
            // 0 tie
            // + b wins

            int toReturn = 0;

            if (a != b)
            {
                switch (a)
                {
                case RPSChoice.Paper:
                    toReturn = (b == RPSChoice.Rock) ? -1 : 1;
                    break;

                case RPSChoice.Rock:
                    toReturn = (b == RPSChoice.Scissors) ? -1 : 1;
                    break;

                case RPSChoice.Scissors:
                    toReturn = (b == RPSChoice.Paper) ? -1 : 1;
                    break;
                }
            }

            return(toReturn);
        }
Example #3
0
        public static int CompareThrows(RPSChoice a, RPSChoice b)
        {
            // a wins
            // 0 tie
            // + b wons

            int toReturn = 0;

            if (a != b)
            {
                switch (a)
                {
                case RPSChoice.Paper:
                    toReturn = (b == RPSChoice.Rock) ? -1 : 1;     //? = turnary operator. if b == rock, if that's true return -1, else that is false and return 1
                    break;

                case RPSChoice.Rock:
                    toReturn = (b == RPSChoice.Scissors) ? -1 : 1;
                    break;

                case RPSChoice.Scissors:
                    toReturn = (b == RPSChoice.Paper) ? -1 : 1;
                    break;
                }
            }

            return(toReturn);
        }
Example #4
0
        public RoundResult PlayRound()
        {
            RPSChoice p1Choice = _player1.GetChoice();
            RPSChoice p2Choice = _player2.GetChoice();

            int result = CompareThrows(p1Choice, p2Choice);

            return(new RoundResult(p1Choice, p2Choice, result));
        }
 public RockPaperScissorsHandler.Outcome duel(RPSChoice other)
 {
     if (other is Rock)
         return RockPaperScissorsHandler.Outcome.TIE;
     if (other is Paper)
         return RockPaperScissorsHandler.Outcome.LOSS;
     if (other is Scissors)
         return RockPaperScissorsHandler.Outcome.WIN;
     return RockPaperScissorsHandler.Outcome.NULL;
 }
Example #6
0
    public static int PlayRPS(RPSChoice _PlayerOneChoice, RPSChoice _PlayerTwoChoice)
    {
        switch (_PlayerOneChoice - _PlayerTwoChoice)
        {
        case -2: // ROCK vs SCISSORS
        case  1: // PAPER vs ROCK || SCISSORS vs PAPER
            return(1);

        case -1: // ROCK vs PAPER || PAPER vs SCISSORS
        case  2: // SCISSORS vs ROCK
            return(2);

        default: // ROCK vs ROCK || PAPER vs PAPER || SCISSOR vs SCISSORS || Error
            return(0);
        }
    }
Example #7
0
        public RPSChoice GetChoice()
        {
            int choice = RNG.NextInt(0, 3);

            RPSChoice toReturn = RPSChoice.Paper;

            switch (choice)
            {
            case 0:
                toReturn = RPSChoice.Paper;
                break;

            case 1:
                toReturn = RPSChoice.Rock;
                break;

            case 2:
                toReturn = RPSChoice.Scissors;
                break;
            }

            return(toReturn);
        }
Example #8
0
        public void PlayGame(IRPSPlayer p1, IRPSPlayer p2)
        {
            RPSChoice p1Choice = p1.GetChoice();
            RPSChoice p2Choice = p2.GetChoice();

            if (p1Choice == p2Choice)
            {
                ConsoleOutput.TieMessage(p1, p2);
            }
            else if (p1Choice == RPSChoice.Rock && p2Choice == RPSChoice.Scissors ||
                     p1Choice == RPSChoice.Paper && p2Choice == RPSChoice.Rock ||
                     p1Choice == RPSChoice.Scissors && p2Choice == RPSChoice.Paper)
            {
                ConsoleOutput.P1WinMessage(p1);
            }
            //else if(p2Choice == RPSChoice.Nuke)
            //{
            //    ConsoleOutput.P1NukedMessage(p1);
            //}
            else
            {
                ConsoleOutput.P2WinMessage(p2);
            }
        }
Example #9
0
        public RPSChoice GetChoice()
        {
            RPSChoice playerChoice = RPSChoice.Paper;

            bool validInput = false;

            while (!validInput)
            {
                Console.Write("Please enter choice (R/P/S): ");
                string playerEntry = Console.ReadLine().ToUpper();

                switch (playerEntry)
                {
                case "R":
                    playerChoice = RPSChoice.Rock;
                    validInput   = true;
                    break;

                case "P":
                    playerChoice = RPSChoice.Paper;
                    validInput   = true;
                    break;

                case "S":
                    playerChoice = RPSChoice.Scissors;
                    validInput   = true;
                    break;

                default:
                    Console.WriteLine("INVALID SELECTION!");
                    break;
                }
            }

            return(playerChoice);
        }
Example #10
0
 public RoundResult(RPSChoice p1Choice, RPSChoice p2Choice, int result)
 {
     P1Choice = p1Choice;
     P2Choice = p2Choice;
     Result   = result;
 }
 public RockPaperScissorsHandler.Outcome duel(RPSChoice other)
 {
     return RockPaperScissorsHandler.Outcome.NULL;
 }