테트리스 문제점좀 지적해주세요..
아더
테트리스 게임 프로젝트 코딩 하던 중
답지와 차이가 나는 부분이 궁금해서 질문 드립니다.
우선 답지에는
static int CurPosX;
static int CurPosY;
static int BlockIdx;
static int RotateIdx;
void InitBlockPos(int x, int y)
{
if(x0 || y0)
return ;
CurPosX=x;
CurPosY=y;
SetCurrentCursorPos(CurPosX, CurPosY);
}
void ChooseBlock(void)
{
srand((unsigned int)time(NULL));
BlockIdx=(rand()%NUM_OF_BLOCK)*4;
}
int GetCurrentBlockIdx(void)
{
return BlockIdx+RotateIdx;
}
void BlockDown(void)
{
DeleteBlock(blockModel[GetCurrentBlockIdx()]);
CurPosY+=1;
SetCurrentCursorPos(CurPosX, CurPosY);
ShowBlock(blockModel[GetCurrentBlockIdx()]);
}
void DeleteBlock(char blockModel[][4])
{
int y,x;
point curPos=GetCurrentCursorPos();
for(y=0; y4; y++)
{
for(x=0; x4; x++)
{
SetCurrentCursorPos(curPos.x+(2*x), curPos.y+y);
if(blockModel[y][x]==1)
printf( );
}
}
SetCurrentCursorPos(curPos.x, curPos.y);
}
void ShowBlock(char blockModel[][4])
{
int y,x;
point curPos=GetCurrentCursorPos();
for(y=0; y4; y++)
{
for(x=0; x4; x++)
{
SetCurrentCursorPos(curPos.x+(2*x),curPos.y+y);
if(blockModel[y][x]==1)
printf(■);
}
}
SetCurrentCursorPos(curPos.x, curPos.y);
}
void BlockLeftRotate(void)
{
int nextRotSte;
DeleteBlock(blockModel[GetCurrentBlockIdx()]);
nextRotSte=RotateIdx+1;
nextRotSte%=4;
RotateIdx=nextRotSte;
SetCurrentCursorPos(CurPosX, CurPosY);
ShowBlock(blockModel[GetCurrentBlockIdx()]);
}
void BlockLeftMove(void)
{
DeleteBlock(blockModel[GetCurrentBlockIdx()]);
CurPosX-=2;
SetCurrentCursorPos(CurPosX, CurPosY);
ShowBlock(blockModel[GetCurrentBlockIdx()]);
}
void BlockRightMove(void)
{
DeleteBlock(blockModel[GetCurrentBlockIdx()]);
CurPosX+=2;
SetCurrentCursorPos(CurPosX, CurPosY);
ShowBlock(blockModel[GetCurrentBlockIdx()]);
}
답지에는 빨간 부분과 같이 인덱스를 함수 리턴값으로 받아서 작동하게 하더라구요..
답지대로 하니깐 문제없이 수행은 잘 되구요........
저는
static int CurPosX;
static int CurPosY;
static int BlockIdx;
static int RotateIdx;
void InitBlockPos(int x, int y)
{
if(x0 || y0)
return ;
CurPosX=x;
CurPosY=y;
SetCurrentCursorPos(CurPosX, CurPosY);
}
void ChooseBlock(void)
{
srand((unsigned int)time(NULL));
BlockIdx=(rand()%NUM_OF_BLOCK)*4;
}
int GetCurrentBlockIdx(void)
{
return BlockIdx+RotateIdx;
} 저는 이 함수는 쓰지 않았고 대신 전역 변수를 사용해서 코딩을 해보았습니다.
void BlockDown(void)
{
DeleteBlock(blockModel[BlockIdx]);
CurPosY+=1;
SetCurrentCursorPos(CurPosX, CurPosY);
ShowBlock(blockModel[BlockIdx]);
}
void DeleteBlock(char blockModel[][4])
{
int y,x;
point curPos=GetCurrentCursorPos();
for(y=0; y4; y++)
{
for(x=0; x4; x++)
{
SetCurrentCursorPos(curPos.x+(2*x), curPos.y+y);
if(blockModel[y][x]==1)
printf( );
}
}
SetCurrentCursorPos(curPos.x, curPos.y);
}
void ShowBlock(char blockModel[][4])
{
int y,x;
point curPos=GetCurrentCursorPos();
for(y=0; y4; y++)
{
for(x=0; x4; x++)
{
SetCurrentCursorPos(curPos.x+(2*x),curPos.y+y);
if(blockModel[y][x]==1)
printf(■);
}
}
SetCurrentCursorPos(curPos.x, curPos.y);
}
void BlockLeftRotate(void)
{
int nextRotSte;
DeleteBlock(blockModel[BlockIdx+RotateIdx]);
nextRotSte=RotateIdx+1;
nextRotSte%=4;
RotateIdx=nextRotSte;
SetCurrentCursorPos(CurPosX, CurPosY);
ShowBlock(blockModel[BlockIdx+RotateIdx]);
}
void BlockLeftMove(void)
{
DeleteBlock(blockModel[BlockIdx+RotateIdx]);
CurPosX-=2;
SetCurrentCursorPos(CurPosX, CurPosY);
ShowBlock(blockModel[BlockIdx+RotateIdx]);
}
void BlockRightMove(void)
{
DeleteBlock(blockModel[BlockIdx+RotateIdx]);
CurPosX+=2;
SetCurrentCursorPos(CurPosX, CurPosY);
ShowBlock(blockModel[BlockIdx+RotateIdx]);
}
저는 이렇게 해서 해봤는데 결과가
블록 방향을 바꾸면 처음에 바꼇다가 원래대로 되돌아 오는 문제가 발생하더라구요..
어떤 문제가 있어서 그렇게 되는지 잘 모르겠어서 질문드립니다.
p?
고수님들의 가르침 부탁드립니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |