#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
INPUT_RECORD rec;
DWORD dwNOER;
HANDLE CIN = 0;
int x,y,boom;
int map[31][31]={};
int mapp[31][31]={};
void click(int *xx, int *yy, int *lr){
while (1)
{
ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &rec, 1, &dwNOER); // 콘솔창 입력을 받아들임.
if (rec.EventType == MOUSE_EVENT) // 마우스 이벤트일 경우
{
if (rec.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED) // 좌측 버튼이 클릭되었을 경우
{
int mouse_x = rec.Event.MouseEvent.dwMousePosition.X; // X값 받아옴
int mouse_y = rec.Event.MouseEvent.dwMousePosition.Y; // Y값 받아옴
*xx=mouse_x; //x값을 넘김
*yy=mouse_y; //y값을 넘김
*lr=1; //마우스 클릭상태를 넘김
break;
}
else if(rec.Event.MouseEvent.dwButtonState & RIGHTMOST_BUTTON_PRESSED) // 우측 버튼이 클릭되었을 경우
{
int mouse_x = rec.Event.MouseEvent.dwMousePosition.X; // X값 받아옴
int mouse_y = rec.Event.MouseEvent.dwMousePosition.Y; // Y값 받아옴
*xx=mouse_x; //x값을 넘김
*yy=mouse_y; //y값을 넘김
*lr=2; //마우스 클릭상태를 넘김
break;
}
}
}
}
void xy(int i, int j){
//x, y 좌표 설정
COORD pos = { j,i };
//커서 이동
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void sleep(){
ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &rec, 1, &dwNOER);
while(rec.EventType == MOUSE_EVENT && rec.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED || rec.Event.MouseEvent.dwButtonState & RIGHTMOST_BUTTON_PRESSED)
{
ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &rec, 1, &dwNOER);
}
return ;
}
void view(){
xy(0,0);
for(int i = 0;i < y;i++){
for(int j = 0;j < x;j++){
if(map[i][j] == 0)
printf("[]");
}
printf("\n");
}
}
void ran(int boom_random,int a,int b){
int n = 0;
while(n < boom){
int i = rand() % y;
int j = rand() % x;
if(i == a && j == b)
return ;
if(map[i][j] == 0){
map[i][j] = 1;
n++;
}
}
}
void DFS(int i,int j){
if(i < 0 || j < 0 || i >= y || j >= x)
return ;
if(map[i][j] == 2)
return ;
int n = 0;
if(map[i+1][j] == 1) n++;
if(map[i-1][j] == 1) n++;
if(map[i][j+1] == 1) n++;
if(map[i][j-1] == 1) n++;
if(map[i+1][j+1] == 1) n++;
if(map[i-1][j-1] == 1) n++;
if(map[i+1][j-1] == 1) n++;
if(map[i-1][j+1] == 1) n++;
if(n == 0){
mapp[i][j] = n;
return ;
}
DFS(i+1,j);
DFS(i-1,j);
DFS(i,j+1);
DFS(i,j-1);
DFS(i+1,j+1);
DFS(i-1,j-1);
DFS(i+1,j-1);
DFS(i-1,j-1);
return ;
}
int main(){
srand(time(NULL));
int i=0,j=0,w=0;
printf("level\nhigh[] middle[] low[]\n");
while(1){
click(&j,&i,&w);
if(i != 1)
continue ;
if(j == 4||j == 5)
{
x=30;
y=16;
boom=99;
break ;
}
if(j == 13||j == 14)
{
x=16;
y=16;
boom=40;
break ;
}
if(j == 19||j == 20)
{
x=9;
y=9;
boom=10;
break ;
}
}
xy(0,0);
printf(" ");
view();
click(&j,&i,&w);
i /= 2;
ran(boom,i,j);
DFS(i,j);
}
top of page
실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
지뢰찾기
지뢰찾기
댓글 0개
좋아요
댓글(0)
bottom of page