Stage ja carrega desde fitxer la informació de les fases
This commit is contained in:
+58
-48
@@ -4,98 +4,108 @@
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <functional> // ⬅️ Para std::function
|
||||
#include <functional>
|
||||
|
||||
// --- Estados posibles para la recolección de poder ---
|
||||
enum class PowerCollectionState {
|
||||
ENABLED,
|
||||
DISABLED
|
||||
ENABLED, // Recolección habilitada
|
||||
DISABLED // Recolección deshabilitada
|
||||
};
|
||||
|
||||
// --- Estados posibles para una fase del juego ---
|
||||
enum class StageStatus {
|
||||
LOCKED,
|
||||
IN_PROGRESS,
|
||||
COMPLETED
|
||||
LOCKED, // Fase bloqueada
|
||||
IN_PROGRESS, // Fase en progreso
|
||||
COMPLETED // Fase completada
|
||||
};
|
||||
|
||||
// --- Representa los datos de una fase del juego ---
|
||||
class StageData {
|
||||
private:
|
||||
int power_to_complete_;
|
||||
int min_menace_;
|
||||
int max_menace_;
|
||||
std::string name_;
|
||||
StageStatus status_;
|
||||
int power_to_complete_; // Poder necesario para completar la fase
|
||||
int min_menace_; // Nivel mínimo de amenaza
|
||||
int max_menace_; // Nivel máximo de amenaza
|
||||
std::string name_; // Nombre de la fase
|
||||
StageStatus status_; // Estado actual de la fase
|
||||
|
||||
public:
|
||||
// Constructor de una fase
|
||||
StageData(int power_to_complete, int min_menace, int max_menace, const std::string& name = "");
|
||||
|
||||
// Getters
|
||||
// --- Getters ---
|
||||
int getPowerToComplete() const { return power_to_complete_; }
|
||||
int getMinMenace() const { return min_menace_; }
|
||||
int getMaxMenace() const { return max_menace_; }
|
||||
const std::string& getName() const { return name_; }
|
||||
StageStatus getStatus() const { return status_; }
|
||||
|
||||
// Setters
|
||||
// --- Setters ---
|
||||
void setStatus(StageStatus status) { status_ = status; }
|
||||
|
||||
// Utilidades
|
||||
// --- Utilidades ---
|
||||
bool isCompleted() const { return status_ == StageStatus::COMPLETED; }
|
||||
};
|
||||
|
||||
class StageManager : public IStageInfo { // ⬅️ Hereda de la interfaz
|
||||
// --- Gestor principal del sistema de fases del juego ---
|
||||
class StageManager : public IStageInfo {
|
||||
private:
|
||||
std::vector<StageData> stages_;
|
||||
int current_power_;
|
||||
int total_power_;
|
||||
size_t current_stage_index_;
|
||||
PowerCollectionState power_collection_state_;
|
||||
std::vector<StageData> stages_; // Lista de todas las fases
|
||||
int current_power_; // Poder actual en la fase activa
|
||||
int total_power_; // Poder total acumulado en todo el juego
|
||||
size_t current_stage_index_; // Índice de la fase actual
|
||||
PowerCollectionState power_collection_state_; // Estado de recolección de poder
|
||||
|
||||
public:
|
||||
using PowerChangeCallback = std::function<void(int)>;
|
||||
|
||||
StageManager();
|
||||
|
||||
// Métodos principales para Game
|
||||
void initialize();
|
||||
void reset();
|
||||
bool advanceToNextStage();
|
||||
// --- Métodos principales del juego ---
|
||||
void initialize(); // Inicializa el gestor de fases
|
||||
void initialize(const std::string& stages_file); // Inicializa con archivo personalizado
|
||||
void reset(); // Reinicia el progreso del juego
|
||||
bool advanceToNextStage(); // Avanza a la siguiente fase
|
||||
|
||||
// Gestión de poder
|
||||
bool subtractPower(int amount);
|
||||
void enablePowerCollection();
|
||||
void disablePowerCollection();
|
||||
// --- Gestión de poder ---
|
||||
bool subtractPower(int amount); // Resta poder de la fase actual
|
||||
void enablePowerCollection(); // Habilita la recolección de poder
|
||||
void disablePowerCollection(); // Deshabilita la recolección de poder
|
||||
|
||||
// Navegación avanzada
|
||||
bool jumpToStage(size_t target_stage_index);
|
||||
// --- Navegación ---
|
||||
bool jumpToStage(size_t target_stage_index); // Salta a una fase específica
|
||||
|
||||
// Consultas de estado
|
||||
std::optional<StageData> getCurrentStage() const;
|
||||
std::optional<StageData> getStage(size_t index) const;
|
||||
// --- Consultas de estado ---
|
||||
std::optional<StageData> getCurrentStage() const; // Obtiene la fase actual
|
||||
std::optional<StageData> getStage(size_t index) const; // Obtiene una fase específica
|
||||
size_t getCurrentStageIndex() const { return current_stage_index_; }
|
||||
int getCurrentPower() const { return current_power_; }
|
||||
int getTotalPower() const { return total_power_; }
|
||||
int getTotalPowerNeededToCompleteGame() const; // ⬅️ Nuevo método
|
||||
int getTotalPowerNeededToCompleteGame() const; // Poder total necesario para completar el juego
|
||||
size_t getTotalStages() const { return stages_.size(); }
|
||||
|
||||
// Progreso
|
||||
bool isCurrentStageCompleted() const;
|
||||
bool isGameCompleted() const;
|
||||
double getProgressPercentage() const; // Progreso total del juego
|
||||
// --- Seguimiento de progreso ---
|
||||
bool isCurrentStageCompleted() const; // Verifica si la fase actual está completada
|
||||
bool isGameCompleted() const; // Verifica si el juego está completado
|
||||
double getProgressPercentage() const; // Progreso total del juego (0-100%)
|
||||
double getCurrentStageProgressPercentage() const; // Progreso de la fase actual (0-100%)
|
||||
double getCurrentStageProgressFraction() const; // Progreso de la fase actual (0.0-1.0)
|
||||
int getPowerNeededForCurrentStage() const;
|
||||
int getPowerNeededForCurrentStage() const; // Poder restante para completar la fase actual
|
||||
|
||||
// ===== IMPLEMENTACIÓN DE IStageInfo =====
|
||||
// (Esto es lo que ven Player y Balloon)
|
||||
// --- Gestión de callbacks ---
|
||||
void setPowerChangeCallback(PowerChangeCallback callback); // Establece callback para cambios de poder
|
||||
void removePowerChangeCallback(); // Elimina callback de cambios de poder
|
||||
|
||||
// --- Implementación de la interfaz IStageInfo ---
|
||||
bool canCollectPower() const override;
|
||||
void addPower(int amount) override;
|
||||
int getCurrentMenaceLevel() const override;
|
||||
using PowerChangeCallback = std::function<void(int)>;
|
||||
void setPowerChangeCallback(PowerChangeCallback callback);
|
||||
void removePowerChangeCallback();
|
||||
|
||||
private:
|
||||
PowerChangeCallback power_change_callback_;
|
||||
PowerChangeCallback power_change_callback_; // Callback para notificar cambios de poder
|
||||
|
||||
void createDefaultStages();
|
||||
bool validateStageIndex(size_t index) const;
|
||||
void updateStageStatuses();
|
||||
// --- Métodos privados ---
|
||||
void createDefaultStages(); // Crea las fases predeterminadas del juego
|
||||
bool loadStagesFromFile(const std::string& filename); // Carga fases desde archivo
|
||||
bool validateStageIndex(size_t index) const; // Valida que un índice de fase sea válido
|
||||
void updateStageStatuses(); // Actualiza los estados de todas las fases
|
||||
};
|
||||
Reference in New Issue
Block a user