示例#1
0
文件: Game.cs 项目: thombeau/RPSCode
        public Result PlayRound(Player player1, Player player2)
        {
            MatchResult result = new MatchResult();
            result.Player1_Choice = player1.GetChoice();
            result.Player2_Choice = player2.GetChoice();

            if (result.Player1_Choice == result.Player2_Choice)
            {
                result.Match_Result = Result.Tie;
            }
            else if ((result.Player1_Choice == Choice.Rock && result.Player2_Choice == Choice.Scissors) ||
                     (result.Player1_Choice == Choice.Rock && result.Player2_Choice == Choice.Lizard) ||
                     (result.Player1_Choice == Choice.Paper && result.Player2_Choice == Choice.Rock) ||
                     (result.Player1_Choice == Choice.Paper && result.Player2_Choice == Choice.Spock) ||
                     (result.Player1_Choice == Choice.Scissors && result.Player2_Choice == Choice.Lizard) ||
                     (result.Player1_Choice == Choice.Scissors && result.Player2_Choice == Choice.Paper) ||
                     (result.Player1_Choice == Choice.Lizard && result.Player2_Choice == Choice.Spock) ||
                     (result.Player1_Choice == Choice.Lizard && result.Player2_Choice == Choice.Paper) ||
                     (result.Player1_Choice == Choice.Spock && result.Player2_Choice == Choice.Rock) ||
                     (result.Player1_Choice == Choice.Spock && result.Player2_Choice == Choice.Scissors))

            {
                result.Match_Result = Result.Win;
            }
            else
            {
                result.Match_Result = Result.Loss;
            }

            ProcessResult(player1, player2, result);

            return result.Match_Result;
        }
示例#2
0
文件: Game.cs 项目: thombeau/RPSCode
        public void ProcessResult(Player Player1, Player Player2, MatchResult Result)
        {
            Console.WriteLine("{0} picked {1}, {2} picked {3}", Player1.Name,
                Enum.GetName(typeof (Choice), Result.Player1_Choice),
                Player2.Name, Enum.GetName(typeof (Choice), Result.Player2_Choice));

            switch (Result.Match_Result)
            {
                case Enums.Result.Win:
                    Console.WriteLine("{0} Wins!", Player1.Name);
                    break;
                case Enums.Result.Loss:
                    Console.WriteLine("{0} Wins!", Player2.Name);
                    break;
                default:
                    Console.WriteLine("You both tied!");
                    break;

            }
        }