C언어 테트리스입니다 ㅠㅠ
세련
질문 제목 : 테트리스 블록 회전 후 잔상이남아요 질문 요약 :테트리스 블록 회전 후 잔상이남아요질문 내용 : #include stdio.h
#include conio.h
#include windows.h
#define up 72 // 위쪽 방향키 아스키코드값 define
#define down 80 // 아랫쪽 방향키 아스키코드값 define
#define left 75 // 왼쪽 방향키 아스키코드값 define
#define right 77 // 오른쪽 방향키 아스키코드값 define
#define one 49
#define two 50
#define three 51
#define space 32
#define enter 13
//kbhit(); 값을 입력받으면 1을 리턴
int h; // 높이 y좌표
int s; // xy 칸 x좌표
int sa; // 배열 칸 x/2좌표
int score = 0;
char ch;
int rd;
void gotoxy(int x, int y)
{
coord pos = { x-1, y-1 };
setconsolecursorposition(getstdhandle(std_output_handle), pos);
}
void prtfield(int (*a)[10])
{
for(h=0;h20;h++)
{
printf(▩);
for(sa=0;sa10;sa++)
{
if(a[h][sa] == 1) // 배열값이 1이면 블럭이 존재한다
printf(■);
else
printf( );
}
printf(▩);
printf(\n);
}
printf(▩▩▩▩▩▩▩▩▩▩▩▩);
}
void gameover()
{
system(cls);
printf(game over);
}
void shape1(int (*a)[10])
{
for(h=2;h20;h++)
{
if(a[h+1][s/2] == 1 || a[h+1][s/2-1] == 1) // 블럭밑에 블럭이 있을때
{
a[h-1][s/2-1] = 1;
a[h-1][s/2] = 1;
a[h][s/2-1] = 1;
a[h][s/2] = 1;// 그 위치 배열에 1을 넣어줌
break;
}
if(h=1 && a[h+1][(s)/2-1] != 1 )
{
sleep(50); // 블럭이 내려오는 딜레이타임
gotoxy(s,h-2); // 블럭이 밑으로 내려가면서 위에있는 블럭은 지워줌
printf( );
gotoxy(s,h-1); // 밑에다 블럭을 그려줌
printf(■■);
gotoxy(s,h);
printf(■■);
if(a[h+1][(s)/2-1] == 1 || a[h+1][s/2] == 1) // 블럭밑에 다른 블럭이 존재하면 그 위치에 1을 리턴
{
a[h-1][s/2-1] = 1;
a[h-1][s/2] = 1;
a[h][s/2-1] = 1;
a[h][s/2] = 1;// 그 위치 배열에 1을 넣어줌
break;
}
if(h==19)
{
a[h-1][s/2-1]=1;
a[h-1][s/2] = 1;
a[h][s/2-1] = 1;
a[h][s/2] = 1;
}
if(_kbhit()) // 키를 입력받았을때
{
ch = _getch();
if(ch == -32 )
{
ch = getch();
switch(ch)
{
case left:
if(s4 && a[h][s/2-2]!=1)
{
gotoxy(s-2,h-1);
printf(■■);
gotoxy(s-2,h);
printf(■■);
gotoxy(s+2,h-1);
printf( );
gotoxy(s+2,h);
printf( );
s-=2;
break;
}
else
break;
case right:
while(1)
{
fflush(stdin);
if(s18 && a[h][s/2+1] != 1)
{
gotoxy(s+1,h-1);
&nbsbsp;printf(■■);
gotoxy(s+1,h);
printf(■■);
gotoxy(s-1,h-1);
printf( );
gotoxy(s-1,h);
printf( );
s+=2;
break;
}
else
break;
}
}
}
switch(ch)
{
case space: // 스페이스를 눌렀을때 바로 바닥으로 이동
for(h=1;h20;h++)
{
if(a[h+1][(s)/2-1] == 1 || a[h+1][s/2] == 1 || h == 19)
{
a[h-1][s/2-1] = 1;
a[h-1][s/2] = 1;
a[h][s/2-1] = 1;
a[h][s/2] = 1; // 그 위치 배열에 1을 넣어줌
break;
}
}
}
}
}
}
}
void shape2(int (*a)[10])
{
for(h=2;h20;h++)
{
switch(rd)
{
case 0:
if(a[h+1][s/2-1] == 1 || a[h+1][s/2] == 1 || a[h+1][s/2+1] == 1 || a[h+1][s/2+2] == 1) // 블럭밑에 블럭이 있을때
{
a[h][s/2+2] = 1;
a[h][s/2+1] = 1;
a[h][s/2] = 1;
a[h][s/2-1] = 1;// 그 위치 배열에 1을 넣어줌
break;
}
if(h=1 && a[h+1][s/2-1] != 1 && a[h+1][s/2] != 1 && a[h+1][s/2+1] != 1 && a[h+1][s/2+2] != 1 )
{
sleep(200); // 블럭이 내려오는 딜레이타임
gotoxy(s,h-1); // 블럭이 밑으로 내려가면서 위에있는 블럭은 지워줌
printf( );
gotoxy(s,h);
printf(■■■■);
if(a[h+1][s/2-1] == 1 || a[h+1][s/2] == 1 || a[h+1][s/2+1] == 1 || a[h+1][s/2+2] == 1) // 블럭밑에 다른 블럭이 존재하면 그 위치에 1을 리턴
{
a[h][s/2+2] = 1;
a[h][s/2+1] = 1;
a[h][s/2] = 1;
a[h][s/2-1] = 1;// 그 위치 배열에 1을 넣어줌
break;
}
if(h==19)
{
a[h][s/2+2] = 1;
a[h][s/2+1] = 1;
a[h][s/2] = 1;
a[h][s/2-1] = 1;// 그 위치 배열에 1을 넣어줌
break;
}
if(_kbhit()) // 키를 입력받았을때
{
ch = _getch();
if(ch == -32)
{
ch = getch();
switch(ch)
{
case left:
if(s4 && a[h][s/2-1]!=1)
{
gotoxy(s+6,h);
printf( );
gotoxy(s-2,h);
printf(■■■■);
s-=2;
break;
}
else
break;
case right:
if(s14 && a[h][s/2+4] != 1)
{
gotoxy(s,h);
printf( );
gotoxy(s+2,h);
printf(■■■■);
s+=2;
break;
}
else
break;
case up:
rd = 1;
}
}
}
}
break;
case 1:
if(a[h-1][s/2-1] == 1) // 블럭밑에 블럭이 있을때
{
a[h-3][s/2-1] = 1;
a[h-2][s/2-1] = 1;
a[h-1][s/2-1] = 1;
a[h][s/2-1] = 1;// 그 위치 배열에 1을 넣어줌
break;
}
if(h=1 && a[h+1][s/2-1] != 1)
{
sleep(200); // 블럭이 내려오는 딜레이타임
gotoxy(s,h-4); // 블럭이 밑으로 내려가면서 위에있는 블럭은 지워줌
printf( );
gotoxy(s,h-3);
printf(■);
gotoxy(s,h-2);
printf(■);
gotoxy(s,h-1);
printf(■);
gotoxy(s,h);
printf(■);
if(a[h-1][s/2-1] == 1) // 블럭밑에 블럭이 있을때
{
a[h-3][s/2-1] = 1;
a[h-2][s/2-1] = 1;
a[h-1][s/2-1] = 1;
a[h][s/2-1] = 1;// 그 위치 배열에 1을 넣어줌
break;
}
if(h==19)
{
a[h-3][s/2-1] = 1;
a[h-2][s/2-1] = 1;
a[h-1][s/2-1] = 1;
a[h][s/2-1] = 1;// 그 위치 배열에 1을 넣어줌
break;
}
if(_kbhit()) // 키를 입력받았을때
{
ch = _getch();
if(ch == -32)
{
ch = getch();
switch(ch)
{
case left:if(s4 && a[h][s/2-1]!=1)
{
gotoxy(s-2,h+4);
printf( );
gotoxy(s-2,h+3);
printf( );
gotoxy(s-2,h+2);
printf( );
gotoxy(s-2,h+1);
printf( );
gotoxy(s-2,h+3);
printf(■);
&nbnbsp;gotoxy(s-2,h+2);
printf(■);
gotoxy(s-2,h+1);
printf(■);
gotoxy(s-2,h);
printf(■);
s-=2;
break;
}
else
break;case right:
if(s20 && a[h][s/2+4] != 1)
{
gotoxy(s+2,h);
printf( );
gotoxy(s+2,h+1);
printf(■);
gotoxy(s+2,h+2);
printf(■);
gotoxy(s+2,h+3);
printf(■);
gotoxy(s+2,h+4);
printf(■);
s+=2;
break;
}
else
break;
case up:
rd = 0;
break;
}
}
}
}
break;
}
}
}
void del(int (*a)[10]) // 줄이 찼는지의 여부를 확인한후 줄 삭제
{
int check[20]={0};
int height=0;
int i, j, k;
int out = 0;
for(i=19;i=0;i--)// 가득찬지의 여부
{
for(j=0;j10;j++)
{
if(a[i][j]!=1) //i가 1이 아니면 확인할 필요 없음
break;
}
if(j==10)
check[i] = 1;
}
for(i=19;i=0;i--)
{
if(check[i]==1)
{
for(k=i;k0;k--)
{
for(j=0;j10;j++)
{
a[k][j] = a[k-1][j]; //윗줄 아래로 내려줌
a[k-1][j] = 0;
}
}
check[i] = 0;
score += 10;
}
}
}
int main()
{
int a[20][10] = {0};
while(1)
{
s = 13;
system(cls);
del(a);
prtfield(a);
gotoxy(50,10);
printf(score %d, score);
shape2(a);
}
return 0;
}이 코딩에서요 shape2함수를 보면 ㅡㅡㅡㅡ 이블록이 누운 상태에서는 좌우이동해도 잔상이없지만, 회전후 좌우이동을 하면 잔상이남습니다 이거어떻게 해결이안될까요?ㅠㅠㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
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 |