// Paquet reçu private async void PacketReceived(object sender, NXTPacketReceivedEventArgs e) { UpdateBuffer(iaVehicule.Buffer); if (CoopEnabled) { if (!iaCoop.ComputeMove()) { iaVehicule.SendNextAction(radioButton1.Checked); remoteVehicule.SendNextAction(radioButton1.Checked); if (radioButton1.Checked) { await Task.Delay((int)numericUpDown1.Value); PacketReceived(sender, e); } } } else { Console.WriteLine("Réponse reçue ! (Autonome)"); if (button1.Text == "Pause") { if (!iaVehicule.SendNextAction(radioButton1.Checked)) { await Task.Delay(TimeSpan.FromMilliseconds((int)numericUpDown1.Value)); if (simulation1.CalculatePath()) { UpdateBuffer(iaVehicule.Buffer); if (radioButton1.Checked) { await Task.Delay(TimeSpan.FromMilliseconds((int)numericUpDown1.Value)); } PacketReceived(sender, e); } else { iaVehicule.Circuit.FillColor(Microsoft.Xna.Framework.Color.White); ButtonDisable(); } } else { if (radioButton1.Checked) { await Task.Delay(TimeSpan.FromMilliseconds((int)numericUpDown1.Value)); PacketReceived(sender, e); } else { iaVehicule.NxtHelper.WaitForData(new EventHandler <NXTPacketReceivedEventArgs>(PacketReceived)); } } } } }
// -------------------------------------------------------------------------- // EVENTS / ASYNC CALLS // -------------------------------------------------------------------------- // Bouton "Lancer"/"Pause" private void Button10_Click(object sender, EventArgs e) { UpdateBuffer(vehicule.Buffer); if (button10.Text == "Pause") { button10.Text = "Lancer"; } else { vehicule.SendNextAction(checkBox2.Checked); if (checkBox2.Checked) { PacketReceived(this, new NXTPacketReceivedEventArgs(new byte[] { })); } else { vehicule.NxtHelper.WaitForData(new EventHandler <NXTPacketReceivedEventArgs>(PacketReceived)); } button10.Text = "Pause"; } }