예제 #1
0
        private void установитьЗначенияМашиныToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!(UIController is null) && !(UIController.Turing is null))
            {
                UIController.Turing.StopWork();
            }
            SettingsTuringForm settingsForm = new SettingsTuringForm();

            if (settingsForm.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var settings = settingsForm.GetSettings();
                    SettingsTuringDefault tSettings = settings;
                    if (tSettings is null)
                    {
                        throw new NullReferenceException();
                    }
                    UIController.SetSettings(tSettings);
                    ShowTuringInterface();
                }
                catch (NullReferenceException)
                {
                    return;
                }
            }
            if (!(UIController is null) && !(UIController.Turing is null))
            {
                UIController.Turing.ContinueWork();
            }
        }
예제 #2
0
 public void SetSettings(SettingsTuringDefault settings)
 {
     Settings = settings ?? throw new ArgumentNullException(nameof(settings));
     Turing   = new Turing(Settings)
     {
         Milliseconds = FormSettings.Milliseconds
     };
     UpdateSettings();
 }
예제 #3
0
        public SettingsTuringDefault GetSettings()
        {
            HashSet <char> alph = alphabetTB.Text.ToHashSet();
            //if (startPositionNUD.Value > maxNUD.Value || startPositionNUD.Value < minNUD.Value)
            //{
            //    MessageBox.Show("Начальная позиция вне границ ленты!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return null;
            //}
            SettingsTuringDefault settings = new SettingsTuringDefault(alph, (int)maxNUD.Value, (int)minNUD.Value, (int)countStateNUD.Value, (int)startPositionNUD.Value, defaultWordTB.Text);

            return(settings);
        }
예제 #4
0
        private void Settings_Load(object sender, EventArgs e)
        {
            SettingsTuringDefault settingsTuringDefault = new SettingsTuringDefault(new HashSet <char>());

            UIController.Instance.Controls.AddRange(new List <Control>()
            {
                label1, label2, label3, label4, label5, label6, alphabetTB, defaultWordTB
            });
            UIController.Instance.UpdateControls();
            minNUD.Value           = settingsTuringDefault.minValueTape;
            maxNUD.Value           = settingsTuringDefault.maxValueTape;
            countStateNUD.Value    = settingsTuringDefault.countState;
            startPositionNUD.Value = maxNUD.Value - (Math.Abs(minNUD.Value) + Math.Abs(maxNUD.Value)) / 2;
        }
예제 #5
0
        private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                using (StreamReader reader = new StreamReader(openFileDialog1.FileName, Encoding.Default))
                {
                    if (reader.ReadLine() == "<Table>")
                    {
                        var    count   = GetIntFromFile(reader.ReadLine().Trim('\t', '\0'));
                        var    max     = GetIntFromFile(reader.ReadLine().Trim('\t', '\0'));
                        var    min     = GetIntFromFile(reader.ReadLine().Trim('\t', '\0'));
                        var    wordDef = GetStringFromFile(reader.ReadLine().Trim('\t', '\0'));
                        var    start   = GetIntFromFile(reader.ReadLine().Trim('\t', '\0'));
                        string alp     = GetStringFromFile(reader.ReadLine().Trim('\t', '\0'));

                        SettingsTuringDefault settingsTuringDefault = new SettingsTuringDefault(new HashSet <char>(alp), countState: count - 1, minValueTape: min,
                                                                                                maxValueTape: max, wordDefault: wordDef, startPosition: start);

                        var currentString = "";
                        int row           = 1;
                        UIController.SetSettings(settingsTuringDefault);
                        while (currentString.Trim('\t', '\0') != "</Table>")
                        {
                            currentString = reader.ReadLine();
                            string[] commandsRow = currentString.Split('\t', '\0');
                            for (int i = 1; i <= commandsRow.Length; i++)
                            {
                                if (Command.TryParse(commandsRow[i - 1], out var command))
                                {
                                    UIController.Turing.AddCommand(i - 1, row, command);
                                }
                            }
                            row++;
                        }
                        ShowTuringInterface();
                        Description.Text = GetStringFromFile(reader.ReadToEnd());
                        //GetTuringCommandToTable();
                    }
                }
            }
        }