//########################################################################## //########################### EVENTOS ############################### //########################################################################## //evento de finalizar simulación al clickear el botón finalizar simulación private void btFinalizarSim_Click(object sender, EventArgs e) { BWprSimulacion.CancelAsync(); BWprJubilacion.CancelAsync(); BWprMensaje.CancelAsync(); BWescudo.CancelAsync(); BWeligeCasillas.CancelAsync(); finalizarSimulacion(); mItFinalizar.Enabled = false; }
//Acciones que realiza el programa al iniciar la interfaz gráfica private void PuenteDeMandoGUI_Load(object sender, EventArgs e) { //Se inicia el backgroundworker BWprSimulacion.RunWorkerAsync(); BWprJubilacion.RunWorkerAsync(); BWprMensaje.RunWorkerAsync(); BWescudo.RunWorkerAsync(); BWeligeCasillas.RunWorkerAsync(); playFondo.PlayLooping();// Vuelve a reproducir la cancion }
//BW que al finalizar la simulación activa la finalización del programa private void BWprSimulacion_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled == false) { BWprSimulacion.CancelAsync(); BWprJubilacion.CancelAsync(); BWprMensaje.CancelAsync(); BWescudo.CancelAsync(); BWeligeCasillas.CancelAsync(); finalizarSimulacion(); } }
//BW comprueba el daño del escudo al finalizar los 30 segs private void BWescudo_DoWork(object sender, DoWorkEventArgs e) { BWescudo.WorkerReportsProgress = true; BWescudo.WorkerSupportsCancellation = true; for (int i = 30; i >= 0; i--) { if (BWescudo.CancellationPending == true) { break; } // Wait 1000 milliseconds. Thread.Sleep(1000); // Report progress. BWescudo.ReportProgress(i); if (i == 0) { i = 30; egui.comprobarDanio(); } } }