#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int map[11][11]={},i,j,mapp[11][11]={},allMax;
void view(){
allMax = 0;
for(int y=1;y<=9;y++){
for(int x=1;x<=9;x++){
if(mapp[y][x]==9)
printf("0 ");
else if(mapp[y][x]==0){
printf("_ ");
if(map[y][x]==0)
allMax++;
}
else
printf("%d ",mapp[y][x]);
}
printf("\n");
}
}
int find(int y,int x){
int max=0;
for(int yi=y-1;yi<=y+1;yi++)
{
for(int xi=x-1;xi<=x+1;xi++)
{
if(map[yi][xi]==1)
max++;
}
}
if(max==0)
return 9;
return max;
}
void DFS(int y,int x){
if(map[y][x]==2)
return ;
int c;
c=find(y,x);
mapp[y][x]=c;
map[y][x]=2;
if(c<9)
return ;
if(y<9) DFS(y+1,x);
if(y>1) DFS(y-1,x);
if(x<9) DFS(y,x+1);
if(x>1) DFS(y,x-1);
if(y>1){
if(x>1) DFS(y-1,x-1);
if(x<9) DFS(y-1,x+1);
}
if(y<9){
if(x>1) DFS(y+1,x-1);
if(x<9) DFS(y+1,x+1);
}
return ;
}
void main(){
int yrandom,xrandom,boom;
scanf("%d",&boom);
scanf("%d %d",&j,&i);
for (int l = 0; l< boom; l++){
srand(time(NULL));
yrandom = rand() % 9 + 1;
srand(time(NULL));
xrandom = rand() % 9 + 1;
if(i==yrandom&&j==xrandom)
l--;
else if(i==yrandom+1&&j==xrandom)
l--;
else if(i==yrandom-1&&j==xrandom)
l--;
else if(i==yrandom&&j==xrandom+1)
l--;
else if(i==yrandom&&j==xrandom-1)
l--;
else if(i==yrandom+1&&j==xrandom-1)
l--;
else if(i==yrandom+1&&j==xrandom+1)
l--;
else if(i==yrandom-1&&j==xrandom+1)
l--;
else if(i==yrandom-1&&j==xrandom-1)
l--;
else if(map[yrandom][xrandom]==0){
map[yrandom][xrandom]=1;
printf("roding.....\n");
}
else
l--;
}
while(1){
if(map[i][j]==1){
mapp[i][j]=-1;
view();
printf("\n\nLose");
return ;
}
DFS(i,j);
view();
if(allMax == 0){
printf("\n\nWin");
return ;
}
scanf("%d %d",&j,&i);
}
}
top of page

기능을 테스트하려면 라이브 사이트로 이동하세요.
수정: 2023년 11월 29일
지뢰 찾기 게임화 (시간 문제)
지뢰 찾기 게임화 (시간 문제)
댓글 0개
좋아요
댓글(0)
bottom of page