diff --git a/IAEngine.c b/IAEngine.c index 8f6bcb6..4be2cea 100644 --- a/IAEngine.c +++ b/IAEngine.c @@ -17,9 +17,10 @@ int IAEngine(PLAYER * player1, PLAYER * player2) { + char Race[20]; + //Player 1 est le joueur, player 2 le bot if((player1 != NULL) & (player2 !=NULL)) - char Race[20]; { //On récupère les positions des 2 joueurs . L'IA sait où est le joueur int Player1PositionX = player1->PositionX; diff --git a/arenaEngine.c b/arenaEngine.c index 9f9acb2..04163af 100644 --- a/arenaEngine.c +++ b/arenaEngine.c @@ -2,36 +2,31 @@ #include #include #include "fileHandler.h" +#include "logHelper.h" -int initResources() { - //resOpen(); - - return 0; -} +/* + * Arena generate functions + */ ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) { ARENA_H_TILE* tile_h = NULL; if (prevHTile == NULL) { tile_h = calloc(1,sizeof(ARENA_H_TILE)); //Using calloc because of resetting all memory allocated to 0 tile_h->type_id = 0; - tile_h->isGround = 1; - tile_h->canBeMined = 0; + tile_h->playerOnTile = NULL; tile_h->nextRow = NULL; tile_h->nextColumn = NULL; - - return tile_h; } else if (prevHTile != NULL) { tile_h = calloc(1,sizeof(ARENA_H_TILE)); prevHTile->nextRow = tile_h; tile_h->type_id = 0; - tile_h->isGround = 1; - tile_h->canBeMined = 0; + tile_h->playerOnTile = NULL; tile_h->nextRow = NULL; tile_h->nextColumn = NULL; } - return NULL; + return tile_h; } ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) { @@ -41,8 +36,7 @@ ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) { tile_w = calloc(1,sizeof(ARENA_W_TILE)); prevHTile->nextColumn = tile_w; tile_w->type_id = 0; - tile_w->isGround = 1; - tile_w->canBeMined = 0; + tile_w->playerOnTile = NULL; tile_w->nextColumn = NULL; return tile_w; @@ -50,29 +44,28 @@ ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) { tile_w = calloc(1,sizeof(ARENA_W_TILE)); prevWTile->nextColumn = tile_w; tile_w->type_id = 0; - tile_w->isGround = 1; - tile_w->canBeMined = 0; + tile_w->playerOnTile = NULL; tile_w->nextColumn = NULL; } return NULL; } -ARENA_H_TILE* genNewArena(int w, int h) { +ARENA_H_TILE* genNewArena(int size_h, int size_w) { ARENA_H_TILE* arenaOrigin = NULL; ARENA_H_TILE* TmpCursor_h = NULL; ARENA_W_TILE* TmpCursor_w = NULL; int i,j; - for(i=0;inextColumn; } - - if (i!=0) TmpCursor_h = TmpCursor_h->nextRow; } return arenaOrigin; } -int deleteArena(ARENA_H_TILE* genNewArena) { + +/* + * Arena delete functions + */ +void deleteWTile(ARENA_W_TILE* WTile) { + if (WTile->nextColumn != NULL) { + deleteWTile(WTile->nextColumn); + } + + free(WTile); +} + +void deleteHTile(ARENA_H_TILE* HTile) { + if (HTile->nextRow != NULL) { + deleteHTile(HTile->nextRow); + } + + deleteWTile(HTile->nextColumn); + free(HTile); +} + +void deleteArena(ARENA_H_TILE* arena) { + deleteHTile(arena); +} + + + +/* + * Arena status functions + */ +int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) { + int type_id = -1; + int i; + + if (coord_y == 0) { + ARENA_H_TILE* tile_h = NULL; + + tile_h = arena; + if (coord_x != 0) { + for (i=0;inextRow; + } + } + + type_id = tile_h->type_id; + } else { + ARENA_W_TILE* tile_w = NULL; + ARENA_H_TILE* tile_h = NULL; + + tile_h = arena; + if (coord_x != 0) { + for (i=0;inextRow; + } + } + + tile_w = tile_h->nextColumn; + if (coord_y != 0) { + for (i=0;inextColumn; + } + } + + type_id = tile_w->type_id; + } + + return type_id; } diff --git a/arenaEngine.h b/arenaEngine.h index c9fe930..972bcaf 100644 --- a/arenaEngine.h +++ b/arenaEngine.h @@ -1,3 +1,5 @@ +#include "playerInterface.h" + #ifndef ARENAENGINE_H_ #define ARENAENGINE_H_ @@ -13,21 +15,32 @@ typedef struct items{ }ITEMS; */ -typedef struct arena_h_tile{ //Rows chained list +typedef struct tileType{ int type_id; //texture? int isGround; int canBeMined; +}TILE; + +typedef struct arena_h_tile{ //Rows chained list + int type_id; + PLAYER* playerOnTile; struct arena_h_tile *nextRow; struct arena_w_tile *nextColumn; }ARENA_H_TILE; typedef struct arena_w_tile{ //Columns chained list int type_id; - //texture? - int isGround; - int canBeMined; + PLAYER* playerOnTile; struct arena_w_tile *nextColumn; }ARENA_W_TILE; + +//Generation functions +ARENA_H_TILE* genNewArena(int size_h, int size_w); +void deleteArena(ARENA_H_TILE* arena); + +//Status functions +int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y); + #endif diff --git a/main.c b/main.c index 010ffc6..24ccd94 100644 --- a/main.c +++ b/main.c @@ -11,65 +11,50 @@ #include #include #include "logHelper.h" -#include "SDL2/SDL.h" -#include "SDL2/SDL_thread.h" -#include "SDL2/SDL_mutex.h" +#include +#include +#include #include "arenaEngine.h" -int main(void) -{ - SDL_Init(SDL_INIT_VIDEO); +#define A_HEIGHT 100 +#define A_WIDTH 100 - if (SDL_Init(SDL_INIT_VIDEO) != 0 ) - { - fprintf(stdout,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError()); - return -1; +void initDisplayLib() { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + addLogCritical("Init SDL libs failed !"); + + exit(EXIT_FAILURE); } - else - { - int continuer = 1; - int action; +} + +void initResources() { + //resOpen(); +} + +int main(int argc, char *argv[]) { + ARENA_H_TILE* arena = NULL; // Création de la fenêtre SDL_Window* pWindow = NULL; pWindow = SDL_CreateWindow("Arena Survival Tournament",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,640,480,SDL_WINDOW_SHOWN); + addLogInfo("Starting game..."); + initDisplayLib(); + initResources(); - SDL_Event event; // Cette variable servira plus tard à gérer les événements + addLogInfo("Creating new arena..."); + arena = genNewArena(A_HEIGHT, A_WIDTH); + if (arena == NULL) { + addLogCritical("Error with arena generator !"); + exit(EXIT_FAILURE); + } + addLogInfo("Successfully created arena."); - if( pWindow ) - { - SDL_Delay(3000); /* Attendre trois secondes, que l'utilisateur voie la fenêtre */ - while (continuer) - { - - action = PlayerInterface(); - if (action == -1) - { - continuer = 0; - } - else - { - - } + deleteArena(arena); + addLogInfo("Cleared arena."); - - } - //SDL_DestroyWindow(pWindow); - } - else - { - fprintf(stderr,"Erreur de création de la fenêtre: %s\n",SDL_GetError()); - } - } - - //IAEngine(); - - SDL_Quit(); - //PlayerInterface(); - - return 0; + return EXIT_SUCCESS; } diff --git a/menuGUI.c b/menuGUI.c index b433bec..52beb08 100644 --- a/menuGUI.c +++ b/menuGUI.c @@ -1,13 +1,6 @@ #include #include -#include "SDL2/SDL.h" - -void initDisplayLib() { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError()); - exit(EXIT_FAILURE); - } -} +#include int createGameMenuWindows() { if (SDL_Init(SDL_INIT_VIDEO) != 0) {