테트리스 문제점좀 지적해주세요..
아더
테트리스 게임 프로젝트 코딩 하던 중
답지와 차이가 나는 부분이 궁금해서 질문 드립니다.
우선 답지에는
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?
고수님들의 가르침 부탁드립니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2699024 | C언어 공부하려는데 도와주세요!!! (2) | 달님 | 2025-06-22 |
2698994 | 날짜 계산하는 C 코드 짜고 있는데 꽉 막혀서 질문드립니다.. (6) | 별 | 2025-06-22 |
2698967 | 파일삭제 윈도우 폴더까지 접근하게하는 함수가 뭔가요 (2) | 샤인 | 2025-06-21 |
2698938 | c언어 메모리질문 (3) | 나래 | 2025-06-21 |
2698909 | 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) | 궁수자리 | 2025-06-21 |
2698882 | 프로그래밍좀 짜주세요 (3) | 황예 | 2025-06-21 |
2698855 | 카프-라빈 알고리즘 코딩 분석좀 도와주세요.. | 꽃봄 | 2025-06-20 |
2698829 | 학점계산기 (7) | MyWay | 2025-06-20 |
2698782 | 기초적인 함수 질문이요ㅠㅠㅠㅠ | 내담 | 2025-06-20 |
2698749 | 프로그램 짜던 도중 패닉입니다...ㅜ | 파랑 | 2025-06-19 |
2698719 | 조건부컴파일 질문입니다.~ (2) | 큐트 | 2025-06-19 |
2698693 | 재귀 함수 에러 | 바닐라 | 2025-06-19 |
2698673 | 고민이있는데 들어좀주세요!! (1) | 초코맛캔디 | 2025-06-19 |
2698644 | 1부터 n까지의 합을 구하는데 엄청긴숫자의 합을 구할때는 어떻게 해야하나요? (4) | 슬우 | 2025-06-18 |
2698616 | 다른 함수로 안넘어갑니다..;;; | 도1도캣 | 2025-06-18 |
2698587 | 배열하다 막혀서... (3) | WhiteCat | 2025-06-18 |
2698559 | 문자열을 비우는방법 (2) | 하늘 | 2025-06-18 |
2698528 | 착하고 친절한 선생씌구해염~ㅋㅋ (4) | 옆집언니야 | 2025-06-17 |
2698502 | 자료구조 큐 | 캔서 | 2025-06-17 |
2698477 | 실행화면 배경문의요 | 선아 | 2025-06-17 |