Пример #1
0
        private void DiceGenerator_Shown(object sender, EventArgs e)
        {
            this.Location = new Point(passedTextBoxLoc.X - passedTextBox.Width - 23, passedTextBoxLoc.Y - this.Height + 8);

            if (passedTextBox.Text == "")
            {
                numericUpDown1.Value = 0;
                numericUpDown2.Value = 0;
                numericUpDown3.Value = 0;

                diceStringLabel.Text = "Gold is set to NULL";
                allowGeneration      = true;
            }
            else
            {
                if (Dice.isValidDiceString(passedTextBox.Text))
                {
                    try
                    {
                        int[] result = Dice.parseDiceString(passedTextBox.Text);

                        /*
                         * if (result[1] < 0)
                         * {
                         *  MessageBox.Show("It's not a valid die string! Minimum can't be lower than 0! Setting it to 0!");
                         *  result[1] = 0;
                         * }
                         */


                        if (result[0] > 16)
                        {
                            MessageBox.Show("This dice string will take too many iterations, generating new one!");
                            string res = Dice.generateDiceString(result[1], result[2]);
                            passedTextBox.Text = res;
                            result             = Dice.parseDiceString(res);
                        }

                        numericUpDown1.Value = result[0];
                        numericUpDown2.Value = result[1];
                        numericUpDown3.Value = result[2];

                        diceStringLabel.Text = "Die string: " + passedTextBox.Text;
                        allowGeneration      = true;
                    }
                    catch
                    {
                        MessageBox.Show("Something went wrong while calculating min-max! Generating new dice string!");
                        allowGeneration = true;
                        doGeneration();
                    }
                }
                else
                {
                    MessageBox.Show("It's not a valid dice string, generating new one!");
                    allowGeneration = true;
                    doGeneration();
                }
            }
        }
Пример #2
0
        public static int Roll(string diceString)
        {
            int[] result = Dice.parseDiceString(diceString);
            int   dices  = result[0];
            int   min    = result[1];
            int   max    = result[2];
            int   damage = result[3];
            int   sides  = result[4];

            /*
             * if (dieString == "5d2-4")
             * {
             *  MessageBox.Show(string.Format("dices({0}) min({1}) max({2}) damage({3}) sides({4})", dices, min, max, damage, sides));
             * }
             */


            if (min == max)
            {
                return(min);
            }

            int totalSum = 0;

            for (int i = 1; i <= dices; i++)
            {
                totalSum += getRandom(1, sides);
            }

            totalSum += damage;

            return(totalSum);
        }
Пример #3
0
        private void doGeneration()
        {
            if (allowGeneration)
            {
                string result = Dice.generateDiceString(int.Parse(numericUpDown2.Value.ToString()), int.Parse(numericUpDown3.Value.ToString()));



                if (Dice.isValidDiceString(result))
                {
                    int[] intRes = Dice.parseDiceString(result);

                    numericUpDown1.Value = intRes[0];
                    numericUpDown2.Value = intRes[1];
                    numericUpDown3.Value = intRes[2];

                    passedTextBox.Text = result;

                    diceStringLabel.Text = "Dice string: " + result;
                }
                else
                {
                    if (result.Contains("NULL"))
                    {
                        passedTextBox.Text = "";
                    }
                    diceStringLabel.Text = result;
                }
            }
        }