Example #1
0
        private void clickManualRoll(object sender, EventArgs e)
        {
            Button dieButton = sender as Button;
            int    dieValue  = DieRegex.findDieValue(dieButton.Name); //get die value from button name

            ManualRoll(dieValue);
        }
Example #2
0
        private (string Total, string[] IndividualRolls) ParseRoll(string rollString)
        {
            int    total          = 0;
            string processingType = "";

            DieRegex.parseRoll(rollString);
            string[] rollTokens = rollString.Split('+', '-');
            string[] indivRolls = new string[rollTokens.Length];
            int      indivIndex = 0;
            int      result;

            foreach (string individualRoll in rollTokens)
            {
                string[] rollValue = individualRoll.Split('d');
                if (rollValue.Length > 1)
                {
                    processingType = "dice roll";
                }
                else
                {
                    processingType = "integer";
                }
                switch (processingType)
                {
                case "dice roll":
                    if (rollValue[0].Contains(" "))
                    {
                        rollValue[0] = rollValue[0].Replace(" ", string.Empty);
                    }
                    if (rollValue[1].Contains(" "))
                    {
                        rollValue[1] = rollValue[1].Replace(" ", string.Empty);
                    }

                    if (!validRolls.Contains(rollValue[1]))
                    {
                        MessageBox.Show(rollValue[1] + " is not a valid die. Please check your roll string", "Roll check", MessageBoxButtons.OK);
                        return(string.Empty, new string[0]);
                    }
                    else
                    {
                        result = RollFunctions.Roll(Convert.ToInt16(rollValue[0]), Convert.ToInt16(rollValue[1]));
                        total += result;
                        indivRolls[indivIndex] = result.ToString();
                        indivIndex++;
                    }
                    break;

                case "integer":
                    result = int.Parse(rollValue[0]);
                    total += result;
                    indivRolls[indivIndex] = result.ToString();
                    indivIndex++;
                    break;
                }
            }
            return(total.ToString(), indivRolls);
        }