테트리스 질문입니다. 제 코딩의 문제점을 지적해주세요.
콩순
테트리스 게임 프로젝트 코딩 하던 중
답지와 차이가 나는 부분이 궁금해서 질문 드립니다.
우선 답지에는
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]);
}
저는 이렇게 해서 해봤는데 결과가
블록 방향을 바꾸면 처음에 바꼇다가 원래대로 되돌아 오는 문제가 발생하더라구요..
어떤 문제가 있어서 그렇게 되는지 잘 모르겠어서 질문드립니다.
고수님들의 가르침 부탁드립니다.
-
역곡중
감사합니다~~~^^^^^
-
은새
BlockDown 이 틀리네요. 아아 숨은그림찾기 힘들다. ㅎㅎㅎ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2703014 | void *fuction(int a) 이런 함수 질문좀요 (3) | 박애교 | 2025-07-28 |
2702932 | 기본 구조체 인데 잘 모르겠네요.ㅠㅠ | 한국녀 | 2025-07-27 |
2702877 | DVD대여프로그램인데요~ 도와주세요!! | 하늘 | 2025-07-27 |
2702850 | enum인데 해석이 안됩니다.. (1) | 수국 | 2025-07-26 |
2702822 | 가우스 소거법좀 부탁드립니다. | 큰힘 | 2025-07-26 |
2702797 | system("mode con: .. ); 명령어 vs2005에서는.. (1) | 콩알눈 | 2025-07-26 |
2702775 | % 연산자, / 연산자 관련질문 | 솔잎 | 2025-07-26 |
2702743 | Linux message queue를 이용한 방법에서 msgrcv | 뚜야 | 2025-07-25 |
2702661 | 동적으로 3개씩 할당되는 배열 (7) | 별빛 | 2025-07-25 |
2702638 | 문제해결좀 (1) | 개굴츼 | 2025-07-24 |
2702495 | mfc edit control 공백체크 (4) | 분홍이 | 2025-07-23 |
2702465 | 이 함수호출에서 뭐가 잘못됬죠 ?ㅠ | 미즈 | 2025-07-23 |
2702438 | C언어에서 Addr이 뭔가요? (6) | 밝은빛누리예 | 2025-07-23 |
2702384 | 흠.. 피보나치 수열을... for문으로 만들었는데요....ㅠㅠ;; (1) | 계획자 | 2025-07-22 |
2702354 | c언어 하나더 질문드리겠습니다^^ | 유키 | 2025-07-22 |
2702323 | 배열 최빈값 구하는 소스 좀 갈켜주셈. | PrinceSs | 2025-07-22 |
2702296 | 오류좀 찾아주세요! 스왑함수 (1) | 지우 | 2025-07-21 |
2702232 | 글씨를 검은색, 바탕을 하얀색으로 하는방법좀 가르쳐주세요 !! | 놓아주세요 | 2025-07-21 |
2702205 | for문 중첩ㅠㅠ (2) | 한뎃집 | 2025-07-21 |
2702177 | 소리나오게 하는법! | 가지 | 2025-07-20 |