Ejemplo n.º 1
0
        private void RunAlgorithmButton_Click(object sender, EventArgs e)
        {
            Button button = RunAlgorithmButton;

            if (button.Tag == null || button.Tag.ToString() == "play")
            {
                ExecTimer.Start();
                button.Image = Properties.Resources.pause;
                button.Tag   = "pause";
            }
            else if (button.Tag.ToString() == "pause")
            {
                ExecTimer.Stop();
                button.Image = Properties.Resources.play;
                button.Tag   = "play";
            }
            else if (button.Tag.ToString() == "restart")
            {
                ExecTimer.Stop();
                button.Image = Properties.Resources.play;
                StateBuffer.Seek(0, SeekOrigin.Begin);
                currentState = (State)fileFormat.Deserialize(StateBuffer);
                UpdateTable();
                InputUpdate();
                CurrentStepLabel.Text = $"Шаг: {currentState.Step}/{currentState.TotalSteps}";
                HighlightCurrentStep();
                button.Tag             = "play";
                CurrentStateLabel.Text = "Нажмите \"Запуск\", чтобы начать исполнение.";
            }
        }
Ejemplo n.º 2
0
        private void NextStep()
        {
            int oldInstructionId, oldItemId;

            try
            {
                char        oldSym         = currentState.Data.Current == '_' ? '\0' : currentState.Data.Current;
                Instruction oldInstruction = GetActiveInstruction();
                oldInstructionId = Array.IndexOf(currentState.Instructions, oldInstruction);
                Operation oldItem = oldInstruction.Operations.Single(i => i.OldChar == oldSym);
                oldItemId = oldInstruction.Operations.IndexOf(oldItem);
                if (currentState.Step == currentState.TotalSteps)
                {
                }
                else
                {
                    string dir = oldItem.Direction == Direction.LEFT ? " и сдвинула курсор влево" : oldItem.Direction == Direction.RIGHT ? " и сдвинула курсор вправо" : "";
                    CurrentStateLabel.Text = $"Инструкция `{oldItem}` заменила символ `{oldSym}` на `{oldItem.NewChar}`{dir}.";
                }
                currentState = (State)fileFormat.Deserialize(StateBuffer);
            }
            catch (Exception)
            {
                ExecTimer.Stop();
                MessageBox.Show("Алгоритм завершился, перезапустите его.", "Невозможно продолжить", MessageBoxButtons.OK, MessageBoxIcon.Information);
                RunAlgorithmButton.Image = Properties.Resources.restart;
                RunAlgorithmButton.Tag   = "restart";
                return;
            }
            if (currentState.Step == currentState.TotalSteps)
            {
                CurrentStateLabel.Text   = "Выполнение завершено, необходим перезапуск.";
                RunAlgorithmButton.Image = Properties.Resources.restart;
                RunAlgorithmButton.Tag   = "restart";
                InputUpdate(currentState.Data.CurrentPosition);
                ExecTimer.Stop();
            }
            else
            {
                if (!ExecTimer.Enabled)
                {
                    RunAlgorithmButton.Image = Properties.Resources.play;
                    RunAlgorithmButton.Tag   = "play";
                }
                try
                {
                    currentState.SaveToFile("saved.emt");
                }
                catch (Exception) { }
                InputUpdate(currentState.Data.PreviousPosition);
            }
            UpdateTable(oldInstructionId, oldItemId + 1);
            CurrentStepLabel.Text = $"Шаг: {currentState.Step}/{currentState.TotalSteps}";
            HighlightCurrentStep();
        }