Skip to content

Commit

Permalink
Instrumentalización completa
Browse files Browse the repository at this point in the history
Co-Authored-By: Anassito <[email protected]>
Co-Authored-By: Paula Martínez Martínez <[email protected]>
Co-Authored-By: Aurora García Jover <[email protected]>
Co-Authored-By: Amaro Blest <[email protected]>
Co-Authored-By: Raúl Blas Ruiz <[email protected]>
  • Loading branch information
6 people committed Apr 17, 2022
1 parent 29216bd commit fbe87c9
Show file tree
Hide file tree
Showing 29 changed files with 440 additions and 269 deletions.
2 changes: 1 addition & 1 deletion src/Events/noDel.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.
No borrar este archivo para que gthub no borre la carpeta Events
99 changes: 68 additions & 31 deletions src/Sources/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Application::Application(GameStateMachine* state) {

// USABILIDAD
tracker_ = Tracker::GetInstance();

}

Application::~Application() {
// USABILIDAD
long long timest = Tracker::GetTimeStamp();
Logout* logout = (Logout*)(Tracker::CreateNewEvent(timest, gameManager_->getIdUser(), "a", (int)EventInfo::EventType::Logout));
auto sesion = gameManager_->getIdSesion();
Logout* logout = (Logout*)(Tracker::CreateNewEvent(timest, gameManager_->getIdUser(), sesion, (int)EventInfo::EventType::Logout));
Tracker::TrackEvent(logout);
tracker_->End();
tracker_->Free();
Expand Down Expand Up @@ -58,6 +58,7 @@ void Application::initSDL() {
throw exception("Game window or renderer was null");
}
}

//USABILIDAD
bool Application::initTracker()
{
Expand All @@ -66,44 +67,24 @@ bool Application::initTracker()
return false;
}

//USABILIDAD
std::string cmd = "getmac";
std::string auxFile = "macaddress.txt";

system((cmd + ">" + auxFile).c_str());
std::string line;
std::ifstream myfile("macaddress.txt");


std::string mac;
int i = 0;
if (myfile.is_open()) {

while (i < 4 && std::getline(myfile, line)) {
i++;
}
mac = line.substr(0, 17);
myfile.close();
}
else
std::cout << "Unable to open the file";

system(("del " + auxFile).c_str());

if (gameManager_ == nullptr) {
std::cout << "Error al inicializar el tracker. Gamemanager sin inicializar...\n";
return false;
}

gameManager_->setIdUser(mac);
createIdUser();
std::string mac = gameManager_->getIdUser();
createIdSesion();
std::string sesion = gameManager_->getIdSesion();

trackerStarted_ = tracker_->Init(PersistenceType::FILE, TypeOfFile::Json, PATH_TRACKER);
if (!tracker_->Init(PersistenceType::FILE, TypeOfFile::Json, PATH_TRACKER))
return false;

long long timest = Tracker::GetTimeStamp();

Login* login = (Login*)(Tracker::CreateNewEvent(timest, mac, "a", (int)EventInfo::EventType::Login));
Login* login = (Login*)(Tracker::CreateNewEvent(timest, mac, sesion, (int)EventInfo::EventType::Login));
Tracker::TrackEvent(login);

return trackerStarted_;
return true;
}

void Application::runApp() {
Expand Down Expand Up @@ -149,6 +130,62 @@ void Application::updateDelta()
deltaTime_ = (double)((currTicks_ - lastTicks_) / (double)SDL_GetPerformanceFrequency());
}

void Application::createIdUser()
{
// Comando de la consola de windows
std::string cmd = "getmac";
std::string auxFile = "macaddress.txt";

system((cmd + ">" + auxFile).c_str());

std::string line;
// Fichero auxiliar temporal
std::ifstream myfile("macaddress.txt");
// Direccion mac final
std::string mac;
int i = 0;
if (myfile.is_open()) {

while (i < 4 && std::getline(myfile, line)) {
i++;
}
mac = line.substr(0, 17);
myfile.close();
}
else
std::cout << "Unable to open the file";

system(("del " + auxFile).c_str());

gameManager_->setIdUser(mac);
}

void Application::createIdSesion()
{
/* initialize random seed: */
srand(time(NULL));
int length = rand() % 16 + 10;
std::string idSesion = "";
for (int i = 0; i < length; i++) {
int choice = (char)rand() % 3 + 0;
switch (choice)
{
case 1:
idSesion += rand() % ('9' - '0' + 1) + '0';;
break;
case 2:
idSesion += rand() % ('Z' - 'A' + 1) + 'A';
break;
case 3:
default:
idSesion += rand() % ('z' - 'a' + 1) + 'a';
break;
}
}

gameManager_->setIdSesion(idSesion);
}

void Application::initResources() {
//Crear e inicializar textureManager
textureManager_ = new TextureManager();
Expand Down
15 changes: 11 additions & 4 deletions src/Sources/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Application
// USABILIDAD
Tracker* tracker_ = nullptr;
bool trackerStarted_ = false;

//
///<summary>Variables basicas de SDL</summary>
SDL_Window* window_ = nullptr;
SDL_Renderer* renderer_ = nullptr;
Expand Down Expand Up @@ -65,14 +65,21 @@ class Application
double deltaTime_;
void updateDelta();

// USABILIDAD
// Genera un ID de usuario obteniendo la dirección mac
void createIdUser();
// Genera un ID de la sesion de juego (inicio hasta cierre)
// de forma aleatoria
void createIdSesion();
//
public:
///<summary>Construtora de la app</summary>
Application(GameStateMachine* state=nullptr);
virtual ~Application();
Application(GameStateMachine* state = nullptr);
virtual ~Application();

///<summary>Constantes con las dimensiones de la ventana </summary>
static const int winWidth_ = 1600;
static const int winHeight_ = 900;
static const int winHeight_ = 900;

/// <summary>
/// USABILIDAD.
Expand Down
73 changes: 47 additions & 26 deletions src/Sources/CaribbeanIslandState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ void CaribbeanIslandState::update()
gm_->setUnlockedIslands(Island::Spooky);

// USABILIDAD
gm_->setCompletedZone(Zone::CaribeanBoss, true);
long long timest = Tracker::GetTimeStamp();
std::string idUser = gm_->getIdUser();
std::string idGame = "a";
LogoutZone* logoutZone = (LogoutZone*)(Tracker::CreateNewEvent(timest, idUser, "a", (int)EventInfo::EventType::LogoutZone));
logoutZone->setZone(14);
//USABILIDAD
auto sesion = gm_->getIdSesion();
LogoutZone* logoutZone = (LogoutZone*)(Tracker::CreateNewEvent(timest, idUser, sesion, (int)EventInfo::EventType::LogoutZone));
int zone = gm_->generateZoneUsa();
logoutZone->setZone(zone);
logoutZone->setNext(0);
Tracker::TrackEvent(logoutZone);
//
Expand All @@ -45,12 +46,8 @@ void CaribbeanIslandState::update()
void CaribbeanIslandState::initState()
{
//Resteo de la isla
// USABILIDAD

gm_->setCurrentZone(Zone::CaribeanA);
gm_->setCurrIsland(Island::Caribbean);

//
//Inicializamos la musica
app_->resetMusicChannels();
app_->resetSoundsChannels();
Expand Down Expand Up @@ -85,9 +82,12 @@ void CaribbeanIslandState::initZone1()

//USABILIDAD
long long timest = Tracker::GetTimeStamp();
LoginZone* logzone = (LoginZone*)(Tracker::CreateNewEvent(timest, gm_->getIdUser(), "a", (int)EventInfo::EventType::LoginZone));
logzone->setZone(11);
Tracker::TrackEvent(logzone);
auto sesion = gm_->getIdSesion();
LoginZone* loginzone = (LoginZone*)(Tracker::CreateNewEvent(timest, gm_->getIdUser(), sesion, (int)EventInfo::EventType::LoginZone));
int zone = gm_->generateZoneUsa();
loginzone->setZone(zone);
loginzone->setCompleted(gm_->getCompletedZone(Zone::CaribeanA));
Tracker::TrackEvent(loginzone);
}

void CaribbeanIslandState::initZone2()
Expand All @@ -99,9 +99,12 @@ void CaribbeanIslandState::initZone2()
TILESET_FILS, TILESET_COLS, Vector2D(app_->getWindowWidth() / 2, 0), collisionTilesIdZone1, wallTilesIdZone2);
//USABILIDAD
long long timest = Tracker::GetTimeStamp();
LoginZone* logzone = (LoginZone*)(Tracker::CreateNewEvent(timest, gm_->getIdUser(), "a", (int)EventInfo::EventType::LoginZone));
logzone->setZone(12);
Tracker::TrackEvent(logzone);
auto sesion = gm_->getIdSesion();
LoginZone* loginzone = (LoginZone*)(Tracker::CreateNewEvent(timest, gm_->getIdUser(), sesion, (int)EventInfo::EventType::LoginZone));
int zone = gm_->generateZoneUsa();
loginzone->setZone(zone);
loginzone->setCompleted(gm_->getCompletedZone(Zone::CaribeanB));
Tracker::TrackEvent(loginzone);
}

void CaribbeanIslandState::initZone3()
Expand All @@ -118,9 +121,12 @@ void CaribbeanIslandState::initZone3()
TILESET_FILS, TILESET_COLS, Vector2D(app_->getWindowWidth() / 2, 0), collisionTilesIdZone1, wallTilesIdZone2);
//USABILIDAD
long long timest = Tracker::GetTimeStamp();
LoginZone* logzone = (LoginZone*)(Tracker::CreateNewEvent(timest, gm_->getIdUser(), "a", (int)EventInfo::EventType::LoginZone));
logzone->setZone(13);
Tracker::TrackEvent(logzone);
auto sesion = gm_->getIdSesion();
LoginZone* loginzone = (LoginZone*)(Tracker::CreateNewEvent(timest, gm_->getIdUser(), sesion, (int)EventInfo::EventType::LoginZone));
int zone = gm_->generateZoneUsa();
loginzone->setZone(zone);
loginzone->setCompleted(gm_->getCompletedZone(Zone::CaribeanC));
Tracker::TrackEvent(loginzone);
}

void CaribbeanIslandState::initBossZone()
Expand All @@ -134,43 +140,58 @@ void CaribbeanIslandState::initBossZone()

//USABILIDAD
long long timest = Tracker::GetTimeStamp();
LoginZone* logzone = (LoginZone*)(Tracker::CreateNewEvent(timest, gm_->getIdUser(), "a", (int)EventInfo::EventType::LoginZone));
logzone->setZone(14);
Tracker::TrackEvent(logzone);
auto sesion = gm_->getIdSesion();
LoginZone* loginzone = (LoginZone*)(Tracker::CreateNewEvent(timest, gm_->getIdUser(), sesion, (int)EventInfo::EventType::LoginZone));
int zone = gm_->generateZoneUsa();
loginzone->setZone(zone);
loginzone->setCompleted(gm_->getCompletedZone(Zone::CaribeanBoss));
Tracker::TrackEvent(loginzone);
}

void CaribbeanIslandState::changeZone()
{
// USABILIDAD
long long timest = Tracker::GetTimeStamp();
LogoutZone* logoutZone = (LogoutZone*)(Tracker::CreateNewEvent(timest, gm_->getIdUser(), "a", (int)EventInfo::EventType::LogoutZone));

logoutZone->setZone((int)GameManager::instance()->getCurrIsland() * 10 + (int)GameManager::instance()->getCurrentZone());
logoutZone->setNext((int)GameManager::instance()->getCurrIsland() * 10 + (int)GameManager::instance()->getCurrentZone() + 1);
auto sesion = gm_->getIdSesion();
LogoutZone* logoutZone = (LogoutZone*)(Tracker::CreateNewEvent(timest, gm_->getIdUser(), sesion, (int)EventInfo::EventType::LogoutZone));
int zone = gm_->generateZoneUsa();
logoutZone->setZone(zone);
Tracker::TrackEvent(logoutZone);
//

delete currentMap_;
collisionCtrl_->clearList();

enemies_.clear();
if (gm_->getCurrentZone() == Zone::CaribeanA) {
gm_->setCompletedZone(Zone::CaribeanA, true);
// Zona 2
logoutZone->setNext(12);
deleteExceptHUD(Zone::CaribeanB);
initZone2();
addRenderUpdateLists(hud_);
}
else if (gm_->getCurrentZone() == Zone::CaribeanB) {
gm_->setCompletedZone(Zone::CaribeanB, true);
int zone = gm_->generateZoneUsa();
logoutZone->setZone(zone);
// Zona 3
logoutZone->setNext(13);
deleteExceptHUD(Zone::CaribeanC);
initZone3();
addRenderUpdateLists(hud_);
}
else if (gm_->getCurrentZone() == Zone::CaribeanC) {
gm_->setCompletedZone(Zone::CaribeanC, true);
int zone = gm_->generateZoneUsa();
logoutZone->setZone(zone);
// Zona del boss
logoutZone->setNext(14);
deleteExceptHUD(Zone::CaribeanBoss);
initBossZone();
addRenderUpdateLists(hud_);
}
hud_->setPlayerInHUD(player_);
player_->initSkills();


Tracker::End();
}
5 changes: 3 additions & 2 deletions src/Sources/Chest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ bool Chest::update() {
void Chest::onCollider() {
open = true;
app_->getAudioManager()->playChannel(Resources::ChestOpeningAudio, 0, Resources::ChestChannelChannel);
auto gm = GameManager::instance();
//USABILIDAD
long long timest = Tracker::GetTimeStamp();
OpenChest* opchest = (OpenChest*)(Tracker::CreateNewEvent(timest, GameManager::instance()->getIdUser(), "a", (int)EventInfo::EventType::OpenChest));
auto sesion = gm->getIdSesion();
OpenChest* opchest = (OpenChest*)(Tracker::CreateNewEvent(timest, gm->getIdUser(), sesion, (int)EventInfo::EventType::OpenChest));
Tracker::TrackEvent(opchest);
//
//TO DO PENSAR EL COFRE AGAIN
}

Loading

0 comments on commit fbe87c9

Please sign in to comment.