Exemple #1
0
        public void ProcessResult(Player Player1, Player Player2, MatchResult Result)
        {
            Console.WriteLine("\n\t{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("\n\t{0} Wins!", Player1.Name);
                    history.AddResult(counter,
                        String.Format("{0} picked {1}, {2} picked {3}", Player1.Name,
                        Enum.GetName(typeof(Choice), Result.Player1_Choice),
                        Player2.Name, Enum.GetName(typeof(Choice), Result.Player2_Choice)) +
                        String.Format(", {0} Wins!", Player1.Name));

                    break;
                case Enums.Result.Loss:
                    Console.WriteLine("\n\t{0} Wins!", Player2.Name);
                    history.AddResult(counter,
                        String.Format("{0} picked {1}, {2} picked {3}", Player1.Name,
                        Enum.GetName(typeof(Choice), Result.Player1_Choice),
                        Player2.Name, Enum.GetName(typeof(Choice), Result.Player2_Choice)) +
                        String.Format(", {0} Wins!", Player2.Name));
                    break;
                default:
                    Console.WriteLine("\n\tYou both Tie!");
                    history.AddResult(counter,
                        String.Format("{0} picked {1}, {2} picked {3}", Player1.Name,
                        Enum.GetName(typeof(Choice), Result.Player1_Choice),
                        Player2.Name, Enum.GetName(typeof(Choice), Result.Player2_Choice)) +
                        ", They Tied!");
                    break;
            }
        }
Exemple #2
0
        public Result PlayRound(Player p1, Player p2)
        {
            Console.Clear();
            MatchResult result = new MatchResult();
            result.Player1_Choice = p1.GetChoice();
            result.Player2_Choice = p2.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.Paper && result.Player2_Choice == Choice.Rock) ||
                     (result.Player1_Choice == Choice.Scissors && result.Player2_Choice == Choice.Paper))
            {
                result.Match_Result = Result.Win;
            }

            else
            {
                result.Match_Result = Result.Loss;
            }

            counter++;
            ProcessResult(p1, p2, result);
            history.DisplaysResultsLog();
            return result.Match_Result;
        }
Exemple #3
0
        //Rock, Paper, Scissors, Lizard, Spock
        public MatchResult PlayLizardSpock(Player p1, Player p2)
        {
            MatchResult result = new MatchResult();
            result.Player1_Choice = p1.GetChoice();
            result.Player2_Choice = p2.GetChoice();

            if (result.Player1_Choice == result.Player2_Choice)
            {
                result.Match_Result = Result.Tie;
                GameResults.Add(gameCount, result.Match_Result);

            }
            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.Paper) ||
                     (result.Player1_Choice == Choice.Scissors && result.Player2_Choice == Choice.Lizard) ||
                     (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.Scissors) ||
                     (result.Player1_Choice == Choice.Spock && result.Player2_Choice == Choice.Scissors))

            {
                result.Match_Result = Result.Win;
                GameResults.Add(gameCount, result.Match_Result);

            }
            else
            {
                result.Match_Result = Result.Loss;
                GameResults.Add(gameCount, result.Match_Result);

            }

            ProcessResult(p1, p2, result);
            MatchHistory(GameResults, p1, p2);
            gameCount++;

            return result;
        }
Exemple #4
0
        public void ProcessResult(Player Player1, Player Player2, MatchResult Result)
        {
            Console.WriteLine("\n{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;
                case Enums.Result.Tie:
                    Console.WriteLine("You both Tie!");
                    break;
            }
        }
        /// <summary>
        /// Displays the results of a Match to the User
        /// </summary>
        public void DisplayMatchResult()
        {
            var matchResultMessage = MatchResult.ToString();

            InteractionController.Output(matchResultMessage);
        }
        /// <summary>
        /// Play  method that involves the match playing pipeline, it injects a GameRules instance to use to play the match.
        /// </summary>
        /// <param name="rules"></param>
        /// <returns></returns>
        public override IContestResult Play(IGameRules rules)
        {
            //  Play each Game that needs to be played based on the specified number of rounds: NumRounds
            //  Display Message to User: Commence Match: Match<1>: Commence...
            Controller.Output(CommencementMessage);

            var gameCounter = 0;
            int numGamesLeft;
            int player1Score;
            int player2Score;

            /*Enter Match Loop*/
            do
            {
                //Increment Game counter
                gameCounter++;

                //Initialise a new Game
                var currentGame = new Game(gameCounter, Participants, new List <IMove>(), Controller);

                //Play the current game and capture the game result:
                var currentGameResult = (GameResult)currentGame.Play(rules);

                //Add gameResult to our GameResults collection:
                GameResults.Add(currentGameResult);

                //Display Game Result Message to User:
                Controller.Output(currentGameResult.ToString());

                //If currentGameResult Outcome is a Win
                if (currentGameResult.Outcome == ContestOutcome.Win)
                {
                    //Increment Match Score for the Player of the winning Move:
                    Score.Scores[currentGameResult.WinningMove.Owner]++;
                }

                //Add current game to Rounds collection:
                Rounds.Add(currentGame);

                //Check if the Match is over: Match ENDS When:  Number of games left == 0 OR (Either Players Score) > number of games left

                numGamesLeft = NumRounds - Rounds.Count;      //  number of games left = (Total Number of Games) - (Number games played)
                player1Score = Score.Scores[Participants[0]]; //  Total Number of Games = NumRounds
                player2Score = Score.Scores[Participants[1]]; //  Number games played = Rounds.Count
            } while (!(numGamesLeft == 0 || player1Score > numGamesLeft || player2Score > numGamesLeft));

            //Determine the Outcome and Winner of the Match
            if (player1Score == player2Score)
            {
                Outcome = ContestOutcome.Draw;
            }
            else
            {
                Outcome = ContestOutcome.Win;
                Winner  = player1Score > player2Score ? Participants[0] : Participants[1];
            }

            //Initialize the Match Result
            var matchResult = new MatchResult(Id, Winner, Score, Participants, Outcome);

            //Return the Match Result
            return(matchResult);
        }