예제 #1
0
        public void CannotLockInScoreThatIsNotPartOfTheUpperSection()
        {
            var section = new UpperSection(x => 1, x => 2, x => 3, x => 4, x => 5, x => 6);

            section.Preview(new List <int>());

            Assert.Throws <Exception>(() => section.Lock(ScoreCard.Items.ThreeOfAKind));
        }
예제 #2
0
        public void ReturnsBonusWhenUpperSectionSumIsEqualToSixtyThree()
        {
            var section = new UpperSection(x => 63, x => 2, x => 3, x => 4, x => 5, x => 6);

            section.Preview(new List <int>());
            section.Lock(ScoreCard.Items.Ones);

            Assert.Equal(35, section.Bonus);
        }
예제 #3
0
        public void ReturnsScoreIncludingBonus()
        {
            var section = new UpperSection(x => 1, x => 2, x => 3, x => 4, x => 5, x => 63);

            section.Preview(new List <int>());
            section.Lock(ScoreCard.Items.Sixes);
            section.Preview(new List <int>());

            Assert.Equal(63 + 35, section.Score);
        }
예제 #4
0
        public void ReturnsScore()
        {
            var section = new UpperSection(x => 1, x => 2, x => 3, x => 4, x => 5, x => 6);

            section.Preview(new List <int>());
            section.Lock(ScoreCard.Items.Sixes);
            section.Preview(new List <int>());
            section.Lock(ScoreCard.Items.Fours);
            section.Preview(new List <int>());

            Assert.Equal(10, section.Score);
        }
예제 #5
0
        public void PreviewsTheScoreForSetOfDice()
        {
            var section = new UpperSection(x => 1, x => 2, x => 3, x => 4, x => 5, x => 6);

            section.Preview(new List <int>());
            Assert.Equal(1, section.Ones);
            Assert.Equal(2, section.Twos);
            Assert.Equal(3, section.Threes);
            Assert.Equal(4, section.Fours);
            Assert.Equal(5, section.Fives);
            Assert.Equal(6, section.Sixes);
        }
예제 #6
0
        public void LockInFivesScore()
        {
            var section = new UpperSection(x => 1, x => 2, x => 3, x => 4, x => 5, x => 6);

            section.Preview(new List <int>());
            section.Lock(ScoreCard.Items.Fives);

            Assert.Equal(0, section.Ones);
            Assert.Equal(0, section.Twos);
            Assert.Equal(0, section.Threes);
            Assert.Equal(0, section.Fours);
            Assert.Equal(5, section.Fives);
            Assert.Equal(0, section.Sixes);
        }
예제 #7
0
        public static int ScoreUpper(UpperSection section, Hand hand)
        {
            int        score      = 0;
            List <int> playerHand = hand.GetDiceList();

            switch (section)
            {
            case UpperSection.threeofakind:
                score = ScoreThreeOfAKind(playerHand);
                break;

            case UpperSection.fourofakind:
                score = ScoreFourOfAKind(playerHand);
                break;

            case UpperSection.fullhouse:
                score = ScoreFullHouse(playerHand);
                break;

            case UpperSection.smallstraight:
                score = ScoreSmallStraight(playerHand);
                break;

            case UpperSection.largestraight:
                score = ScoreLargeStraight(playerHand);
                break;

            case UpperSection.yahtzee:
                score = ScoreYahtzee(playerHand);
                break;

            case UpperSection.chance:
                score = ScoreChance(playerHand);
                break;

            default:
                Console.WriteLine("Invalid scoring option");
                break;
            }

            return(score);
        }
예제 #8
0
        public static int ScoreHand(string section, Hand hand)
        {
            section = section.ToLower();

            if (Enum.IsDefined(typeof(LowerSection), section))
            {
                int diceValue = (int)Enum.Parse(typeof(LowerSection), section);
                return(ScoreLower(diceValue, hand));
            }
            else if (Enum.IsDefined(typeof(UpperSection), section))
            {
                UpperSection scoringSection = (UpperSection)Enum.Parse(typeof(UpperSection), section);
                return(ScoreUpper(scoringSection, hand));
            }
            else
            {
                Console.WriteLine("INVALID SCORE CATEGORY");
                return(0);
            }
        }
예제 #9
0
        public static IDictionary <string, int> ScoreFullCard(Hand hand)
        {
            IDictionary <string, int> ScoreCard = new Dictionary <string, int>()
            {
            };

            foreach (var val in LowerSection.GetValues(typeof(LowerSection)))
            {
                string section = val.ToString();
                ScoreCard[section] = Score.ScoreHand(section, hand);
            }

            foreach (var val in UpperSection.GetValues(typeof(UpperSection)))
            {
                string section = val.ToString();
                ScoreCard[section] = Score.ScoreHand(section, hand);
            }

            return(ScoreCard);
        }
예제 #10
0
        public void ReturnsBonusOfZeroWhenUpperSectionSumIsUnderSixtyThree()
        {
            var section = new UpperSection(x => 1, x => 2, x => 3, x => 4, x => 5, x => 6);

            Assert.Equal(0, section.Bonus);
        }