private void startAlgorithm(object sender, EventArgs e) { change_enabled_setting(); //Toggle controls AlgorithmManager.StartAlgorithm(); FormsHandler.LoadAndDisplayState(AlgorithmManager.GetCurrentState()); }
private void restartAlgorithm_buttonClick(object sender, EventArgs e) { FormsHandler.loadedState = AlgorithmManager.GetCurrentState(); AlgorithmManager.EraseBoard(); FormsHandler.ResetConfiguration(); //Clear comboboxes and other forms change_enabled_setting(); //Togle controls }
//Advance algorithm button async private void buttonAdvancestepsdropdownClick(object sender, EventArgs e) { FormsHandler.halted = false; int stepsToTake = Int32.Parse(comboboxAdvancesteps.Text); int episodes = Int32.Parse(comboboxAdvanceepisodes.Text); if (episodes > 0) { stepsToTake += (Int32.Parse(comboboxAdvanceepisodes.Text) * FormsHandler.loadedState.GetStepLimit()) + 1; //+1 to get the new episode generated } int initial_delay = Int32.Parse(comboboxDelayms.Text); int delay = initial_delay; if (checkBox1.Checked) { FormsHandler.hasUrlStartedChasing = true; } if (FormsHandler.hasUrlStartedChasing) { while (FormsHandler.hasUrlStartedChasing) { AlgorithmManager.StepPrepare(); } FormsHandler.LoadAndDisplayState(AlgorithmManager.GetCurrentState()); } else if (stepsToTake > 1) { textboxProgresssteps.Text = stepsToTake.ToString(); groupboxCountdown.Enabled = true; groupboxAlgorithmprogress.Enabled = false; groupboxHistory.Enabled = false; while (stepsToTake-- > 0 && !FormsHandler.halted) { AlgorithmManager.StepPrepare(); FormsHandler.LoadAndDisplayState(AlgorithmManager.GetCurrentState()); textboxProgresssteps.Text = stepsToTake.ToString(); do { await Task.Delay(1); textboxCountdown.Text = delay.ToString(); } while (--delay > 0 && !FormsHandler.halted); delay = initial_delay; } groupboxAlgorithmprogress.Enabled = true; groupboxCountdown.Enabled = false; groupboxHistory.Enabled = true; } else { AlgorithmManager.StepPrepare(); FormsHandler.LoadAndDisplayState(AlgorithmManager.GetCurrentState()); } }
private void Form1Load(object sender, EventArgs e) { AlgorithmManager.SetDefaultConfiguration(); //Second entry point of the program. //When the form loads, we'll create some pictureboxes, that will function as the robot world grid. FormsHandler.load(); PictureBox picturebox_inProgress; //Temporary picturebox SquareBoardDisplay squareTo_build; //This is object inherits from boardSquare, but has a picture element. //Create pictureboxes and pass them to our board for (int i = 0; i < InitialSettings.SizeOfBoard; i++) { for (int j = 0; j < InitialSettings.SizeOfBoard; j++) { //Fill in the column with rows picturebox_inProgress = new PictureBox(); squareTo_build = new SquareBoardDisplay(i, j); picturebox_inProgress.Name = i.ToString() + "-" + j.ToString(); //Each name is the coordinate picturebox_inProgress.Location = new Point(InitialSettings.X_Offset + (i * InitialSettings.EdgeLength), InitialSettings.Y_Offset + (j * InitialSettings.EdgeLength)); picturebox_inProgress.Size = new Size(InitialSettings.EdgeLength, InitialSettings.EdgeLength); picturebox_inProgress.SizeMode = PictureBoxSizeMode.StretchImage; picturebox_inProgress.BackgroundImageLayout = ImageLayout.Stretch; Controls.Add(picturebox_inProgress); squareTo_build.pictureData = picturebox_inProgress; FormsHandler.Add(i, 9 - j, squareTo_build); //9-j to handle the board layout, for some reason! } } //Called from the restart button, but works here on initial launch. //This triggers the constructor for algorithm manager, as well textboxStatus.Text = "Program launched."; FormsHandler.DisplayState(); //First time we display the board. }