dev를 이용한 C언어 오목프로그램좀 도와주세요
하림
#includestdio.h
#includewindows.h
#includeconio.h
#includestdlib.h
void move_arrow_key(char key, int *x1, int *y1, int x_b, int y_b);
void gotoxy(int x, int y);
void draw_check01(int c, int r);
void game_control(void );
void display_stone(int matrix[][20][20]);
int judgement(int matrix[][20][20]);
int main(void )
{
game_control();
return 0;
}
void move_arrow_key(char key, int *x1, int *y1, int x_b, int y_b)
{
switch(key)
{
case 72:
(*y1)--; //위쪽(상) 방향의화살표키입력
if(*y11) *y1=1; //y좌표의최솟값
break;
case 75:
(*x1)-=2; //왼쪽(좌) 방향의화살표키입력
if(*x11) *x1=1; //x좌표의최솟값
break;
case 77:
(*x1)+=2; //오른쪽(우) 방향의화살표키입력
if(*x1x_b) *x1=x_b; //x좌표의최댓값
break;
case 80:
(*y1)++; //아래쪽(하) 방향의화살표키입력
if(*y1y_b) *y1=y_b; //y좌표의최댓값
break;
default:
return ;
}
}
void gotoxy(int x, int y)
{
coord pos = { x-1, y-1 };
setconsolecursorposition(getstdhandle(std_output_handle), pos);
}
void draw_check01(int c, int r)
{
int i, j;
unsigned char a=0xa6;
unsigned char b[12];
for(i=1;i12;i++)
b[i]=0xa0+i;
printf(%c%c, a, b[3]);
for(i=0;ic;i++)
printf(%c%c, a, b[8]);
printf(%c%c, a, b[4]);
printf(\n);
for(i=0;ir-1;i++)
{
printf(%c%c, a, b[7]);
for(j=0;jc;j++)
printf(%c%c, a, b[11]);
printf(%c%c, a, b[9]);
printf(\n);
}
printf(%c%c, a, b[6]);
for(i=0;i=0;ic;i++)
printf(%c%c, a, b[10]);
printf(%c%c, a, b[5]);
printf(\n);
}
//바둑판위에놓은돌을흑돌과백돌로구분하여출력하는함수
void display_stone(int matrix[][20][20])
{
int i, x, y;
char *stone[2]={○, ●};
for(i=0;i2;i++)
for(x=1;x20;x++)
for(y=1;y20;y++)
{
if(matrix[i][x][y]==1)
{
gotoxy(x*2-1, y);
printf(%s, stone[i]);
}
}
}
//번갈아가며흑백의바둑돌을놓는함수game_control
void game_control(void )
{
int x=1, y=1, other=0;
int matrix[2][20][20]={0};
char key, judge=0;
char *stone[2]={○,●};
do
{
gotoxy(1,1);
draw_check01(18,18);
gotoxy(x,y);
printf(%s, stone[other]);
display_stone(matrix);
gotoxy(1,20);
if(other)
printf(●차례입니다.);
else
printf(○차례입니다.);
gotoxy(1,21);
printf(방향키로움직이고스페이스키를누르시오);
key=_getch();
if(key==27) //esc 종료
exit(0);
else if(key==32) //스페이스라면
{
matrix[other][(x+1)/2][y]=1;
judge=judgement(matrix);
if(judge!=0)
{
gotoxy(1,20);
printf(☆★☆★축하합니다~~!! %s님이승리하셨습니다~!\n ,stone[other]);
exit(0);
}
other=1-other;
}
else if(key=72)
move_arrow_key(key, &x, &y, 37, 19);
}while(1);
}
int judgement(int matrix[][20][20])
{
int i, x, y;
int z, c[4]={0}; //현재점에서방향↓↘→↗바둑돌개수
for(i=0;i2;i++)
{
for(x=0;x16;x++)
{
for(y=0;y16;y++)
{
c[0]=0,c[1]=0,c[2]=0,c[3]=0;
for(z=0;z5;z++)
{
if(matrix[i][x][y+z]==1) //↓방향이연속개면
{
p; c[0]++;
if(c[0]==5)
return 1;
}
if(matrix[i][x+z][y+z]==1) //↘방향이연속개면
{
c[1]++;
if(c[1]==5)
return 1;
}
if(matrix[i][x+z][y]==1) //→방향이연속개면
{
c[2]++;
if(c[2]==5)
return 1;
}
if(matrix[i][x+z][y+4-z]==1) //↗방향이연속개면
{
c[3]++;
if(c[3]==5)
return 1;
}
}
}
}
}
system(pause);
return 0;
}
질문 제목 : 3*3 금지 규정을 입력하고싶은데 너무 어렵숩니다.
도와주세요.
질문 요약 :3*3 금지 규정을 입력하고싶은데 너무 어렵숩니다.
도와주세요.
질문 내용 : 3*3 금지 규정을 입력하고싶은데 너무 어렵숩니다.
도와주세요.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2685477 | 소수점이하 출력하는거요 | 널위해 | 2025-02-18 |
2685449 | printf배우고있는데요 궁금한게있어요 (8) | 꽃큰 | 2025-02-18 |
2685393 | c언어 질문이요.... | 붕붕 | 2025-02-18 |
2685365 | 윈도우7에서 visual studio c++6.0 (1) | 빛길 | 2025-02-17 |
2685317 | segmentation fault가 나요 | 가람 | 2025-02-17 |
2685292 | 다중스택질문 | 올해1살 | 2025-02-17 |
2685231 | C언어와 닷넷에 대해서 질문!! (2) | 설아 | 2025-02-16 |
2685206 | VisualBasic 과 DEV++ 의 장단점과 만든 파일 호환 가능하나요? | 에드워드 | 2025-02-16 |
2685154 | 배열 크기조절 | 해찬솔 | 2025-02-15 |
2685124 | 수정이거 제가 뭐가 잘못한거죠 ? | 아이돌 | 2025-02-15 |
2685096 | 포인터의 고수분들 모두 보세요!! 제발 ㅠ_ㅠ 헷갈려헷갈려..갈려헷.. (7) | 치킨마루 | 2025-02-15 |
2685045 | 전처리기 질문 | 치에미 | 2025-02-14 |
2685016 | 오류 좀 확인해 주시면 감사하겠습니다 | 초코맛사탕 | 2025-02-14 |
2684917 | 알고리즘을 이용한 행렬의 전치// 문제다운 문제네요. | 뿡뿡 | 2025-02-13 |
2684868 | 양방향 연결리스트에서 실행도중 죽는 이유좀 찾아주세요. (2) | 예다움 | 2025-02-13 |
2684844 | 시계프로그램인데 도저히 모르겠어요ㅠ (1) | 비내리던날 | 2025-02-12 |
2684812 | 레포트좀도와주세요ㅠㅠ (2) | 갈매빛 | 2025-02-12 |
2684780 | 채팅창 흉내내보려고하는데요 ㅜ.ㅜ (1) | 바름 | 2025-02-12 |
2684729 | 내일 시험인데 메모리 그리는것좀 도와주세요 ㅠ (1) | 상처주지마 | 2025-02-11 |
2684701 | 버퍼 관련 질문 3가지 (이전거랑 달라요) | 한국녀 | 2025-02-11 |