diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index 387bc13..fe2dfdf 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -58,16 +58,17 @@ int main(int argc, char *argv[]) { size_t nbPlayers = 2; Player* players = (Player*)malloc(sizeof(Player)*2); - players[0] = newPlayer("Bépo", PlayerViolet); - players[1] = newPlayer("Azeryty", PlayerYellow); + /*players[0] = newPlayer("Bépo", PlayerViolet); + players[1] = newPlayer("Azeryty", PlayerYellow);*/ //players[2] = newPlayer("Adcsg", PlayerRed); - //bool crashed = gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH, &players, &nbPlayers); + bool crashed = gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH, &players, &nbPlayers); - /* if (crashed) { + if (crashed) { fprintf(stderr,"sorry"); exit(-1); - }*/ + } + generalState = GS_Game; gameView(&generalState, window, renderer, players, nbPlayers); diff --git a/Pontu/entryPoints/test.c b/Pontu/entryPoints/test.c index 5f8258d..4b2780a 100644 --- a/Pontu/entryPoints/test.c +++ b/Pontu/entryPoints/test.c @@ -7,7 +7,7 @@ //#include "../test/testDrawMainMenu.c //#include "../test/testSettingsView.c" #include "../test/testCreationMenu.c" -#include "../test/testGameInterface.c" +//#include "../test/testGameInterface.c" //#include "../test/testConnectionMenu.c" //#include "../test/testDrawMainMenu.c" //#include "../test/testSettingsView.c" @@ -26,10 +26,10 @@ int main(int argc, char *argv[]) { //testConnectionMenu(); //testMenuEndGame(); //testButton(); - testGameInterface(); + //testGameInterface(); //testConnectionMenu(); //testDrawMainMenu(); - //testCreationMenu(); + testCreationMenu(); //testSettingsView(); return 0; diff --git a/Pontu/include/engine/Colors.h b/Pontu/include/engine/Colors.h index 83c5e6b..e9b6df3 100644 --- a/Pontu/include/engine/Colors.h +++ b/Pontu/include/engine/Colors.h @@ -7,9 +7,7 @@ extern const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND; extern const SDL_Color COLOR_GENERIC_BUTTON_BORDER; extern const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND_HOVER; -extern const SDL_Color PLAYER_ONE_COLOR; -extern const SDL_Color PLAYER_TWO_COLOR; -extern const SDL_Color PLAYER_THREE_COLOR; -extern const SDL_Color PLAYER_FOUR_COLOR; +extern const SDL_Color PLAYER_SDL_COLORS[]; + #endif diff --git a/Pontu/include/model/PlayersColors.h b/Pontu/include/model/PlayersColors.h index 50a3aa9..a824209 100644 --- a/Pontu/include/model/PlayersColors.h +++ b/Pontu/include/model/PlayersColors.h @@ -1,11 +1,20 @@ #ifndef PLAYERS_COLORS_INCLUDED #define PLAYERS_COLORS_INCLUDED + +#define MACRO_FOR_EACH_PLAYER_COLOR(M) \ + M(Red) \ + M(Violet) \ + M(Blue) \ + M(Yellow) + +#define MACRO_GEN_ENUM_PLAYER_COLOR(Elem) Player##Elem, + typedef enum { - PlayerRed, - PlayerViolet, - PlayerBlue, - PlayerYellow + MACRO_FOR_EACH_PLAYER_COLOR(MACRO_GEN_ENUM_PLAYER_COLOR) + NB_PLAYER_COLORS } PlayersColors; +extern const PlayersColors playersColors[]; + #endif //PLAYERS_COLORS_INCLUDED diff --git a/Pontu/include/view/GameCreationMenu.h b/Pontu/include/view/GameCreationMenu.h index 98522e1..eb7de43 100644 --- a/Pontu/include/view/GameCreationMenu.h +++ b/Pontu/include/view/GameCreationMenu.h @@ -30,7 +30,7 @@ typedef struct typedef struct { Player* p; - SDL_Color color; + PlayersColors color; } ChangeColorParams; typedef struct diff --git a/Pontu/src/engine/Colors.c b/Pontu/src/engine/Colors.c index 1204c9b..de1dfc5 100644 --- a/Pontu/src/engine/Colors.c +++ b/Pontu/src/engine/Colors.c @@ -4,7 +4,10 @@ const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND = {225, 225, 225, 255}; const SDL_Color COLOR_GENERIC_BUTTON_BORDER = {10, 10, 10, 255}; const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND_HOVER = {250, 250, 250, 255}; -const SDL_Color PLAYER_ONE_COLOR = {166, 58, 252, 255}; -const SDL_Color PLAYER_TWO_COLOR = {14, 159, 100, 255}; -const SDL_Color PLAYER_THREE_COLOR = {240, 45, 45, 255}; -const SDL_Color PLAYER_FOUR_COLOR = {255, 255, 255, 255}; +const SDL_Color PLAYER_SDL_COLORS[] = {//Order mater (need to be the same as in model/PlayersColors.h) + {241, 0, 4 , 255}, // Red + {175, 0, 202, 255}, // Violet + {6 , 0, 202, 255}, // Blue + {202, 152, 0, 255}, // Yellow +}; + diff --git a/Pontu/src/model/PlayersColors.c b/Pontu/src/model/PlayersColors.c new file mode 100644 index 0000000..67486b7 --- /dev/null +++ b/Pontu/src/model/PlayersColors.c @@ -0,0 +1,6 @@ +#include "model/PlayersColors.h" + + +const PlayersColors playersColors[] = { + MACRO_FOR_EACH_PLAYER_COLOR(MACRO_GEN_ENUM_PLAYER_COLOR) +}; diff --git a/Pontu/src/view/GameCreationMenu.c b/Pontu/src/view/GameCreationMenu.c index 5bc2912..327b75f 100644 --- a/Pontu/src/view/GameCreationMenu.c +++ b/Pontu/src/view/GameCreationMenu.c @@ -107,12 +107,7 @@ CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int int const hColorBtn = 32; int const colorBtnXMargin = 8; SDL_Texture* btnTexture, *btnTextureHover; - SDL_Color const colors[NB_COLORS]= { - PLAYER_ONE_COLOR, - PLAYER_TWO_COLOR, - PLAYER_THREE_COLOR, - PLAYER_FOUR_COLOR - }; + P_Button* colorsBtn = (P_Button*) malloc(sizeof(P_Button)*NB_COLORS); P_Button ai = createButton(NULL, NULL, xmin, y, 0, 0, NULL); @@ -134,11 +129,11 @@ CreateMenuLine createCreateMenuLine(SDL_Renderer* renderer, int xmin, int y, int { params = (ChangeColorParams*) malloc(sizeof(ChangeColorParams)); params->p = player; - params->color=colors[i]; + params->color=playersColors[i]; colorsBtn[i] = createButton(NULL, NULL, xmax-wColorBtn*(i+1), y, wColorBtn, hColorBtn, changePlayerColor); colorsBtn[i].arg = params; - btnTexture = createGenericButtonTexture("", font, 0, COLOR_GENERIC_BUTTON_BORDER, colors[i], 4, 8, NULL, NULL, renderer); - btnTextureHover = createGenericButtonTexture("", font, 0, COLOR_GENERIC_BUTTON_BACKGROUND, colors[i], 4, 8, NULL, NULL, renderer); + btnTexture = createGenericButtonTexture("", font, 0, COLOR_GENERIC_BUTTON_BORDER, PLAYER_SDL_COLORS[i], 4, 8, NULL, NULL, renderer); + btnTextureHover = createGenericButtonTexture("", font, 0, COLOR_GENERIC_BUTTON_BACKGROUND, PLAYER_SDL_COLORS[i], 4, 8, NULL, NULL, renderer); colorsBtn[i].texture = btnTexture; colorsBtn[i].hoverTexture = btnTextureHover;