수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

이 테트리스 소스에서

루라

2023.04.01


질문 제목 : 이 테트리스 소스에서 테트리스질문 내용 :

안녕하세요.
윤성우 교재에 있는 테트리스 소스인데요.
완성소스는 아니구요.
블럭이 떨어지고 라인이 차면서 지워지는 그 부분을 나타내려는데요.
int blockdown(void)이 함수에서
void removefillupline(void)을 주석처리로 함수를 막아놓으면 블럭이 계속 나타나 떨어지는데
주석을 풀어놓으면 블럭이 한번만 나타납니다.
지금 막아놓은 함수는 라인이 가득 차면 지워지면서 위에 블럭들이 내려오는 그런 함수거든요.
블럭이 왜 한번만 나타는 것인가요?
막아놓은 부분은 블럭의 충돌조건시에만 실행되는 부분이라 연관도 없을것 같은데 왜 그러죠?

일단 그 부분을 여기에 올리구요.
파일로도 올립니다.

보시기 불편하시면 눈이 피로해질 수 있으니 컴파일러에서 실행시켜서 봐주세요.
그럼 한 수 가르쳐 주시길요 꾸벅^^__^^#include time.h
#include common.h
#include point.h
#include blockinfo.h
#include keycurcontrol.h
#define gboard_width 10
#define gboard_height 20
#define gboard_origin_x 4
#define gboard_origin_y 2
static int gameboardinfo[gboard_height+1][gboard_width+2]={0,};

static int currentblockmodel;
static int curposx, curposy;
static int rotateste;

//블록의 첫 위치 지정
void initnewblockpos(int x, int y)
{
if(x0 || y0)
return;
curposx=x;
curposy=y;
setcurrentcursorpos(x,y);
}
//출력할 블럭을 무작위 선택
void chooseblock(void)
{
srand((unsigned int)time(null));
currentblockmodel=(rand()%num_of_block_model)*4;
}
//현재 출력해야 하는 블록의 index 정보 반환
int getcurrentblockidx(void)
{
return currentblockmodel + rotateste;
}//전달된 인자를 참조하여 블럭 출력
void showblock(char blockinfo[][4])
{
int x,y;
point curpos=getcurrentcursorpos();

for(y=0; y4 ;y++)
{
for(x=0; x4; x++)
{
setcurrentcursorpos(curpos.x+x*2,curpos.y+y);
if(blockinfo[y][x]==1)
printf(■);
//printf(%d %d \n,y,x);
}
}
setcurrentcursorpos(curpos.x,curpos.y);
}
//현재 블록의 삭제
void deleteblock(char blockinfo[][4])
{
int y,x;
point curpos=getcurrentcursorpos();
for(y=0; y4; y++)
{
for(x=0; x4 ; x++)
{
setcurrentcursorpos(curpos.x+x*2,curpos.y+y);

if(blockinfo[y][x]==1)

printf( );
}
}
setcurrentcursorpos(curpos.x,curpos.y);
}
int detectcollision(int posx,nt posx,int posy,char blockmodel[][4])
{
int x,y;
int arrx=(posx-gboard_origin_x)/2;
int arry=posy-gboard_origin_y;
for(x=0; x4; x++)
{
for(y=0; y4; y++)
{
if(blockmodel[y][x]==1 && gameboardinfo[arry+y][arrx+x]==1)
return 0;
}
}
return 1;
}

//굳어진 블록을 그린다.
void drawsolidblock(void)
{
int x,y;
int cursx,cursy;
for(y=0; ygboard_height ; y++)
{
for(x=1; xgboard_width+1 ; x++)
{
cursx=x*2 +gboard_origin_x;
cursy=y+gboard_origin_y;
setcurrentcursorpos(cursx,cursy);
if(gameboardinfo[y][x]==1)
printf(■);

else
printf( );
}
}
}
//행 단위로 블록을 삭제
void removefillupline(void)
{
int x,y;
int line;
for(y=gboard_height-1; y0 ; y--)
{
for(x=1; xgboard_width+1; x++)
{
if(gameboardinfo[y][x] != 1)
break;
}
if(x==(gboard_width+1))
{
for(line=0; y-line0; line++)
{

memcpy(&gameboardinfo[y-line][1],&gameboardinfo[(y-line)-1][1],gboard_width * sizeof(int));
}
}

y++;
}
drawsolidblock();
}

void addcurrentblockinfotoboard(void)
{
int x,y;
int arrcurx;
int arrcury;
for(y=0; y4; y++)
{
for(x=0; x4 ;x++)
{
arrcurx=(curposx-gboard_origin_x)/2;
arrcury=curposy-gboard_origin_y;
if(blockmodel[getcurrentblockidx()][y][x]==1)
gameboardinfo[arrcury+y][arrcurx+x]=1;
}
}
}
//블록 다운
int blockdown(void)
{
if(!detectcollision(curposx,curposy+1,blockmodel[getcurrentblockidx()]))
{
addcurrentblockinfotoboard();
//removefillupline();========================//이부분을 막아놓으면 다른 블록들이 잘 나오는데
//막아놓지 않으면 블록이 한번만 등장함.
return 0;
}
deleteblock(blockmodel[getcurrentblockidx()]);
curposy+=1;
setcurrentcursorpos(curposx,curposy);
showblock(blockmodel[getcurrentblockidx()]);

return 1;
}

//블록을 왼쪽으로 한칸 이동
void shiftleft(void)
{
if(!detectcollision(curposx-2,curposy,blockmodel[getcurrentblockidx()]))
return;
deleteblock(blockmodel[getcurrentblockidx()]);
curposx-=2;
setcurrentcursorpos(curposx,curposy);
showblock(blockmodel[getcurrentblockidx()]);
}

//블록을 오른쪽으로 한칸 이동
void shiftright(void)
{
if(!detectcollision(curposx+2,curposy,blockmodel[getcurrentblockidx()]))
return;deleteblock(blockmodel[getcurrentblockidx()]);
curposx+=2;
setcurrentcursorpos(curposx,curposy);
showblock(blockmodel[getcurrentblockidx()]);
}//블록을 90도 회전
void rotateblock(void)
{
int nextrotate;
int beforerotate=rotateste;

deleteblock(blockmodel[getcurrentblockidx()]);
nextrotate=rotateste+1;
nextrotate %= 4;
rotateste=nextrotate;

if(!detectcollision(curposx,curposy,blockmodel[getcurrentblockidx()]))
{
rotateste=beforerotate;
return;
}

setcurrentcursorpos(curposx,curposy);
showblock(blockmodel[getcurrentblockidx()]);
}
void solidcurrentblock(void)
{
while(blockdown());
}
void drawgameboard(void)
{
int x, y;
for(y=0; y=gboard_height ;y++)
{
setcurrentcursorpos(gboard_origin_x,gboard_origin_y+y);
if(y==gboard_height)
printf(┗);
else
printf(┃);
}
for(y=0; y=gboard_height ; y++)
{
setcurrentcursorpos(gboard_origin_x+(gboard_width+1)*2,gboard_origin_y+y);
if(y==gboard_height)
printf(┛);
else
printf(┃);
}
for(x=1 ; xgboard_width+1 ; x++)
{
setcurrentcursorpos(gboard_origin_x+x*2,gboard_origin_y+gboard_height);
printf(━);
}
setcurrentcursorpos(0,0);
for(y=0 ; ygboard_height; y++)
{
gameboardinfo[y][0]=1;
gameboardinfo[y][gboard_width+1]=1;
}

for(x=0; xgboard_width+2 ; x++)
{
gameboardinfo[gboard_height][x]=1;
}
}int isgameover(void)
{
if(!detectcollision(curposx,curposy,blockmodel[getcurrentblockidx()]))
return 1;
else
return 0;
}

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2694900 dequeue 에서 리턴값 프린트 방법알려주세요 오늘 12시까지 대화방에 있습니다 도와주세요 미투리 2025-05-15
2694854 절대값을 구할때 (2) 그녀는귀여웠다 2025-05-15
2694827 이제 어떻게 공부해야할지 모르겠네요 새얀 2025-05-14
2694778 순열 계산요. 맛조이 2025-05-14
2694754 ShowWindow 함수를 이용하려 하는데 질문있습니다. (2) 파도 2025-05-14
2694731 리눅스 커널의 시작점 질문 미르 2025-05-13
2694702 이거 뭐가문제인가요 코드수정좀 (3) 맑은 2025-05-13
2694675 C언어 후위표기를 중위표기로 앨런 2025-05-13
2694646 안녕하세요 파일 합치기 함수! (1) 연블루 2025-05-13
2694618 잘몰라서 설명부탁드립니다. scanf 관련 (3) 파라 2025-05-12
2694590 이 코드가 뭐하는 코드일까요? #2 빵순 2025-05-12
2694559 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) 늘솔길 2025-05-12
2694532 네트워크에 관하여... (4) 황소자리 2025-05-12
2694503 프로그램 연산 후 바로 종료되는 현상 (6) Judicious 2025-05-11
2694450 while문질문입니다. (1) 허리품 2025-05-11
2694420 C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) 은새 2025-05-11
2694370 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 들찬 2025-05-10
2694339 putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) 미르 2025-05-10
2694316 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) 나빛 2025-05-10
2694285 언어 공부하는 과정 좀 추천해주세요! (1) 아빠몬 2025-05-09
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com