#include #include #include #include #include "raylib.h" #define ARRAT(arr, type, x, y) ((arr) + (y)*(type) + (x)) static inline int min(int a, int b) { return a < b ? a : b; } static inline int max(int a, int b) { return a > b ? a : b; } char game[16][30] = {0}; typedef enum GameType { BEGINNER, INTERMEDIATE, EXPERT, } GameType; typedef struct Vec2i { int x; int y; } Vec2i; Vec2i game_size; int nb_bomb; int screen_width = 500; int screen_height = 550; Rectangle menu; Vec2i nb_cell = {9, 9}; // 9-9 16-16 16-30 int grid_len = 0; Rectangle grid = {0}; Image tile_image_orig = {0}; Texture tile_texture = {0}; Image tile_hover_image_orig = {0}; Texture tile_hover_texture = {0}; Image mine_image_orig = {0}; Texture mine_texture = {0}; void screen_resize_handle(void) { screen_width = GetScreenWidth(); screen_height = GetScreenHeight(); menu.width = screen_width; grid_len = min(screen_width, screen_height - menu.height); grid = (Rectangle){ (screen_width - grid_len) / 2, screen_height - grid_len, grid_len, grid_len }; Image tile_copy = ImageCopy(tile_image_orig); ImageResize(&tile_copy, grid.width/nb_cell.x, grid.height/nb_cell.y); tile_texture = LoadTextureFromImage(tile_copy); Image tile_hover_copy = ImageCopy(tile_hover_image_orig); ImageResize(&tile_hover_copy, grid.width/nb_cell.x, grid.height/nb_cell.y); tile_hover_texture = LoadTextureFromImage(tile_hover_copy); Image mine_copy = ImageCopy(mine_image_orig); ImageResize(&mine_copy, grid.width/nb_cell.x, grid.height/nb_cell.y); mine_texture = LoadTextureFromImage(mine_copy); } void fill_game(GameType type) { memset(game, 0, 16*30); switch (type) { case BEGINNER: game_size.x = 9; game_size.y = 9; nb_bomb = 10; break; case INTERMEDIATE: game_size.x = 16; game_size.y = 16; nb_bomb = 40; break; case EXPERT: game_size.x = 16; game_size.y = 30; nb_bomb = 99; break; } for (int i=0; i game_size.x) continue; for (int j=-1; j<=1; j++) { if (y+j < 0 || y+j > game_size.y) continue; if (i == 0 && j == 0) continue; if (game[y+j][x+i] == 'X') count++; } } return count; } int main(void) { srand(time(NULL)); SetConfigFlags(FLAG_WINDOW_RESIZABLE); menu = (Rectangle){0, 0, screen_width, screen_height - screen_width}; tile_image_orig = LoadImage("ressources/tile.png"); tile_hover_image_orig = LoadImage("ressources/tile_hover.png"); mine_image_orig = LoadImage("ressources/mine.png"); InitWindow(screen_width, screen_height, "mineur"); SetTargetFPS(60); screen_resize_handle(); fill_game(BEGINNER); while (!WindowShouldClose()) { if (IsWindowResized()) screen_resize_handle(); BeginDrawing(); { ClearBackground(BLACK); if (IsKeyPressed(KEY_R)) { fill_game(BEGINNER); } DrawRectangleRec(menu, RED); DrawRectangleRec(grid, (Color) { .r = 0xFF, .g = 0xDA, .b = 0x2E, .a = 255 }); for (int x=0; x