Пример #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
        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;
                }
            }
        }