private void Timer1_Click(object sender, EventArgs e) { //Si el juego no ha iniciado, no se hace nada if (!GameData.GameStarted) { return; } GameData.performedTicks += 0.01; // Si por alguna razon esta nulo, no se invocara, de lo contrario se invocara // Se hace un try catch dentro de otro try catch, para optimizar el código try { MovingBall?.Invoke(); } catch (OutOfBoundsException ex) { try { GameData.lifes--; GameData.GameStarted = false; timer1.Stop(); RepositionElements(); UpdateElements(); if (GameData.lifes == 0) { throw new NoRemainingLifesExeption(""); } } catch (NoRemainingLifesExeption ex2) { timer1.Stop(); EndGame?.Invoke(); } } }
private void Timer1_Tick(object sender, EventArgs e) { if (!DatosJuego.juegoIniciado) { return; } DatosJuego.ticksRealizados += 0.01; try { MovimientoPelota?.Invoke(); } catch (System.IndexOutOfRangeException ex) { try { DatosJuego.vidas--; DatosJuego.juegoIniciado = false; timer1.Stop(); ReposicionarElementos(); ActualizarElementos(); if (DatosJuego.vidas == 0) { //throw new NoRemainingLifesException(""); throw new Exception(); } } catch (Exception ex2) { timer1.Stop(); //TerminarJuego?.Invoke(false); TerminarJuego?.Invoke(); } } }