c 오목 질문
별글
제가 오목을 숙제로 짜고 있습니다.판별은 되긴 되는데, 선배들 말이 5목 일때만 되야하고, 6목일때부터는 되지 않게 하라는군요..근데 아무리 해도 전 그렇게 못만들겟더라구요...소스는 밑에 복붙할게요..
/*여건이 되신다면 3*3 방지도 만들어주시면 안될까요? 그리고 마지막으로, 이미 놓은 돌에는 제가 못 놓게 하긴 햇는데, 문구를 띄울라 하거든요.. 근데 모두 gotoxy 로 쓴 지라, 한번만 띄우고 제대로 놓앗을땐 사라지게 하는 방법을 모르겟습니다.. 되신다면 알려주시면 감사하겟습니다... ㅠㅠ*/
----------------------------------------------------------------
#include stdio.h#include windows.h#include conio.h#define LEFT 75#define RIGHT 77#define UP 72#define DOWN 80char p1_name[100];char p2_name[100];int start();void drawingmap();void INPUTNAME();void REDWIN();void BLUEWIN();void EXPLAIN();enum{ BLACK, // 0 : 까망 DARK_BLUE, // 1 : 어두운 파랑 DARK_GREEN, // 2 : 어두운 초록 DARK_SKY_BLUE, // 3 : 어두운 하늘 DARK_RED, // 4 : 어두운 빨강 DARK_VIOLET, // 5 : 어두운 보라 DARK_YELLOW, // 6 : 어두운 노랑 GRAY, // 7 : 회색 DARK_GRAY, // 8 : 어두운 회색 BLUE, // 9 : 파랑 GREEN, // 10 : 초록 SKY_BLUE, // 11 : 하늘 RED, // 12 : 빨강 VIOLET, // 13 : 보라 YELLOW, // 14 : 노랑 WHITE, // 15 : 하양};
void gotoxy(int x, int y){ COORD Pos = {x*2, y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);}
void SetColor(int BK_Color, int FT_Color){ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BK_Color*16 + FT_Color);}
void main(void){ system(mode con lines=27 cols=43); //화면 크기 조절 start(); //시작 함수 시작}void EXPLAIN(){ system(cls); puts(게임하시는 방법은 아래와 같습니다.\n); Sleep(1500); puts(돌을 움직이시려면 \n방향키를 누르시면 됩니다.\n); Sleep(1500); puts(돌을 놓으시려면 \n엔터(Enter)를 누르시면 됩니다.\n); Sleep(1500); puts(흰돌은 빨강이며\n검은돌은 하늘색입니다\n헷갈리시면 안됩니다!\n); Sleep(1500); puts(게임에 시작하게 되시면 \n이름을 입력하시고 \n엔터(Enter)를 누르시면 됩니다.^^\n); Sleep(1500); puts(건투를 빕니다 ^^);
for(int i=3;i=1;i--){ gotoxy(2,18); printf(%d초후 게임이 시작됩니다., i); Sleep(i*1000); } return;}void INPUTNAME(){ system(cls); gotoxy(2, 11); printf(플레이어 1 (빨강팀) 이름 입력 : \n\t); gets(p1_name); fflush(stdin); system(cls); gotoxy(2,11); printf(플레이어 2 (파랑팀) 이름 입력 : \n\t); gets(p2_name); fflush(stdin); system(cls); //플레이어 2명의 이름을 받음}int start(){ char get; int point=1;
SetColor(BLACK,GREEN); gotoxy(8,11); printf([게임시작]); SetColor(BLACK,GRAY); gotoxy(8,12); printf( 게임설명); gotoxy(8,13); printf( 게임종료);//처음 출력 화면
while(1) { get = getch(); //키 입력 system(cls); //처음 출력 화면 삭제
switch(get) { case DOWN : point++; break; case UP: point--; break; }
if(point==4) point=1; else if (point==0) point=3; //아래로 3번 누를때 또는 위로 3번 누를때 순환(?) 하게 if(point==1) { SetColor(BLACK,GREEN); gotoxy(8,11); printf([게임시작]); SetColor(BLACK,GRAY); gotoxy(8,12); printf( 게임설명); gotoxy(8,13); printf( 게임종료);
if(get==13) break; } else if(point==2) { gotoxy(8,11); printf( 게임시작); gotoxy(8,12); SetColor(BLACK,GREEN); printf([게임설명]); SetColor(BLACK,GRAY); gotoxy(8,13); printf( 게임종료);
if(get==13) { EXPLAIN(); break; } } else if(point==3) { gotoxy(8,11); printf( 게임시작); gotoxy(8,12); printf( 게임설명); SetColor(BLACK,GREEN); gotoxy(8,13); printf([게임종료]); SetColor(BLACK,GRAY);
if(get==13) return 0; }
}
SetColor(BLACK,GRAY); INPUTNAME(); drawingmap();
return 0;}void drawingmap(){ int map[21][21]={0,}; int x=10, y=10; //시작 좌표 int count=1; char key; system(cls); SetColor(BLACK,GRAY); for(int i=0;i21;i++){ for(int j=0;j21;j++){ if((i==0 || i==20) || (j==0 || j==20)) { SetColor(BLACK,WHITE); printf(※); SetColor(BLACK,GRAY); //테두리 출력 } else if(i==x && j==y) { SetColor(BLACK,RED); printf(☆); SetColor(BLACK,GRAY); //처음출력 화면의 커서 위치 } else printf(┼); //기본 맵 출력 } puts(); }
gotoxy(0,22);
if(count==1) { SetColor(BLACK,RED); printf(\%s\님(빨강) 차례\t\t\t\t, p1_name); SetColor(BLACK,GRAY); }
while(1) { SetColor(BLACK,GRAY); key=getch(); gotoxy(x,y);
if(map[x][y]==0) printf(┼); if(map[x][y]==1) { SetColor(BLACK,RED); printf(○); SetColor(BLACK,GRAY); } if(map[x][y]==2) { SetColor(BLACK,SKY_BLUE); printf(○); SetColor(BLACK,GRAY); }
if(key==DOWN&&y19) y++; else if(key==LEFT&&x1) x--; else if(key==RIGHT&&x19) x++; else if(key==UP&&y1) y--; // 테두리 안에서만 움직이게 만듬
gotoxy(x,y);
if(count==1) { SetColor(BLACK,RED); printf(☆); SetColor(BLACK,GRAY); } if(count==2) { SetColor(BLACK,SKY_BLUE); printf(☆); SetColor(BLACK,GRAY); } // 흰색 검은색 돌 차례 바꾸기
if(count==1) { if(key==13&&(map[x][y]==0)) { map[x][y]=1; gotoxy(x,y); SetColor(BLACK,RED); printf(○); SetColor(BLACK,GRAY); count++; } } else if(count==2) { if(key==13&&(map[x][y]==0)) pre; { map[x][y]=2; gotoxy(x,y); SetColor(BLACK,SKY_BLUE); printf(○); SetColor(BLACK,GRAY); count=1; } }
gotoxy(0,22); if(count==1) { SetColor(BLACK,RED); printf(\%s\님(빨강) 차례\t\t\t\t, p1_name); SetColor(BLACK,GRAY); } else { SetColor(BLACK,SKY_BLUE); printf(\%s\님(파랑) 차례\t\t\t\t, p2_name); SetColor(BLACK,GRAY); }
for(int i=1;i20;i++){ for(int j=1;j20;j++){ if(map[i][j]==1 && map[i+1][j+1]==1 && map[i+2][j+2]==1 && map[i+3][j+3]==1 && map[i+4][j+4]==1) { REDWIN(); return; } else if(map[i][j]==1 && map[i-1][j+1]==1 && map[i-2][j+2]==1 && map[i-3][j+3]==1 && map[i-4][j+4]==1) { REDWIN(); return; } else if(map[i][j]==1 && map[i+1][j]==1 && map[i+2][j]==1 && map[i+3][j]==1 && map[i+4][j]==1) { REDWIN(); return; } else if(map[i][j]==1 && map[i][j+1]==1 && map[i][j+2]==1 && map[i][j+3]==1 && map[i][j+4]==1) { REDWIN(); return; } else if(map[i][j]==2 && map[i+1][j+1]==2 && map[i+2][j+2]==2 && map[i+3][j+3]==2 && map[i+4][j+4]==2) { BLUEWIN(); return; } else if(map[i][j]==2 && map[i-1][j+1]==2 && map[i-2][j+2]==2 && map[i-3][j+3]==2 && map[i-4][j+4]==2) { BLUEWIN(); return; } else if(map[i][j]==2 && map[i+1][j]==2 && map[i+2][j]==2 && map[i+3][j]==2 && map[i+4][j]==2) { BLUEWIN(); return;
} else if(map[i][j]==2 && map[i][j+1]==2 && map[i][j+2]==2 && map[i][j+3]==2 && map[i][j+4]==2) { BLUEWIN(); return; } } } }}
void REDWIN(){ gotoxy(0,24); SetColor(BLACK,RED); printf(\%s\님(빨강) 승리, p1_name); SetColor(BLACK,GRAY); gotoxy(0,25); printf(\n끝내시려면 아무키나 누르세요.\n); getch(); return;}void BLUEWIN(){ gotoxy(0,24); SetColor(BLACK,SKY_BLUE); printf(\%s\님(파랑) 승리, p2_name); SetColor(BLACK,GRAY); gotoxy(0,25); printf(\n끝내시려면 아무키나 누르세요.\n); getch(); return;}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2695766 | 달팽이 배열 어디서 틀렸는지 모르겠습니다ㅠㅠ | 연분홍 | 2025-05-23 |
2695738 | fopen과fclose질문~~ (5) | 희선 | 2025-05-23 |
2695707 | 3의 배수 나타내기. (2) | 수리 | 2025-05-23 |
2695626 | 피보나치수열 과제 때문에 질문 드립니다. (6) | 옆집언니 | 2025-05-22 |
2695595 | 포인트공부중입니다 int형에서 4=1 인가요? (3) | 족장 | 2025-05-22 |
2695567 | 드라이브 고유번호를 가져오는 함수 (2) | 초코맛사탕 | 2025-05-21 |
2695533 | 음수의 산술변환! 질문이요 ㅠㅠ... (4) | 꽃여름 | 2025-05-21 |
2695506 | 구조체 배열 이용 도서목록 출력 프로그램 (1) | 가을귀 | 2025-05-21 |
2695450 | c언어 함수 질문이요.... | 이슬비 | 2025-05-20 |
2695403 | VirtualAlloc함수 및 메모리 질문 | 크리에이터 | 2025-05-20 |
2695355 | c언어 for함수 | 미쿡 | 2025-05-19 |
2695327 | 안녕하세요 제가 이번에 좀 큰 프로그램을.. | 악당 | 2025-05-19 |
2695295 | mutex동기화의 thread기반 채팅 서버소스 질문입니다 | 그루터기 | 2025-05-19 |
2695270 | 질문이요..swap 관한겁니다..ㅠㅠ (3) | 콩알녀 | 2025-05-19 |
2695244 | 노땅초보궁금한게 하나 있는데요..반복문(while문)초보자질문 (6) | 큰꽃늘 | 2025-05-18 |
2695166 | do while 문 어떤것이잘못된건지 모르겠어요 (2) | 아이폰 | 2025-05-18 |
2695122 | 구조체에 대해 물어보고 싶은게 있습니다 ^^^.. (7) | 수련 | 2025-05-17 |
2695091 | txt 파일 입출력 후 2차 배열에 저장하기입니다. (3) | 헛장사 | 2025-05-17 |
2695063 | 수도요금 프로그램좀 짜주세요. | 시내 | 2025-05-17 |
2695033 | 답변좀요ㅠㅠ (1) | 비사벌 | 2025-05-16 |