コード例 #1
0
        public int Play(IMatchParameters matchParameters)
        {
            if (matchParameters == null)
            {
                throw new ArgumentNullException(nameof(matchParameters));
            }

            while (true)
            {
                GameOutcome result = null;

                switch (matchParameters.GetRandomScorer())
                {
                case 1:
                    result = _score.UpdateScore(_player1Id);
                    break;

                case 2:
                    result = _score.UpdateScore(_player2Id);
                    break;

                default:
                    throw new InvalidOperationException("Invalid scorer.");
                }

                if (result != null)
                {
                    return(result.GetWinner());
                }
            }
        }
コード例 #2
0
ファイル: Score.cs プロジェクト: dylsmith8/tennissim
        public GameOutcome UpdateScore(int scorer)
        {
            if (scorer == 1)
            {
                Player1Score = UpdateScore(Player1Score);
            }
            else
            {
                Player2Score = UpdateScore(Player2Score);
            }

            Tuple <Enums.GameOutcome, int> roundResult = DetermineGameOutcome();

            GameOutcome outcome = null;

            if (roundResult != null && roundResult.Item1 == Enums.GameOutcome.Win)
            {
                outcome = new GameOutcome(roundResult.Item2);
                ResetScores();
            }

            return(outcome);
        }