public void ShouldReturnACalculatorBasedOnEnum(ScoreCategory a_scoreCategory, Type a_type)
        {
            sut = new ScoreCalculatorFactory();
            IScoreCalculator actual = sut.GetScoreCalculator(a_scoreCategory);

            Assert.True(actual.GetType() == a_type);
        }
Exemple #2
0
        public void YatzyCategoryTest()
        {
            var scoreCard = new ScoreCard();

            var score = ScoreCalculatorFactory.CreateCalculator(scoreCard.CategoryScoreCard.First(category => category.CategoryKey == "o"), new List <Die>
            {
                new Die {
                    Value = 1
                },
                new Die {
                    Value = 1
                },
                new Die {
                    Value = 1
                },
                new Die {
                    Value = 1
                },
                new Die {
                    Value = 1
                }
            }).Calculate();

            Assert.Equal(50, score);
        }
Exemple #3
0
        public void GameShouldScoreIfResponseIsScoreInCategory(string input, int expected, int a, int b, int c, int d, int e)
        {
            var scoreCard = new ScoreCard();

            var score = ScoreCalculatorFactory.CreateCalculator(scoreCard.CategoryScoreCard.First(category => category.CategoryKey == input.ToLower()), new List <Die>
            {
                new Die {
                    Value = a
                },
                new Die {
                    Value = b
                },
                new Die {
                    Value = c
                },
                new Die {
                    Value = d
                },
                new Die {
                    Value = e
                }
            }).Calculate();

            Assert.Equal(expected, score);
        }
        public void ShouldThrowExceptionIfGivenIllegalScoreCategory()
        {
            sut = new ScoreCalculatorFactory();

            Assert.Throws <ArgumentException>(delegate()
            {
                var actual = sut.GetScoreCalculator(ScoreCategory.Illegal);
            });
        }
Exemple #5
0
        public static void DisplayCategories(ScoreCard scoreCard, List <Die> diceCup)
        {
            Console.Write("Categories:\n");
            foreach (var category in scoreCard.CategoryScoreCard)
            {
                if (category.IsUsed)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(category.ToString());
                    Console.ResetColor();
                }
                else
                {
                    Console.WriteLine(
                        $"{category.CategoryKey}) {category.CategoryName}: {ScoreCalculatorFactory.CreateCalculator(category, diceCup).Calculate()}");
                }
            }

            Console.Write("\n");
        }
Exemple #6
0
        private void ScoreForChosenCategory(Response response)
        {
            var chosenCategory = _scoreCard.CheckIfCategoryUsed(response);

            if (chosenCategory.IsUsed)
            {
                response.ResponseType = ResponseType.InvalidResponse;
            }
            else
            {
                chosenCategory.CategoryScore = ScoreCalculatorFactory.CreateCalculator(chosenCategory, DiceCup).Calculate();
                chosenCategory.IsUsed        = true;
                if (!_scoreCard.CategoryScoreCard.All(category => category.IsUsed))
                {
                    return;
                }
                Display.FinishedGame(_scoreCard);
                IsPlayingGame = false;
            }
        }