@@ -116,12 +116,12 @@ void EscenarioJuego::agregarEtapa(Etapa * etapa) {
116
116
this ->etapas .push_back (etapa);
117
117
}
118
118
119
- bool EscenarioJuego::manejarEvento (int nroAvion, int evento) {
119
+ int EscenarioJuego::manejarEvento (int nroAvion, int evento) {
120
120
vector<Disparo *> disparo;
121
- bool resetea = false ;
121
+ int eventoIteracion = CONTINUA_PARTIDA ;
122
122
switch (evento) {
123
123
case PRESIONA_R:
124
- resetea = true ;
124
+ eventoIteracion = RESETEA_PARTIDA ;
125
125
break ;
126
126
case PRESIONA_ESPACIO:
127
127
disparo = avion (nroAvion)->disparar ();
@@ -141,11 +141,13 @@ bool EscenarioJuego::manejarEvento(int nroAvion, int evento) {
141
141
case PRESIONA_P:
142
142
this ->togglePausa ();
143
143
break ;
144
+ case PRESIONA_C:
145
+ eventoIteracion = CIERRA_PARTIDA;
144
146
default :
145
147
avion (nroAvion)->manejarEvento (evento);
146
148
break ;
147
149
}
148
- return resetea ;
150
+ return eventoIteracion ;
149
151
}
150
152
151
153
void EscenarioJuego::avanzarEtapa () {
@@ -189,6 +191,29 @@ void EscenarioJuego::reiniciarEtapas() {
189
191
190
192
}
191
193
194
+ void EscenarioJuego::terminarEtapas () {
195
+ desactivar ();
196
+ pthread_mutex_lock (&mutexPowerUps);
197
+ this ->powerUps .clear ();
198
+ pthread_mutex_unlock (&mutexPowerUps);
199
+ pthread_mutex_lock (&mutexListaEnemigos);
200
+ this ->enemigos .clear ();
201
+ pthread_mutex_unlock (&mutexListaEnemigos);
202
+ pthread_mutex_lock (&mutexListaDisparosEnemigos);this ->disparos .clear ();
203
+ this ->disparosEnemigos .clear ();
204
+ pthread_mutex_unlock (&mutexListaDisparosEnemigos);
205
+ pthread_mutex_lock (&mutexListaDisparos);this ->disparos .clear ();
206
+ this ->disparos .clear ();
207
+ pthread_mutex_unlock (&mutexListaDisparos);
208
+
209
+ while (!this ->colaEventos .vacia ()) {
210
+ this ->colaEventos .pop ();
211
+ }
212
+ temporizador.detener ();
213
+
214
+ this ->etapas .clear ();
215
+ }
216
+
192
217
int EscenarioJuego::comenzarEtapa () {
193
218
this ->activar ();
194
219
scrollingOffset = 0 ;
@@ -234,7 +259,7 @@ int EscenarioJuego::mainLoop() {
234
259
}
235
260
236
261
int EscenarioJuego::actualizarEstado (float timeStep) {
237
- bool resetear = false ;
262
+ int eventoIteracion = CONTINUA_PARTIDA ;
238
263
int eventoFinal = AVANZAR_ETAPA;
239
264
if (this ->posicionY < this ->etapaActual ()->getLongitud () - 800 ) {
240
265
if (!this ->pausado ) {
@@ -253,7 +278,7 @@ int EscenarioJuego::actualizarEstado(float timeStep) {
253
278
this ->moverDisparos (timeStep);
254
279
this ->getProximoEnemigo ();
255
280
}
256
- resetear = this ->manejarProximoEvento ();
281
+ eventoIteracion = this ->manejarProximoEvento ();
257
282
} else {
258
283
this ->moverEnemigos (timeStep);
259
284
this ->moverDisparosEnemigos (timeStep);
@@ -282,9 +307,12 @@ int EscenarioJuego::actualizarEstado(float timeStep) {
282
307
}
283
308
}
284
309
}
285
- if (resetear ){
310
+ if (eventoIteracion == RESETEA_PARTIDA ){
286
311
this ->reiniciarEtapas ();
287
312
eventoFinal = REINICIAR_ESCENARIO;
313
+ } else if (eventoIteracion == CIERRA_PARTIDA){
314
+ this ->terminarEtapas ();
315
+ eventoFinal = FINALIZAR_JUEGO;
288
316
}
289
317
return eventoFinal;
290
318
}
@@ -351,19 +379,19 @@ int EscenarioJuego::jugar(bool serverActivo) {
351
379
return comenzarEtapa ();
352
380
}
353
381
354
- bool EscenarioJuego::manejarProximoEvento () {
355
- bool resetear = false ;
382
+ int EscenarioJuego::manejarProximoEvento () {
383
+ int eventoIteracion = CONTINUA_PARTIDA ;
356
384
if (!this ->colaEventos .vacia ()) {
357
385
pair<int , int > evento = this ->colaEventos .pop ();
358
386
if (!this ->pausado ){
359
- resetear = this ->manejarEvento (evento.first , evento.second );
387
+ eventoIteracion = this ->manejarEvento (evento.first , evento.second );
360
388
} else {
361
389
if (evento.second == PRESIONA_P || evento.second == PRESIONA_R){
362
- resetear = this ->manejarEvento (evento.first , evento.second );
390
+ eventoIteracion = this ->manejarEvento (evento.first , evento.second );
363
391
}
364
392
}
365
393
}
366
- return resetear ;
394
+ return eventoIteracion ;
367
395
}
368
396
369
397
void EscenarioJuego::pushEvento (pair<int , int > evento) {
0 commit comments