From 1d09e9f3f4f25227b15f2c0ebdc75aa4a9f7e76b Mon Sep 17 00:00:00 2001 From: Gladosse Date: Mon, 3 Jan 2022 20:16:07 +0100 Subject: [PATCH] Delete 'board.c' --- board.c | 214 -------------------------------------------------------- 1 file changed, 214 deletions(-) delete mode 100644 board.c diff --git a/board.c b/board.c deleted file mode 100644 index 9fcd93a..0000000 --- a/board.c +++ /dev/null @@ -1,214 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "board.h" - -extern bopti_image_t img_cursor; - -void set_board(struct Board *brd){ - int height = brd->height; - int width = brd->width; - - brd->board_state = malloc(sizeof(struct Cell*) * height); - for(int i=0; iboard_state[i] = malloc(sizeof(struct Cell) * width); - } - - for(int v=0;vboard_state[v][z].value=0; //assign all cells 0 (no mine) - brd->board_state[v][z].state=0; - brd->board_state[v][z].flagged=0; - } - } -} - -int around(int x, int y, int a, int b, struct Board* brd){ - int height = brd->height; - int width = brd->width; - for(int v=y-1;v<=y+1;v++){ - for(int z=x-1;z<=x+1;z++){ - if(z=0 && v>=0){ - if(z==a && v==b) - return 1; - } - } - } - return 0; -} - -void gen_board(int a, int b, struct Board *brd){ - int height = brd->height; - int width = brd->width; - - for(int i=0; inmines; i++){ - int y = rand()%brd->height; - int x = rand()%brd->width; - srand(rtc_ticks()); - while(brd->board_state[y][x].value==69 || around(a,b,x,y,brd)){ - y = rand()%brd->height; - x = rand()%brd->width; - } - brd->board_state[y][x].value=69; - - for(int v=y-1;v<=y+1;v++){ - for(int z=x-1;z<=x+1;z++){ - if(z=0 && v>=0){ - if(brd->board_state[v][z].value!=69) - brd->board_state[v][z].value++; - } - } - } - } -} - -void draw_board(struct Board *brd){ - extern bopti_image_t img_nums; - extern bopti_image_t img_bomb; - extern bopti_image_t img_desert_cell; - extern bopti_image_t img_flag; - int height = brd->height; - int width = brd->width; - - for(int y=0; yboard_state[y][x].state){ - int value = brd->board_state[y][x].value; - if(value==69){ - dsubimage(x*20+7,y*20+40,&img_bomb,0,0,20,20, DIMAGE_NONE); - }else if(value==0){ - dsubimage(x*20+7,y*20+40,&img_nums,160,0,180+20,20, DIMAGE_NONE); - } - else{ - if(x*20board_state[y][x].flagged==1){ - dsubimage(x*20+7,y*20+40,&img_flag,0,0,20,20, DIMAGE_NONE); - }else{ - dsubimage(x*20+7,y*20+40,&img_desert_cell,0,0,20,20,DIMAGE_NONE); - } - } - if(brd->board_state[y][x].flagged==1) - dsubimage(x*20+7,y*20+40,&img_flag,0,0,20,20, DIMAGE_NONE); - } - } - -} - -void draw_cursor(struct Board *brd){ - dimage(brd->pos[0]*20+7,brd->pos[1]*20+40,&img_cursor); -} - -int show_cell(int x,int y, struct Board *brd){ - int height = brd->height; - int width = brd->width; - if (x=0 && y>=0 && brd->board_state[y][x].flagged==0) - brd->board_state[y][x].state=1; - - if (brd->board_state[y][x].value==0) { // invisible - for (int v =y-1; v<=y+1;v++) { - for (int z=x-1;z<=x+1;z++) { - if (z=0 && v>=0 && brd->board_state[y][x].flagged==0) { - if (brd->board_state[v][z].value != 69 && brd->board_state[v][z].state == 0) { // not mine and not visible and not flagged - show_cell(z,v,brd); - } - } - } - } - } - return 0; -} - -int reveal(int x, int y, struct Board *brd){ - int height = brd->height; - int width = brd->width; - int flags = 0; - for(int v=y-1;v<=y+1;v++){ - for(int z=x-1;z<=x+1;z++){ - if(z=0 && v>=0){ - if(brd->board_state[v][z].flagged == 1) - flags++; - } - } - } - if(brd->board_state[y][x].value==flags && brd->board_state[y][x].value!=0){ - for(int v=y-1;v<=y+1;v++){ - for(int z=x-1;z<=x+1;z++){ - if(z=0 && v>=0){ - if(brd->board_state[v][z].flagged==0){ - brd->board_state[v][z].state=1; - if(brd->board_state[v][z].value==69) - return 1; - } - } - } - } - for(int v=y-1;v<=y+1;v++){ - for(int z=x-1;z<=x+1;z++){ - if(z=0 && v>=0){ - if(brd->board_state[v][z].state==1 && brd->board_state[v][z].value==0) - show_cell(z,v,brd); - } - } - } - } - return 0; -} - -void flag_cell(int x,int y, struct Board *brd){ - int height = brd->height; - int width = brd->width; - if (x=0 && y>=0 && brd->board_state[y][x].state==0) - brd->board_state[y][x].flagged=!brd->board_state[y][x].flagged; -} - - -void lose(int a, int b, struct Board *brd){ - extern bopti_image_t img_nums; - extern bopti_image_t img_bomb; - extern bopti_image_t img_desert_cell; - extern bopti_image_t img_flag; - extern bopti_image_t img_red_bomb; - extern bopti_image_t img_cross_bomb; - int height = brd->height; - int width = brd->width; - - for(int y=0; yboard_state[y][x].state){ - int value = brd->board_state[y][x].value; - if(value==69){ - dsubimage(x*20+7,y*20+40,&img_bomb,0,0,20,20, DIMAGE_NONE); - }else if(value==0){ - dsubimage(x*20+7,y*20+40,&img_nums,160,0,180+20,20, DIMAGE_NONE); - } - else{ - if(x*20board_state[y][x].flagged==1){ - if(brd->board_state[y][x].value==69) - dsubimage(x*20+7,y*20+40,&img_flag,0,0,20,20, DIMAGE_NONE); - else - dsubimage(x*20+7,y*20+40,&img_cross_bomb,0,0,20,20, DIMAGE_NONE); - }else if(brd->board_state[y][x].value==69){ - dsubimage(x*20+7,y*20+40,&img_bomb,0,0,20,20, DIMAGE_NONE); - } - else{ - dsubimage(x*20+7,y*20+40,&img_desert_cell,0,0,20,20,DIMAGE_NONE); - } - } - if(brd->board_state[y][x].flagged==1) - dsubimage(x*20+7,y*20+40,&img_flag,0,0,20,20, DIMAGE_NONE); - } - } - dsubimage(a*20+7,b*20+40,&img_red_bomb,0,0,20,20, DIMAGE_NONE); -} \ No newline at end of file