Пример #1
0
        private void processDieCommand(string[] sLine)
        {
            bool multiRoll = false;
            bool sum       = false;
            int  sides;
            int  rollCount = 1;

            sLine[0] = sLine[0].Remove(0, 1);
            string[] diceString = sLine[0].Split('*');
            sides = int.Parse(diceString[0]);

            if (diceString.Length == 2)
            {
                rollCount = int.Parse(diceString[1]);
            }

            if (rollCount <= 1)
            {
                rollCount = 1;
            }
            else
            {
                multiRoll = true;
            }


            foreach (string s in sLine)
            {
                if (multiRoll)
                {
                    if (s.Equals("sum") || s.Equals("s"))
                    {
                        sum = true;
                    }
                }
            }

            Die d = new Die(2494);

            if (rollCount == 1)
            {
                printLine("\nD" + sides + " Roll: " + d.roll(sides));
            }
            else if (sum)
            {
                int total = 0;

                printLine("\nD" + sides + " x" + rollCount + ":");
                while (rollCount > 0)
                {
                    int roll = d.roll(sides);
                    total += roll;
                    printLine("           " + roll);
                    rollCount -= 1;
                }

                printLine("\nTotal: " + total);
            }
            else
            {
                printLine("\nD" + sides + " x" + rollCount + ":");
                while (rollCount > 0)
                {
                    printLine("          " + d.roll(sides));
                    rollCount -= 1;
                }
            }
        }