테트리스 문제점좀 지적해주세요..
아더
테트리스 게임 프로젝트 코딩 하던 중
답지와 차이가 나는 부분이 궁금해서 질문 드립니다.
우선 답지에는
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?
고수님들의 가르침 부탁드립니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2655361 | 엔터 입력받을때까지 기다리는 getchar (1) | 큰모음 | 2024-05-19 |
2655328 | 함수에서 포인터 (3) | 모아 | 2024-05-18 |
2655299 | 아이콘바꾸는법..? | 소 | 2024-05-18 |
2655271 | scanf 입력받으면 쭉 실행되는.. (5) | ComeOn | 2024-05-18 |
2655184 | 이 세개 프로그램좀 해결해주실.... 고수님들???? (3) | 말달리자 | 2024-05-17 |
2655129 | 다차원 배열 원소들 주소계산하는거 질문이요~ | 터전 | 2024-05-17 |
2655103 | AVRstudio MoveAxis. MoveLine 함수질문 | 앨버트 | 2024-05-16 |
2655072 | 콘솔창의 위치와 크기를 정하고 싶습니다. | 딥레드 | 2024-05-16 |
2655044 | 자료구조랑 online judge site에 대해서 질문있습니다... (1) | 뽀송뽀송 | 2024-05-16 |
2655016 | 별찍기 문제 중 이해안되는 부분이 있어요... | 도전중 | 2024-05-16 |
2654986 | 입력받은 성적을 배열에 저장하기 (3) | 안녕나야 | 2024-05-15 |
2654959 | ===========-이런거 미리 지정하는법 (1) | 김자영 | 2024-05-15 |
2654930 | 도와주십시요 ㅜㅜ 자료구조 ㅜㅜ | 도널드 | 2024-05-15 |
2654881 | PID 모듈 검색 부분 질문합니다 . | 이름없음 | 2024-05-14 |
2654850 | 조건에 만족하는 다음 수를 찾고 싶습니다. | 초엘 | 2024-05-14 |
2654790 | 두파일간 byte단위 txt파일 복사 中 | 슬찬 | 2024-05-14 |
2654768 | 사전만들기 입니다. | 여우By | 2024-05-13 |
2654716 | c언어 고수님들 답좀적어주세요 급합니다 ㅠㅠ | 한말글 | 2024-05-13 |
2654688 | c언어 ㅠㅠ 너 무 어려 워요 ㅠ 도와주세요!! | 별빛 | 2024-05-13 |
2654659 | 구구단 소스 궁금한 점 도움 부탁드립니다! (2) | 미련곰팅이 | 2024-05-12 |