From 1e8d685ad632aea5fce47db8611ca893a59cdc6a Mon Sep 17 00:00:00 2001 From: Awale Date: Sun, 23 Jan 2022 20:53:03 +0100 Subject: [PATCH] =?UTF-8?q?il=20faut=20que=20j'arr=C3=AAte=20le=20thread?= =?UTF-8?q?=20d'une=20methode=20lors=20du=20bouton=20stop(simulation)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cavalier_Euler/Form2.Designer.cs | 1 + Cavalier_Euler/Form2.cs | 104 +++++++++++++++++++++++++------ 2 files changed, 86 insertions(+), 19 deletions(-) diff --git a/Cavalier_Euler/Form2.Designer.cs b/Cavalier_Euler/Form2.Designer.cs index 0995155..422f7e0 100644 --- a/Cavalier_Euler/Form2.Designer.cs +++ b/Cavalier_Euler/Form2.Designer.cs @@ -76,6 +76,7 @@ private void InitializeComponent() this.listBox1.Size = new System.Drawing.Size(120, 95); this.listBox1.TabIndex = 4; this.listBox1.Visible = false; + this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); // // listBox2 // diff --git a/Cavalier_Euler/Form2.cs b/Cavalier_Euler/Form2.cs index b89789e..44b504a 100644 --- a/Cavalier_Euler/Form2.cs +++ b/Cavalier_Euler/Form2.cs @@ -26,6 +26,7 @@ public partial class Form2 : Form int position; int fuiteMin; int fuiteMinIndex; + Timer timer; public Form2() { @@ -63,6 +64,7 @@ public Form2() } fuiteMin = 0; fuiteMinIndex = 0; + timer = new System.Windows.Forms.Timer(); } @@ -87,19 +89,12 @@ private void button1_Click(object sender, EventArgs e) testPositionAvailable(); coups.Add(position); - Button buttonGo = new Button(); - buttonGo.Text = "Go"; - buttonGo.Location = new System.Drawing.Point(600, 300); - buttonGo.Name = "buttonGo"; - buttonGo.Size = new System.Drawing.Size(60, 60); - buttonGo.UseVisualStyleBackColor = true; - buttonGo.Click += new System.EventHandler(this.buttonGo_Click); - buttonGo.Visible = true; - this.Controls.Add(buttonGo); + goAndStopButton(); } } + private void button1_Click_1(object sender, EventArgs e) { label1.Text = "Veuillez cliquer sur la case ou vous souhaitez commencer"; @@ -136,8 +131,14 @@ private void button2_Click(object sender, EventArgs e) button1.Visible = false; button2.Visible = false; listBox1.Visible = true; - listBox2.Visible = true; + listBox2.Visible = false; + + goAndStopButton(); + + } + private void goAndStopButton() + { Button buttonGo = new Button(); buttonGo.Text = "Go"; buttonGo.Location = new System.Drawing.Point(600, 300); @@ -148,24 +149,79 @@ private void button2_Click(object sender, EventArgs e) buttonGo.Visible = true; this.Controls.Add(buttonGo); + Button buttonStop = new Button(); + buttonStop.Text = "Stop"; + buttonStop.Location = new System.Drawing.Point(800, 300); + buttonStop.Name = "buttonStop"; + buttonStop.Size = new System.Drawing.Size(60, 60); + buttonStop.UseVisualStyleBackColor = true; + buttonStop.Click += new System.EventHandler(this.buttonStop_Click); + buttonStop.Visible = false; + this.Controls.Add(buttonStop); } - private void buttonGo_Click(object sender, EventArgs e) + private void buttonStop_Click(object sender, EventArgs e) { - if (listBox1.SelectedItem == null || listBox2.SelectedItem == null) - return; - label1.Text = "sa marche !!!!!"; - string type = listBox1.SelectedItem.ToString(); - string time = listBox2.SelectedItem.ToString(); + Control [] buttonGo = this.Controls.Find("buttonGo", false); + buttonGo[0].Enabled = true; + Button myButton = (Button)sender; + myButton.Visible = false; + + // la je veux stopper la fonction buttonGo_Click, mais je sais pas comment , un truc avec stop Thread surement + } + + async private void buttonGo_Click(object sender, EventArgs e) + { + Control[] buttonGo = this.Controls.Find("buttonGo", false); + Control[] buttonStop = this.Controls.Find("buttonStop", false); + + string type = ""; + string time = ""; + if (listBox1.SelectedItem == null) + return; + type = listBox1.SelectedItem.ToString(); + if (listBox1.SelectedIndex == 2) + { + if (listBox2.SelectedItem == null) + return; + time = listBox2.SelectedItem.ToString(); + } + + if(type == "pas-a-pas") { - Task.Delay(20000000); - label1.Text = "omggggggggggggg"; + label1.Text = "c'est le " + compteur + " coup(s) !"; algoEuler(); } - } + else if(type == "pas-de-5") + { + for (int i = 0; i < 5; ++i) + algoEuler(); + label1.Text = "c'est le " + compteur + " coup(s) !"; + + } + else if (type == "Itinéraire-non-stop") + { + buttonStop[0].Visible = true; + buttonGo[0].Enabled = false; + for (int i = 0; i < grille.Length; ++i) + { + algoEuler(); + if (time == "1s") + { + await Task.Delay(1000); + //System.Threading.Thread.Sleep(1000); + } + else if (time == "3s") + await Task.Delay(3000); + else if (time == "5s") + await Task.Delay(5000); + label1.Text = "c'est le " + compteur + " coup(s) !"; + } + } + } private int getIndiceButton(Button bp) { @@ -312,6 +368,16 @@ private void jouerButton(int buttonP) return; } + + private void listBox1_SelectedIndexChanged(object sender, EventArgs e) + { + ListBox myListBox = (ListBox)sender; + if (myListBox.SelectedIndex == 2) + listBox2.Visible = true; + else + listBox2.Visible = false; + + } } }