- "Info" ara es una unitat simple

This commit is contained in:
2024-01-29 14:52:53 +01:00
parent aca0f646b3
commit 80234e195e
11 changed files with 56 additions and 62 deletions

10
info.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include "info.h"
namespace info
{
int estat_joc;
bool rosita_enabled;
bool job_enabled;
int dificultat;
int personatge;
}

14
info.h
View File

@@ -21,10 +21,10 @@
#define PERSONATGE_ROSITA 1
#define PERSONATGE_JOB 2
struct Info {
int estat_joc;
bool rosita_enabled;
bool job_enabled;
int dificultat;
int personatge;
};
namespace info{
extern int estat_joc;
extern bool rosita_enabled;
extern bool job_enabled;
extern int dificultat;
extern int personatge;
}

View File

@@ -36,47 +36,46 @@ int main( int argc, char* args[] ) {
JD8_Init("Pepe El Pintor");
JS_Init();
Info info;
info.estat_joc = ESTAT_ICEKAS; // ESTAT_SEQUENCIA; // ESTAT_ICEKAS;
info.rosita_enabled = false;
info.job_enabled = false;
info.dificultat = MODE_FACIL;
info.personatge = PERSONATGE_PEPE;
info::estat_joc = ESTAT_ICEKAS; // ESTAT_SEQUENCIA; // ESTAT_ICEKAS;
info::rosita_enabled = false;
info::job_enabled = false;
info::dificultat = MODE_FACIL;
info::personatge = PERSONATGE_PEPE;
FILE* ini = fopen("trick.ini", "rb");
if (ini != NULL) {
unsigned char contingut = 0;
fread(&contingut, 1, 1, ini);
fclose(ini);
if (contingut > 0) info.rosita_enabled = true;
if (contingut > 1) info.job_enabled = true;
if (contingut > 0) info::rosita_enabled = true;
if (contingut > 1) info::job_enabled = true;
}
while (info.estat_joc != ESTAT_EIXIR) {
switch (info.estat_joc) {
while (info::estat_joc != ESTAT_EIXIR) {
switch (info::estat_joc) {
case ESTAT_ICEKAS:
case ESTAT_LOGO:
ModuleStaticScreen * moduleStaticScreen;
moduleStaticScreen = new ModuleStaticScreen(&info);
info.estat_joc = moduleStaticScreen->Go();
moduleStaticScreen = new ModuleStaticScreen();
info::estat_joc = moduleStaticScreen->Go();
delete moduleStaticScreen;
break;
case ESTAT_MENU:
ModuleMenu * moduleMenu;
moduleMenu = new ModuleMenu(&info);
info.estat_joc = moduleMenu->Go();
moduleMenu = new ModuleMenu();
info::estat_joc = moduleMenu->Go();
delete moduleMenu;
break;
case ESTAT_SELECT:
ModuleSelect * moduleSelect;
moduleSelect = new ModuleSelect(&info);
info.estat_joc = moduleSelect->Go();
moduleSelect = new ModuleSelect();
info::estat_joc = moduleSelect->Go();
delete moduleSelect;
break;
case ESTAT_SEQUENCIA:
ModuleSequence * moduleSequence;
moduleSequence = new ModuleSequence(&info);
info.estat_joc = moduleSequence->Go();
moduleSequence = new ModuleSequence();
info::estat_joc = moduleSequence->Go();
delete moduleSequence;
break;
}

View File

@@ -6,6 +6,7 @@
#include "jsound.h"
#include <stdlib.h>
#include <string>
#include "info.h"
#define SENSE_OPCIO -1
#define OPCIO_TIMEATTACK 0
@@ -13,8 +14,7 @@
#define OPCIO_CLASSICMODE 2
#define OPCIO_OPTIONS 3
ModuleMenu::ModuleMenu(Info* info) {
this->info = info;
ModuleMenu::ModuleMenu() {
}
ModuleMenu::~ModuleMenu(void) {

View File

@@ -1,12 +1,10 @@
#pragma once
#include "info.h"
class ModuleMenu {
public:
ModuleMenu(Info* info);
ModuleMenu();
~ModuleMenu(void);
int Go();
@@ -15,6 +13,5 @@ private:
//void showMenu();
Info* info;
int contador;
};

View File

@@ -6,9 +6,10 @@
#include "jsound.h"
#include <stdlib.h>
#include <string>
#include "info.h"
ModuleSelect::ModuleSelect(Info* info) {
this->info = info;
ModuleSelect::ModuleSelect() {
}
ModuleSelect::~ModuleSelect(void) {
@@ -37,7 +38,7 @@ int ModuleSelect::Go() {
int num_personatges = 3;
if (!this->info->rosita_enabled) {
if (!info::rosita_enabled) {
num_personatges--;
for (int i = 137; i <= 212; i++) for (int j = 11; j <= 91; j++) JD8_PutPixel(fondo, i, j, 0);
JD8_PutPixel(fondo, 145, 19, 14);
@@ -52,7 +53,7 @@ int ModuleSelect::Go() {
JD8_PutPixel(fondo, 139, 37, 9);
JD8_PutPixel(fondo, 211, 81, 9);
}
if (!this->info->job_enabled) {
if (!info::job_enabled) {
num_personatges--;
for (int i = 219; i <= 294; i++) for (int j = 11; j <= 91; j++) JD8_PutPixel(fondo, i, j, 0);
JD8_PutPixel(fondo, 228, 65, 14);
@@ -78,9 +79,9 @@ int ModuleSelect::Go() {
while (!JG_ShouldUpdate()) { JI_Update(); }
}
int opcio_seleccionada = this->info->dificultat;
int opcio_seleccionada = info::dificultat;
int opcio_triada = SENSE_OPCIO;
int personatge_seleccionat = this->info->personatge;
int personatge_seleccionat = info::personatge;
bool fletxa_amunt_pulsada = false;
bool fletxa_avall_pulsada = false;
bool fletxa_esquerra_pulsada = false;
@@ -165,8 +166,8 @@ int ModuleSelect::Go() {
if (JG_Quitting()) {
return ESTAT_EIXIR;
} else {
this->info->dificultat = opcio_triada;
this->info->personatge = personatge_seleccionat;
info::dificultat = opcio_triada;
info::personatge = personatge_seleccionat;
return ESTAT_SEQUENCIA;
}
}

View File

@@ -1,17 +1,14 @@
#pragma once
#include "info.h"
class ModuleSelect {
public:
ModuleSelect(Info* info);
ModuleSelect();
~ModuleSelect(void);
int Go();
private:
Info* info;
};

View File

@@ -6,13 +6,13 @@
#include "jsound.h"
#include <stdlib.h>
#include <string>
#include "info.h"
JD8_Surface gfx = nullptr;
JD8_Surface fondo = nullptr;
JD8_Palette pal = nullptr;
ModuleSequence::ModuleSequence(Info* info) {
this->info = info;
ModuleSequence::ModuleSequence() {
gfx = nullptr;
fondo = nullptr;
pal = nullptr;

View File

@@ -1,20 +1,16 @@
#pragma once
#include "info.h"
class ModuleSequence {
public:
ModuleSequence(Info* info);
ModuleSequence();
~ModuleSequence(void);
int Go();
private:
Info * info;
void FadeIn();
void FadeOut();
void ShowText(int x, int y, int color, int speed, const char* text1, const char* text2 = nullptr, const char* text3 = nullptr);

View File

@@ -6,9 +6,10 @@
#include "jsound.h"
#include <stdlib.h>
#include <string>
#include "info.h"
ModuleStaticScreen::ModuleStaticScreen() {
ModuleStaticScreen::ModuleStaticScreen( Info* info ) {
this->info = info;
}
ModuleStaticScreen::~ModuleStaticScreen(void) {
@@ -16,7 +17,7 @@ ModuleStaticScreen::~ModuleStaticScreen(void) {
int ModuleStaticScreen::Go() {
switch( this->info->estat_joc ) {
switch( info::estat_joc ) {
case ESTAT_ICEKAS:
doIcekas();
break;
@@ -30,7 +31,7 @@ int ModuleStaticScreen::Go() {
if( JG_Quitting() ) {
return ESTAT_EIXIR;
} else {
switch (this->info->estat_joc) {
switch (info::estat_joc) {
case ESTAT_ICEKAS: return ESTAT_LOGO; break;
case ESTAT_LOGO: return ESTAT_MENU; break;
}
@@ -38,10 +39,6 @@ int ModuleStaticScreen::Go() {
return 0;
}
const int minim( const int a, const int b ) {
if( b < a ) { return b; } else { return a; }
}
void ModuleStaticScreen::doIcekas() {
bool eixir = false;

View File

@@ -1,12 +1,10 @@
#pragma once
#include "info.h"
class ModuleStaticScreen {
public:
ModuleStaticScreen( Info* info );
ModuleStaticScreen();
~ModuleStaticScreen(void);
int Go();
@@ -16,6 +14,5 @@ private:
void doIcekas();
void doLogo();
Info* info;
int contador;
};