Ejemplo n.º 1
0
        private void GenBtn_Click(object sender, EventArgs e)
        {
            try
            {
                tick = 0;
                h    = 0;
                m    = 0;

                Timer.Enabled = true;

                int CountOT = 1;

                if (!int.TryParse(CBCount.Text, out CountOT))
                {
                    CountOT = 1;
                }


                EndGameRB.Clear();

                Key         key  = new Key();
                ConvertRule Rule = new ConvertRule(SimpleTrig);

                int intKeyGen = -1;

                if (int.TryParse(KeyGenTB.Text, out intKeyGen) && intKeyGen != -1)
                {
                    File.WriteAllText(path, "");
                    int   KGLength = intKeyGen.ToString().Length;
                    int[] mas      = new int[KGLength];
                    for (int i = 0; i < KGLength; i++)
                    {
                        mas[i]    = (intKeyGen % 10 % 6);
                        intKeyGen = intKeyGen / 10;
                    }
                    for (int i = 0; i < KGLength; i++)
                    {
                        switch (mas[i])
                        {
                        case 0:
                            Rule = SimpleTrig;
                            key.KeyGen(i, Rule);
                            break;

                        case 1:
                            Rule = MiddleTrig1;
                            key.KeyGen(i, Rule);
                            break;

                        case 2:
                            Rule = MiddleTrig2;
                            key.KeyGen(i, Rule);
                            break;

                        case 3:
                            Rule = MiddleTrig3;
                            key.KeyGen(i, Rule);
                            break;

                        case 4:
                            Rule = MiddleTrig4;
                            key.KeyGen(i, Rule);
                            break;

                        case 5:
                            Rule = MiddleTrig5;
                            key.KeyGen(i, Rule);
                            break;
                        }
                    }
                    ToHtml();
                    if (WebCheckBox.Checked == true)
                    {
                        Process.Start("ST.html");
                    }
                }
                else
                {
                    File.WriteAllText(path, "");
                    for (int i = 0; i < CountOT; i++)
                    {
                        int another = rnd.Next(1, 7);
                        if (another == 1)
                        {
                            SimpleTrig(i);
                        }
                        if (another == 2)
                        {
                            MiddleTrig1(i);
                        }
                        if (another == 3)
                        {
                            MiddleTrig2(i);
                        }
                        if (another == 4)
                        {
                            MiddleTrig3(i);
                        }
                        if (another == 5)
                        {
                            MiddleTrig4(i);
                        }
                        if (another == 6)
                        {
                            MiddleTrig5(i);
                        }
                    }
                    ToHtml();
                    if (WebCheckBox.Checked == true)
                    {
                        Process.Start("ST.html");
                    }
                }
            }
            catch (IOException ioex)
            {
                MessageBox.Show("Something wrong with files!\n" + ioex.ToString());
            }
            catch (UnauthorizedAccessException unex)
            {
                MessageBox.Show(unex.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }