示例#1
0
        public override ThrowChoice GetChoice()
        {
            ThrowChoice computerChoice = new ThrowChoice();

            int i = _randomGenerator.Next(1, 6);

            switch (i)
            {
            case 1:
                computerChoice.throwChoice = Choice.Rock;
                break;

            case 2:
                computerChoice.throwChoice = Choice.Paper;
                break;

            case 3:
                computerChoice.throwChoice = Choice.Scissors;
                break;

            case 4:
                computerChoice.throwChoice = Choice.Lizard;
                break;

            default:
                computerChoice.throwChoice = Choice.Spock;
                break;
            }

            return(computerChoice);
        }
        public override ThrowChoice GetChoice()
        {
            ThrowChoice computerChoice = new ThrowChoice();

            int i = _randomGenerator.Next(1, 6);

            switch (i)
            {
                case 1:
                    computerChoice.throwChoice = Choice.Rock;
                    break;
                case 2:
                    computerChoice.throwChoice = Choice.Paper;
                    break;
                case 3:
                    computerChoice.throwChoice = Choice.Scissors;
                    break;
                case 4:
                    computerChoice.throwChoice = Choice.Lizard;
                    break;
                default:
                    computerChoice.throwChoice = Choice.Spock;
                    break;
            }

            return computerChoice;
        }
        public override ThrowChoice GetChoice()
        {
            ThrowChoice playerChoice = new ThrowChoice();

            playerChoice.throwChoice = Choice.Unknown;

            while (playerChoice.throwChoice == Choice.Unknown)
            {
                Console.WriteLine("{0}: Enter a choice (R)ock, (P)aper, (S)cissors, (L)izard, (SP)ock: ", Name);
                string input = Console.ReadLine();

                switch (input.ToUpper())
                {
                case "R":
                    playerChoice.throwChoice = Choice.Rock;
                    break;

                case "P":
                    playerChoice.throwChoice = Choice.Paper;
                    break;

                case "S":
                    playerChoice.throwChoice = Choice.Scissors;
                    break;

                case "L":
                    playerChoice.throwChoice = Choice.Lizard;
                    break;

                case "SP":
                    playerChoice.throwChoice = Choice.Spock;
                    break;

                default:
                    Console.WriteLine("Invalid entry! Please try again!");
                    playerChoice.throwChoice = Choice.Unknown;
                    break;
                }
            }

            return(playerChoice);
        }
        public override ThrowChoice GetChoice()
        {
            ThrowChoice playerChoice = new ThrowChoice();
            playerChoice.throwChoice = Choice.Unknown;

            while (playerChoice.throwChoice == Choice.Unknown)
            {
                Console.WriteLine("{0}: Enter a choice (R)ock, (P)aper, (S)cissors, (L)izard, (SP)ock: ", Name);
                string input = Console.ReadLine();

                switch (input.ToUpper())
                {
                    case "R":
                        playerChoice.throwChoice = Choice.Rock;
                        break;
                    case "P":
                        playerChoice.throwChoice = Choice.Paper;
                        break;
                    case "S":
                        playerChoice.throwChoice = Choice.Scissors;
                        break;
                    case "L":
                        playerChoice.throwChoice = Choice.Lizard;
                        break;
                    case "SP":
                        playerChoice.throwChoice = Choice.Spock;
                        break;
                    default:
                        Console.WriteLine("Invalid entry! Please try again!");
                        playerChoice.throwChoice = Choice.Unknown;
                        break;
                }
            }

            return playerChoice;
        }
示例#5
0
        public int CompareTo(object obj)
        {
            ThrowChoice opponentChoice = obj as ThrowChoice;

            if (opponentChoice != null)
            {
                if (this.throwChoice == Choice.Rock)
                {
                    switch (opponentChoice.throwChoice)
                    {
                    case Choice.Rock:
                        return(0);

                    case Choice.Scissors:
                    case Choice.Lizard:
                        return(1);

                    default:
                        return(-1);
                    }
                }
                else if (this.throwChoice == Choice.Paper)
                {
                    switch (opponentChoice.throwChoice)
                    {
                    case Choice.Paper:
                        return(0);

                    case Choice.Rock:
                    case Choice.Spock:
                        return(1);

                    default:
                        return(-1);
                    }
                }
                else if (this.throwChoice == Choice.Scissors)
                {
                    switch (opponentChoice.throwChoice)
                    {
                    case Choice.Scissors:
                        return(0);

                    case Choice.Paper:
                    case Choice.Lizard:
                        return(1);

                    default:
                        return(-1);
                    }
                }
                else if (this.throwChoice == Choice.Lizard)
                {
                    switch (opponentChoice.throwChoice)
                    {
                    case Choice.Lizard:
                        return(0);

                    case Choice.Paper:
                    case Choice.Spock:
                        return(1);

                    default:
                        return(-1);
                    }
                }
                else if (this.throwChoice == Choice.Spock)
                {
                    switch (opponentChoice.throwChoice)
                    {
                    case Choice.Spock:
                        return(0);

                    case Choice.Rock:
                    case Choice.Scissors:
                        return(1);

                    default:
                        return(-1);
                    }
                }
                else
                {
                    throw new ArgumentException("Object is Unknown.");
                }
            }
            else
            {
                throw new ArgumentException("Object is not a valid Throw Choice.");
            }
        }