Demanada ajuda a la IA pa que m'arregle un poc la meua merda: Para optimizar este código y evitar duplicar la lógica para cada jugador, podemos extraer el código común en una función reutilizable. Así, reducimos la repetición y mejoramos la legibilidad.
This commit is contained in:
@@ -2817,6 +2817,17 @@ void Game::addScoreToScoreBoard(std::string name, int score)
|
||||
manager->saveToFile(asset->get("score.bin"));
|
||||
}
|
||||
|
||||
// Saca del estado de GAME OVER al jugador si el otro está activo
|
||||
void Game::checkAndUpdatePlayerStatus(int activePlayerIndex, int inactivePlayerIndex)
|
||||
{
|
||||
if (players[activePlayerIndex]->isGameOver() &&
|
||||
!players[inactivePlayerIndex]->isGameOver() &&
|
||||
!players[inactivePlayerIndex]->isWaiting())
|
||||
{
|
||||
players[activePlayerIndex]->setStatusPlaying(playerStatus::WAITING);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el estado de los jugadores
|
||||
void Game::checkPlayersStatusPlaying()
|
||||
{
|
||||
@@ -2835,21 +2846,9 @@ void Game::checkPlayersStatusPlaying()
|
||||
}
|
||||
}
|
||||
|
||||
// Saca del estado de GAME OVER al primer jugador si el segundo está activo
|
||||
const bool a1 = players[0]->isGameOver();
|
||||
const bool b1 = !players[1]->isGameOver() && !players[1]->isWaiting();
|
||||
if (a1 && b1)
|
||||
{
|
||||
players[0]->setStatusPlaying(playerStatus::WAITING);
|
||||
}
|
||||
|
||||
// Saca del estado de GAME OVER al segundo jugador si el primero está activo
|
||||
const bool a2 = players[1]->isGameOver();
|
||||
const bool b2 = !players[0]->isGameOver() && !players[0]->isWaiting();
|
||||
if (a2 && b2)
|
||||
{
|
||||
players[1]->setStatusPlaying(playerStatus::WAITING);
|
||||
}
|
||||
// Comprobar estado de ambos jugadores
|
||||
checkAndUpdatePlayerStatus(0, 1);
|
||||
checkAndUpdatePlayerStatus(1, 0);
|
||||
}
|
||||
|
||||
// Obtiene un jugador a partir de su "id"
|
||||
|
||||
@@ -124,7 +124,7 @@ private:
|
||||
std::vector<Item *> items; // Vector con los items
|
||||
std::vector<SmartSprite *> smartSprites; // Vector con los smartsprites
|
||||
|
||||
std::unique_ptr<Texture> bulletTexture; // Textura para las balas
|
||||
std::unique_ptr<Texture> bulletTexture; // Textura para las balas
|
||||
std::vector<Texture *> itemTextures; // Vector con las texturas de los items
|
||||
std::vector<Texture *> balloonTextures; // Vector con las texturas de los globos
|
||||
std::vector<Texture *> explosionsTextures; // Vector con las texturas de las explosiones
|
||||
@@ -195,7 +195,7 @@ private:
|
||||
bool coffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego
|
||||
bool gameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
|
||||
int gameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
|
||||
gameDifficulty difficulty; // Dificultad del juego
|
||||
gameDifficulty difficulty; // Dificultad del juego
|
||||
float difficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
|
||||
color_t difficultyColor; // Color asociado a la dificultad
|
||||
int lastStageReached; // Contiene el número de la última pantalla que se ha alcanzado
|
||||
@@ -444,6 +444,9 @@ private:
|
||||
// Añade una puntuación a la tabla de records
|
||||
void addScoreToScoreBoard(std::string name, int score);
|
||||
|
||||
// Saca del estado de GAME OVER al jugador si el otro está activo
|
||||
void checkAndUpdatePlayerStatus(int activePlayerIndex, int inactivePlayerIndex);
|
||||
|
||||
// Comprueba el estado de juego de los jugadores
|
||||
void checkPlayersStatusPlaying();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user