示例#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());
        }