Пример #1
0
        private string FormatSingleDiceGroupRoll(DiceGroupRollResult result, int groupIndex)
        {
            var firstDiceRollResult = result.DiceResults.First();
            var linePrefix          = $"Одиночная кость #{groupIndex}";

            return(FormatSingleDiceRoll(firstDiceRollResult, linePrefix));
        }
Пример #2
0
        private string FormatDiceGroupRoll(DiceGroupRollResult rollResult, int groupIndex)
        {
            string result;

            if (rollResult.DiceResults.Count > 1)
            {
                result = FormatMultiDiceGroupRoll(rollResult, groupIndex);
            }
            else
            {
                result = FormatSingleDiceGroupRoll(rollResult, groupIndex);
            }

            return(result);
        }
Пример #3
0
        public DiceGroupRollResult RollDiceGroup(DiceGroup diceGroup)
        {
            var result = new DiceGroupRollResult();

            foreach (var dice in diceGroup.Dice)
            {
                var rollResult = RollSingleDice(dice);

                result.MaxSum += rollResult.MaxResult;
                result.Sum    += rollResult.Result;

                result.DiceResults.Add(rollResult);
            }

            return(result);
        }
Пример #4
0
        private string FormatDiceGroupContents(DiceGroupRollResult groupRollResult)
        {
            var diceCountBySideCount = new Dictionary <int, int>();

            foreach (var rollResult in groupRollResult.DiceResults)
            {
                var currentSideCount = rollResult.MaxResult;

                if (diceCountBySideCount.TryGetValue(currentSideCount, out var diceCount))
                {
                    diceCountBySideCount[currentSideCount] = diceCount + 1;
                }
                else
                {
                    diceCountBySideCount.Add(currentSideCount, 1);
                }
            }

            var formattedDice = diceCountBySideCount.Select(x => x.Value == 1 ? $"d{x.Key}" : $"{x.Value}d{x.Key}");

            return(string.Join("+", formattedDice));
        }
Пример #5
0
        private string FormatMultiDiceGroupRoll(DiceGroupRollResult result, int groupIndex)
        {
            var stringBuilder = new StringBuilder();

            var groupContents = FormatDiceGroupContents(result);

            stringBuilder.AppendLine($"Группа #{groupIndex} ({groupContents}):");

            var diceIndex = 1;

            foreach (var diceResult in result.DiceResults)
            {
                var linePrefix        = $"Кость #{diceIndex++}";
                var formattedDiceRoll = FormatSingleDiceRoll(diceResult, linePrefix);

                stringBuilder.AppendLine(formattedDiceRoll);
            }

            stringBuilder.AppendLine($"Сумма: {result.Sum} / {result.MaxSum}");

            return(stringBuilder.ToString());
        }