posant ordre en Stage i Background
This commit is contained in:
+89
-26
@@ -1,33 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector> // Para vector
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
Namespace Stage: gestiona los datos y operaciones de las fases del juego.
|
||||
Permite consultar y modificar el poder necesario, la amenaza y el estado de cada fase.
|
||||
*/
|
||||
#include "stage_interface.h"
|
||||
|
||||
namespace Stage {
|
||||
// --- Estructura con los datos de una fase ---
|
||||
struct Stage {
|
||||
int power_to_complete; // Cantidad de poder que se necesita para completar la fase
|
||||
int min_menace; // Umbral mínimo de amenaza de la fase
|
||||
int max_menace; // Umbral máximo de amenaza de la fase
|
||||
|
||||
// Constructor
|
||||
Stage(int power_to_complete, int min_menace, int max_menace)
|
||||
: power_to_complete(power_to_complete), min_menace(min_menace), max_menace(max_menace) {}
|
||||
enum class PowerCollectionState {
|
||||
ENABLED,
|
||||
DISABLED
|
||||
};
|
||||
|
||||
// --- Variables globales del estado de las fases ---
|
||||
extern std::vector<Stage> stages; // Vector con los datos de cada pantalla
|
||||
extern int power; // Poder acumulado en la fase actual
|
||||
extern int total_power; // Poder total necesario para completar el juego
|
||||
extern int number; // Índice de la fase actual
|
||||
extern bool power_can_be_added; // Indica si se puede añadir poder a la fase
|
||||
enum class StageStatus {
|
||||
LOCKED,
|
||||
IN_PROGRESS,
|
||||
COMPLETED
|
||||
};
|
||||
|
||||
// --- Funciones principales ---
|
||||
auto get(int index) -> Stage; // Devuelve una fase por índice
|
||||
void init(); // Inicializa las variables del namespace Stage
|
||||
void addPower(int amount); // Añade poder a la fase actual
|
||||
} // namespace Stage
|
||||
class StageData {
|
||||
private:
|
||||
int power_to_complete_;
|
||||
int min_menace_;
|
||||
int max_menace_;
|
||||
std::string name_;
|
||||
StageStatus status_;
|
||||
|
||||
public:
|
||||
StageData(int power_to_complete, int min_menace, int max_menace, const std::string& name = "");
|
||||
|
||||
// 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
|
||||
void setStatus(StageStatus status) { status_ = status; }
|
||||
|
||||
// Utilidades
|
||||
bool isCompleted() const { return status_ == StageStatus::COMPLETED; }
|
||||
};
|
||||
|
||||
class StageManager : public IStageInfo { // Hereda de la interfaz
|
||||
private:
|
||||
std::vector<StageData> stages_;
|
||||
int current_power_;
|
||||
int total_power_;
|
||||
size_t current_stage_index_;
|
||||
PowerCollectionState power_collection_state_;
|
||||
|
||||
public:
|
||||
StageManager();
|
||||
|
||||
// Métodos principales para Game
|
||||
void initialize();
|
||||
void reset();
|
||||
bool advanceToNextStage();
|
||||
|
||||
// Gestión de poder
|
||||
bool subtractPower(int amount);
|
||||
void enablePowerCollection();
|
||||
void disablePowerCollection();
|
||||
|
||||
// Navegación avanzada
|
||||
bool jumpToStage(size_t target_stage_index);
|
||||
|
||||
// Consultas de estado
|
||||
std::optional<StageData> getCurrentStage() const;
|
||||
std::optional<StageData> getStage(size_t index) const;
|
||||
size_t getCurrentStageIndex() const { return current_stage_index_; }
|
||||
int getCurrentPower() const { return current_power_; }
|
||||
int getTotalPower() const { return total_power_; }
|
||||
int getTotalPowerNeededToCompleteGame() const;
|
||||
size_t getTotalStages() const { return stages_.size(); }
|
||||
|
||||
// Progreso
|
||||
bool isCurrentStageCompleted() const;
|
||||
bool isGameCompleted() const;
|
||||
double getProgressPercentage() const; // Progreso total del juego
|
||||
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;
|
||||
|
||||
// ===== IMPLEMENTACIÓN DE IStageInfo =====
|
||||
// (Esto es lo que ven Player y Balloon)
|
||||
bool canCollectPower() const override;
|
||||
void addPower(int amount) override;
|
||||
int getCurrentMenaceLevel() const override;
|
||||
|
||||
private:
|
||||
void createDefaultStages();
|
||||
bool validateStageIndex(size_t index) const;
|
||||
void updateStageStatuses();
|
||||
};
|
||||
Reference in New Issue
Block a user