숫자 퍼즐게임 도와주세요ㅠㅠㅠㅠㅠ
꺄홋
질문 제목 : 숫자퍼즐게임 질문질문 요약 :왜 움직임에 에러가 나는거죠 어디가 문제인가요??질문 내용 :
#include stdio.h
#include conio.h
#include time.h
#include stdlib.h
#include windows.h
#define left 75
#define right 77
#define up 70
#define down 80
void map();
void mix(int x[3][3]);
void draw();
void move();
void gotoxy(int x,int y);
void blank(int x[3][3]);
int main()
{
int answer[3][3]={{1,2,3},{4,5,6},{7,8,0}};
int puz[3][3];
char insert;
mix(puz);
while(1)
{
gotoxy(0,0);
map();
draw(puz);
blank(puz);
insert=getch();
move(insert,puz);}
return 0;
}
void move(char c,int x[3][3])
{
int i,j,y,z,temp;
for(i=0;i3;i++)
{
for(j=0;j3;j++)
{
if(x[i][j]==0)
{
y=i;
z=j;
}
}
}
switch(c)
{
case left:
if(z==0)
{
break;
}
temp=x[y][z];
x[y][z]=x[y][z+1];
x[y][z+1]=temp;
break;
case right:
if(z==2)
{
break;
}
temp=x[y][z];
x[y][z]=x[y][z-1];
x[y][z-1]=temp;
break;
case up:
if(y==0)
{
break;
}
temp=x[y][z];
x[y][z]=x[y+1][z];
x[y+1][z]=temp;
break;
case down:
if(y==2)
{
break;
}
temp=x[y][z];
x[y][z]=x[y-1][z];
x[y-1][z]=temp;
break;
}
}
void mix(int x[3][3])
{
int i,j;
int num=0;
int random;
srand(time(null));
random=rand();
for(i=0;i3;i++)
{
for(j=0;j3;j++)
{
x[i][j]=(random+num)%9;num+=7;
}}
}
void gotoxy(int x,int y)
{
coord cur;
cur.x=x;
cur.y=y;
setconsolecursorposition(getstdhandle(std_output_handle),cur);
}
void map()
{
printf(┌────────────┐\n);
printf(│┌──┐┌──┐┌──┐│\n);
printf(││ ││ ││ ││\n);
printf(│└──┘└──┘└──┘│\n);
printf(│┌──┐┌──┐┌──┐│\n);
printf(││ ││ ││ ││\n);
printf(│└──┘└──┘└──┘│\n);
printf(│┌──┐┌──┐┌──┐│\n);
printf(││ ││ ││ ││\n);
printf(│└──┘└──┘└──┘│\n);
printf(└────────────┘\n);
}
void draw(int x[3][3])
{
int i,j;
gotoxy(6,2);
printf(%d,x[0][0]);
gotoxy(14,2);
printf(%d,x[0][1]);
gotoxy(22,2);
printf(%d,x[0][2]);
gotoxy(6,5);
printf(%d,x[1][0]);
gotoxy(14,5);
printf(%d,x[1][1]);
gotoxy(22,5);
printf(%d,x[1][2]);
gotoxy(6,8);
printf(%d,x[2][0]);
gotoxy(14,8);
printf(%d,x[2][1]);
gotoxy(22,8);
printf(%d,x[2][2]);
}
void blank(int x[3][3])
{
if(x[0][0]==0)br]==0)
{
gotoxy(3,2);
printf( );
gotoxy(3,1);
printf( );
gotoxy(3,3);
printf( );
}
if(x[0][1]==0)
{
gotoxy(11,2);
printf( );
gotoxy(11,1);
printf( );
gotoxy(11,3);
printf( );
}
if(x[0][2]==0)
{
gotoxy(19,2);
printf( );
gotoxy(19,1);
printf( );
gotoxy(19,3);
printf( );
}
if(x[1][0]==0)
{
gotoxy(3,5);
printf( );
gotoxy(3,4);
printf( );
gotoxy(3,6);
printf( );
}
if(x[1][1]==0)
{
gotoxy(11,5);
printf( );
gotoxy(11,4);
printf( );
gotoxy(11,6);
printf( );
}
if(x[1][2]==0)
{
gotoxy(19,5);
printf( );
gotoxy(19,4);
printf( );
gotoxy(19,6);
printf( );
}
if(x[2][0]==0)
{
gotoxy(3,8);
printf( );
gotoxy(3,7);
printf( );
gotoxy(3,9);
printf( );
}
if(x[2][1]==0)
{
gotoxy(11,8);
printf( );
gotoxy(11,7);
printf( );
gotoxy(11,9);
printf( );
}
if(x[2][2]==0)
{
gotoxy(19,8);
printf( );
gotoxy(19,7);
printf( );
gotoxy(19,9);
printf( );
}
}
| 번호 | 제 목 | 글쓴이 | 날짜 |
|---|---|---|---|
| 2752142 | 더블 포인터 관련 최대최소값 구하기 (2) | 풀잎 | 2026-10-21 |
| 2752115 | c언어 이상한질문 (4) | 모드니 | 2026-10-21 |
| 2752085 | 문자열을 랜덤하게 출력해서 대체,삽입,삭제 횟수를 각가 표시하고 그걸 표 형태로 출력 | 슬아s | 2026-10-20 |
| 2752056 | 포인터 && 배열 질문요~ (2) | 해찬나래 | 2026-10-20 |
| 2752031 | x^n 구하는 코드 짜봤는데 값이 틀려요 ㅠㅠ | 세실 | 2026-10-20 |
| 2752000 | 나 정말 미치겠어요..ㅠㅜ (4) | 다이 | 2026-10-20 |
| 2751978 | 문자열 질문이요.. | 초시계 | 2026-10-19 |
| 2751945 | 숫자 맞추는 프로그램이요 ㅠㅠ (1) | 동은 | 2026-10-19 |
| 2751917 | C언어 이중 연결 관련 질문합니다. | 유우 | 2026-10-19 |
| 2751888 | return의 정확한 의미좀 알려주세요 (3) | 올해1살 | 2026-10-19 |
| 2751857 | 포인터 배열 (2) | 터큰 | 2026-10-18 |
| 2751831 | 연산자? 질문입니다 (2) | 진주 | 2026-10-18 |
| 2751800 | C언어 기초질문입니다.. (3) | 핫블랙 | 2026-10-18 |
| 2751739 | 파일 출력을 구조체로 받을 때, 파일의 끝을 판별하는 방법을 알려주세요. (2) | 얼 | 2026-10-17 |
| 2751715 | unresolved external symbol 에러... | 이룩 | 2026-10-17 |
| 2751686 | 변수 설정에 관한 질문입니다. | 꽃달 | 2026-10-17 |
| 2751655 | 자료구조 연습문제 | 한무릎 | 2026-10-17 |
| 2751631 | gets 함수 질문이요. (4) | 해늘 | 2026-10-16 |
| 2751553 | 퀵정렬 소스인데 주석좀 달아주세요 (1) | 싴흐한세여니 | 2026-10-16 |
| 2751528 | 저기 이거하는법좀 질문.. (2) | 가람슬기 | 2026-10-15 |
