From 3c5a3c0383ec4c1f09b50a5b5bd8a26c847cf600 Mon Sep 17 00:00:00 2001 From: valentin carmona Date: Thu, 17 Mar 2022 14:33:18 +0100 Subject: [PATCH 1/2] process en cours de completion --- model.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/model.c b/model.c index f39f724..9d06611 100644 --- a/model.c +++ b/model.c @@ -15,6 +15,18 @@ /* **************************************************************** */ +#define RESTART_UP "../img/restart_up.png" +#define RESTART_DOWN "../img/restart_down.png" +#define UNDO_UP "../img/undo_up.png" +#define UNDO_DOWN "../img/undo_down.png" +#define REDO_UP "../img/redo_up.png" +#define REDO_DOWN "../img/redo_down.png" +#define SOLVE_UP "../img/solve_up.png" +#define SOLVE_DOWN "../img/solve_down.png" + +/* **************************************************************** */ + + struct Env_t { game g; SDL_Texture** zero; // array of two texture one white and one red for each number (red color = r:255 g:50 b:50) @@ -23,14 +35,17 @@ struct Env_t { SDL_Texture** three; SDL_Texture** four; SDL_Texture** lightbulb; // array of the two lightbulb images first white second red - SDL_Texture* but_restart_up; - SDL_Texture* but_restart_down; - SDL_Texture* but_undo_up; - SDL_Texture* but_undo_down; - SDL_Texture* but_redo_up; - SDL_Texture* but_redo_down; - SDL_Texture* but_solve_up; - SDL_Texture* but_solve_down; + SDL_Texture* text_restart; + SDL_Texture* text_undo; + SDL_Texture* text_redo; + SDL_Texture* text_solve; + SDL_Rect* rec_redo; //rectangle of each buttons + SDL_Rect* rec_undo; + SDL_Rect* rec_restart; + SDL_Rect* rec_solve; + SDL_Rect* rec_game; //rectangle of the grid + SDL_Rect** tab_rec_game; //array of rectangles containing each square of the grid + uint size_game; //contain the number of squares in the game }; /* **************************************************************** */ @@ -166,11 +181,62 @@ bool process(SDL_Window* win, SDL_Renderer* ren, Env* env, SDL_Event* e) { #else else if (e->type == SDL_WINDOWEVENT) { - init(win, ren, w, h /*(w, h) a changer*/); + /*a changer en rapport avec le placement des boutons*/ } else if (e->type == SDL_MOUSEMOTION) { SDL_Point mouse; SDL_GetMouseState(&mouse.x, &mouse.y); + if(SDL_PointInRect(mouse, env->rec_restart)){ + env->text_restart = IMG_LoadTexture(ren, RESTART_DOWN); + if (!env->text_restart) ERROR("IMG_LoadTexture: %s\n", RESTART_DOWN); + } + else if(SDL_PointInRect(mouse, env->rec_undo)){ + env->text_undo = IMG_LoadTexture(ren, UNDO_DOWN); + if (!env->text_undo) ERROR("IMG_LoadTexture: %s\n", UNDO_DOWN); + } + else if(SDL_PointInRect(mouse, env->rec_redo)){ + env->text_redo = IMG_LoadTexture(ren, REDO_DOWN); + if (!env->text_redo) ERROR("IMG_LoadTexture: %s\n", REDO_DOWN); + } + else if(SDL_PointInRect(mouse, env->rec_sove)){ + env->text_solve = IMG_LoadTexture(ren, SOLVE_DOWN); + if (!env->text_solve) ERROR("IMG_LoadTexture: %s\n", SOLVE_DOWN); + }else{ + env->text_restart = IMG_LoadTexture(ren, RESTART_UP); + if (!env->text_restart) ERROR("IMG_LoadTexture: %s\n", RESTART_UP); + env->text_undo = IMG_LoadTexture(ren, UNDO_UP); + if (!env->text_undo) ERROR("IMG_LoadTexture: %s\n", UNDO_UP); + env->text_redo = IMG_LoadTexture(ren, REDO_UP); + if (!env->text_redo) ERROR("IMG_LoadTexture: %s\n", REDO_UP); + env->text_solve = IMG_LoadTexture(ren, SOLVE_UP); + if (!env->text_solve) ERROR("IMG_LoadTexture: %s\n", SOLVE_UP); + } } else if (e->type == SDL_MOUSEBUTTONDOWN) { + SDL_Point mouse; + SDL_GetMouseState(&mouse.x, &mouse.y); + if(SDL_PointInRect(mouse, env->rec_restart)){ + game_restart(env->g); + } + else if(SDL_PointInRect(mouse, env->rec_undo)){ + game_undo(env->g); + } + else if(SDL_PointInRect(mouse, env->rec_redo)){ + game_redo(env->g); + } + else if(SDL_PointInRect(mouse, env->rec_sove)){ + game_solve(env->g); + }else if (SDL_PointInRect(mouse, env->rec_game)){ + for(uint ind = 0; i < env->size; ind++){ + uint i = ind%(env->g->height); + uint j = ind/(env->g->width); + if(SDL_PointInRect(mouse, env->tab_rec_game[ind])){ + if(game_is_blank(env->g, i, j)){ + game_play_move(env->g, i, j, S_LIGHTBULB); + }else if(game_is_lightbulb(env->g, i, j)){ + game_play_move(env->g, i, j, S_BLANK); + } + } + } + } } #endif return false; From 9a439ac59123818ef0c23cd7654f283a5093b121 Mon Sep 17 00:00:00 2001 From: valentin carmona Date: Thu, 17 Mar 2022 14:38:23 +0100 Subject: [PATCH 2/2] clang de con --- model.c | 71 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/model.c b/model.c index 9d06611..ad597ee 100644 --- a/model.c +++ b/model.c @@ -26,7 +26,6 @@ /* **************************************************************** */ - struct Env_t { game g; SDL_Texture** zero; // array of two texture one white and one red for each number (red color = r:255 g:50 b:50) @@ -39,13 +38,13 @@ struct Env_t { SDL_Texture* text_undo; SDL_Texture* text_redo; SDL_Texture* text_solve; - SDL_Rect* rec_redo; //rectangle of each buttons + SDL_Rect* rec_redo; // rectangle of each buttons SDL_Rect* rec_undo; SDL_Rect* rec_restart; SDL_Rect* rec_solve; - SDL_Rect* rec_game; //rectangle of the grid - SDL_Rect** tab_rec_game; //array of rectangles containing each square of the grid - uint size_game; //contain the number of squares in the game + SDL_Rect* rec_game; // rectangle of the grid + SDL_Rect** tab_rec_game; // array of rectangles containing each square of the grid + uint size_game; // contain the number of squares in the game }; /* **************************************************************** */ @@ -185,53 +184,55 @@ bool process(SDL_Window* win, SDL_Renderer* ren, Env* env, SDL_Event* e) { } else if (e->type == SDL_MOUSEMOTION) { SDL_Point mouse; SDL_GetMouseState(&mouse.x, &mouse.y); - if(SDL_PointInRect(mouse, env->rec_restart)){ + if (SDL_PointInRect(mouse, env->rec_restart)) { env->text_restart = IMG_LoadTexture(ren, RESTART_DOWN); - if (!env->text_restart) ERROR("IMG_LoadTexture: %s\n", RESTART_DOWN); - } - else if(SDL_PointInRect(mouse, env->rec_undo)){ + if (!env->text_restart) + ERROR("IMG_LoadTexture: %s\n", RESTART_DOWN); + } else if (SDL_PointInRect(mouse, env->rec_undo)) { env->text_undo = IMG_LoadTexture(ren, UNDO_DOWN); - if (!env->text_undo) ERROR("IMG_LoadTexture: %s\n", UNDO_DOWN); - } - else if(SDL_PointInRect(mouse, env->rec_redo)){ + if (!env->text_undo) + ERROR("IMG_LoadTexture: %s\n", UNDO_DOWN); + } else if (SDL_PointInRect(mouse, env->rec_redo)) { env->text_redo = IMG_LoadTexture(ren, REDO_DOWN); - if (!env->text_redo) ERROR("IMG_LoadTexture: %s\n", REDO_DOWN); - } - else if(SDL_PointInRect(mouse, env->rec_sove)){ + if (!env->text_redo) + ERROR("IMG_LoadTexture: %s\n", REDO_DOWN); + } else if (SDL_PointInRect(mouse, env->rec_sove)) { env->text_solve = IMG_LoadTexture(ren, SOLVE_DOWN); - if (!env->text_solve) ERROR("IMG_LoadTexture: %s\n", SOLVE_DOWN); - }else{ + if (!env->text_solve) + ERROR("IMG_LoadTexture: %s\n", SOLVE_DOWN); + } else { env->text_restart = IMG_LoadTexture(ren, RESTART_UP); - if (!env->text_restart) ERROR("IMG_LoadTexture: %s\n", RESTART_UP); + if (!env->text_restart) + ERROR("IMG_LoadTexture: %s\n", RESTART_UP); env->text_undo = IMG_LoadTexture(ren, UNDO_UP); - if (!env->text_undo) ERROR("IMG_LoadTexture: %s\n", UNDO_UP); + if (!env->text_undo) + ERROR("IMG_LoadTexture: %s\n", UNDO_UP); env->text_redo = IMG_LoadTexture(ren, REDO_UP); - if (!env->text_redo) ERROR("IMG_LoadTexture: %s\n", REDO_UP); + if (!env->text_redo) + ERROR("IMG_LoadTexture: %s\n", REDO_UP); env->text_solve = IMG_LoadTexture(ren, SOLVE_UP); - if (!env->text_solve) ERROR("IMG_LoadTexture: %s\n", SOLVE_UP); + if (!env->text_solve) + ERROR("IMG_LoadTexture: %s\n", SOLVE_UP); } } else if (e->type == SDL_MOUSEBUTTONDOWN) { SDL_Point mouse; SDL_GetMouseState(&mouse.x, &mouse.y); - if(SDL_PointInRect(mouse, env->rec_restart)){ + if (SDL_PointInRect(mouse, env->rec_restart)) { game_restart(env->g); - } - else if(SDL_PointInRect(mouse, env->rec_undo)){ + } else if (SDL_PointInRect(mouse, env->rec_undo)) { game_undo(env->g); - } - else if(SDL_PointInRect(mouse, env->rec_redo)){ + } else if (SDL_PointInRect(mouse, env->rec_redo)) { game_redo(env->g); - } - else if(SDL_PointInRect(mouse, env->rec_sove)){ + } else if (SDL_PointInRect(mouse, env->rec_sove)) { game_solve(env->g); - }else if (SDL_PointInRect(mouse, env->rec_game)){ - for(uint ind = 0; i < env->size; ind++){ - uint i = ind%(env->g->height); - uint j = ind/(env->g->width); - if(SDL_PointInRect(mouse, env->tab_rec_game[ind])){ - if(game_is_blank(env->g, i, j)){ + } else if (SDL_PointInRect(mouse, env->rec_game)) { + for (uint ind = 0; i < env->size; ind++) { + uint i = ind % (env->g->height); + uint j = ind / (env->g->width); + if (SDL_PointInRect(mouse, env->tab_rec_game[ind])) { + if (game_is_blank(env->g, i, j)) { game_play_move(env->g, i, j, S_LIGHTBULB); - }else if(game_is_lightbulb(env->g, i, j)){ + } else if (game_is_lightbulb(env->g, i, j)) { game_play_move(env->g, i, j, S_BLANK); } }