아직 완성시킨 거는 아니고 틀만 잡아놓은 원형이지만(그러니까 주석도 조금씩 있지만) 그래도 컴파일 되고 초기 입출력 되게까지는 했는데 왜 초기화면에서 넘어가지를 않을까. 변수 추적하면서 계속 초기화 다시 시켜주는데도 무한루프 걸릴 데 없는것도 확인했는데.
#include
#include
#include
#include
#include
#include
int display[21][12]={0};
int curloc[4][2]={0};
int curloc_b[4][2]={0};
int lib(int a, int mod);
int smdand(int a, int b)
{
if (a!=0 && b!=0)
{
return 1;
}
else
{
return 0;
}
}
int main(void)
{
int temp=0;
int check=0;
int count=0;
int score=0;
int delcon=0;
char ibuf=0;
int curid=0;
int nexid=0;
int rotct=1;
int xrow=0;
int yrow=0;
int line=0;
puts("TETRIS SMDyne v 0.0D\nPress [1] to continue, [0]to end");
gamestart:;
scanf("%d", &temp);
if (temp==0){
printf("Programme End");
return 0;
}
else if (temp!=1){
puts("Select error.");
goto gamestart;
}
//fflush(stdin);
while (yrow<21)//initloop
{
while (xrow++<12)
{
if (xrow==1 || xrow ==11)
{
display[yrow][xrow]=1;
}
else
{
display[yrow][xrow]=0;
}
}
xrow=0;
}
xrow=0;
while (xrow++<12)//botline
{
display[0][xrow]=1;
}
xrow=0;
yrow=0;
while (1) //Main LP
{
if (check==0)//new block.
{
srand(time(0)+count);
nexid=(rand()%5+1);
if (curid==0){
curid=nexid;
}
lib(curid, 1);
check=1;
}
printf("SCORE: %d\n", score);
printf("NEXT: \n");
lib(nexid, 2);
//display impl.
while (yrow++<4)
{
display[curloc[yrow][0]][curloc[yrow][1]]=1;
}
yrow=1;
while (yrow++<21)//Display LP
{
xrow=1;
while (xrow++<11)
{
printf("%d", display[xrow][yrow]);
}
printf("\n");
xrow=0;
}
yrow=0;
xrow=0;
while (yrow++<4)//del block
{
display[curloc[yrow][0]][curloc[yrow][1]]=0;
}
yrow=0;
memcpy(curloc_b, curloc, sizeof(int)*8);//backup
printf("[a][s][d]\n([w]to rotate, [ELSE] to nothing)\n");
scanf("%c", &ibuf);
unav:;
temp=0;
switch ((int)ibuf)
{
case 97://==a
while (yrow++<4)
{
while (xrow++<2)
{
curloc[yrow][xrow]-=1;
}
yrow=0;
}
xrow=0;
yrow=0;
break;
case 100://==d
while (yrow++<4)
{
while (yrow++<2)
{
curloc[yrow][xrow]+=1;
}
yrow=0;
}
xrow=0;
yrow=0;
break;
case 119://==w
if (rotct%4==1){
}
else if (rotct%4==2){
}
else if (rotct%4==3){
}
else if (rotct%4==0){
}
rotct++;
//no break-> to def.
default://nothing OR s
while (yrow++<4)
{
curloc[yrow][1]-=1;
}
xrow=0;
yrow=0;
}
while (yrow++<4)//test here with AND.
{
if (smdand(1, display[curloc[yrow][0]][curloc[yrow][1]]))
{
if (smdand(1, display[curloc_b[yrow][0]-1][curloc_b[yrow][1]]))//under
{
temp=1;
break;
}
else//stuck
{
temp=-1;
break;
}
}
}
yrow=0;
xrow=0;
if (temp==-1)//stuck or sth.
{
//Stuck->then==nth
puts("Unavailable CMD.");
memcpy(curloc, curloc_b, sizeof(int)*4);
ibuf='s';
goto unav;
}
if (temp==1)//met end
{
puts("OBJ. END");
check=0;
rotct=1;
curid=nexid;
}
xrow=1;
yrow=1;
while (yrow<21)//line del cond search.
{
xrow=1;
while(xrow++<12)
{
delcon+=display[yrow][xrow];
}
xrow=0;
if(delcon>=10)
{
line=yrow;
//deleteline
//downline
score+=1000;
}
delcon=0;
}
yrow=0;
xrow=0;
while (xrow++<8)
{
if (display[21][xrow]!=0)
{
puts("Game Over!");
break;
}
}
xrow=0;
count++;
}
printf("your score: %d\n", score);
puts("Programme End");
return 0;
}
int lib(int a, int mod)
{//1gen 2show
if (mod==1)
{
switch (a)
{
case 1:
curloc[0][0]=0;
curloc[0][1]=0;
curloc[1][0]=0;
curloc[1][1]=0;
curloc[2][0]=0;
curloc[2][1]=0;
curloc[3][0]=0;
curloc[3][1]=0;
break;
case 2:
curloc[0][0]=0;
curloc[0][1]=0;
curloc[1][0]=0;
curloc[1][1]=0;
curloc[2][0]=0;
curloc[2][1]=0;
curloc[3][0]=0;
curloc[3][1]=0;
break;
case 3:
curloc[0][0]=0;
curloc[0][1]=0;
curloc[1][0]=0;
curloc[1][1]=0;
curloc[2][0]=0;
curloc[2][1]=0;
curloc[3][0]=0;
curloc[3][1]=0;
break;
case 4:
curloc[0][0]=0;
curloc[0][1]=0;
curloc[1][0]=0;
curloc[1][1]=0;
curloc[2][0]=0;
curloc[2][1]=0;
curloc[3][0]=0;
curloc[3][1]=0;
break;
case 5:
curloc[0][0]=0;
curloc[0][1]=0;
curloc[1][0]=0;
curloc[1][1]=0;
curloc[2][0]=0;
curloc[2][1]=0;
curloc[3][0]=0;
curloc[3][1]=0;
break;
default:
return -1;
}
}
if (mod==2)
{
switch (a)
{
case 1:
printf(" []\n[][][]\n");
break;
case 2:
printf("[][][][]\n");
break;
case 3:
printf("[][]\n[][]\n");
break;
case 4:
printf(" []\n[][][]\n");
break;
case 5:
printf("[][]\n [][]\n");
break;
default:
return -1;
}
}
return 0;
}
#include
#include
#include
#include
#include
#include
int display[21][12]={0};
int curloc[4][2]={0};
int curloc_b[4][2]={0};
int lib(int a, int mod);
int smdand(int a, int b)
{
if (a!=0 && b!=0)
{
return 1;
}
else
{
return 0;
}
}
int main(void)
{
int temp=0;
int check=0;
int count=0;
int score=0;
int delcon=0;
char ibuf=0;
int curid=0;
int nexid=0;
int rotct=1;
int xrow=0;
int yrow=0;
int line=0;
puts("TETRIS SMDyne v 0.0D\nPress [1] to continue, [0]to end");
gamestart:;
scanf("%d", &temp);
if (temp==0){
printf("Programme End");
return 0;
}
else if (temp!=1){
puts("Select error.");
goto gamestart;
}
//fflush(stdin);
while (yrow<21)//initloop
{
while (xrow++<12)
{
if (xrow==1 || xrow ==11)
{
display[yrow][xrow]=1;
}
else
{
display[yrow][xrow]=0;
}
}
xrow=0;
}
xrow=0;
while (xrow++<12)//botline
{
display[0][xrow]=1;
}
xrow=0;
yrow=0;
while (1) //Main LP
{
if (check==0)//new block.
{
srand(time(0)+count);
nexid=(rand()%5+1);
if (curid==0){
curid=nexid;
}
lib(curid, 1);
check=1;
}
printf("SCORE: %d\n", score);
printf("NEXT: \n");
lib(nexid, 2);
//display impl.
while (yrow++<4)
{
display[curloc[yrow][0]][curloc[yrow][1]]=1;
}
yrow=1;
while (yrow++<21)//Display LP
{
xrow=1;
while (xrow++<11)
{
printf("%d", display[xrow][yrow]);
}
printf("\n");
xrow=0;
}
yrow=0;
xrow=0;
while (yrow++<4)//del block
{
display[curloc[yrow][0]][curloc[yrow][1]]=0;
}
yrow=0;
memcpy(curloc_b, curloc, sizeof(int)*8);//backup
printf("[a][s][d]\n([w]to rotate, [ELSE] to nothing)\n");
scanf("%c", &ibuf);
unav:;
temp=0;
switch ((int)ibuf)
{
case 97://==a
while (yrow++<4)
{
while (xrow++<2)
{
curloc[yrow][xrow]-=1;
}
yrow=0;
}
xrow=0;
yrow=0;
break;
case 100://==d
while (yrow++<4)
{
while (yrow++<2)
{
curloc[yrow][xrow]+=1;
}
yrow=0;
}
xrow=0;
yrow=0;
break;
case 119://==w
if (rotct%4==1){
}
else if (rotct%4==2){
}
else if (rotct%4==3){
}
else if (rotct%4==0){
}
rotct++;
//no break-> to def.
default://nothing OR s
while (yrow++<4)
{
curloc[yrow][1]-=1;
}
xrow=0;
yrow=0;
}
while (yrow++<4)//test here with AND.
{
if (smdand(1, display[curloc[yrow][0]][curloc[yrow][1]]))
{
if (smdand(1, display[curloc_b[yrow][0]-1][curloc_b[yrow][1]]))//under
{
temp=1;
break;
}
else//stuck
{
temp=-1;
break;
}
}
}
yrow=0;
xrow=0;
if (temp==-1)//stuck or sth.
{
//Stuck->then==nth
puts("Unavailable CMD.");
memcpy(curloc, curloc_b, sizeof(int)*4);
ibuf='s';
goto unav;
}
if (temp==1)//met end
{
puts("OBJ. END");
check=0;
rotct=1;
curid=nexid;
}
xrow=1;
yrow=1;
while (yrow<21)//line del cond search.
{
xrow=1;
while(xrow++<12)
{
delcon+=display[yrow][xrow];
}
xrow=0;
if(delcon>=10)
{
line=yrow;
//deleteline
//downline
score+=1000;
}
delcon=0;
}
yrow=0;
xrow=0;
while (xrow++<8)
{
if (display[21][xrow]!=0)
{
puts("Game Over!");
break;
}
}
xrow=0;
count++;
}
printf("your score: %d\n", score);
puts("Programme End");
return 0;
}
int lib(int a, int mod)
{//1gen 2show
if (mod==1)
{
switch (a)
{
case 1:
curloc[0][0]=0;
curloc[0][1]=0;
curloc[1][0]=0;
curloc[1][1]=0;
curloc[2][0]=0;
curloc[2][1]=0;
curloc[3][0]=0;
curloc[3][1]=0;
break;
case 2:
curloc[0][0]=0;
curloc[0][1]=0;
curloc[1][0]=0;
curloc[1][1]=0;
curloc[2][0]=0;
curloc[2][1]=0;
curloc[3][0]=0;
curloc[3][1]=0;
break;
case 3:
curloc[0][0]=0;
curloc[0][1]=0;
curloc[1][0]=0;
curloc[1][1]=0;
curloc[2][0]=0;
curloc[2][1]=0;
curloc[3][0]=0;
curloc[3][1]=0;
break;
case 4:
curloc[0][0]=0;
curloc[0][1]=0;
curloc[1][0]=0;
curloc[1][1]=0;
curloc[2][0]=0;
curloc[2][1]=0;
curloc[3][0]=0;
curloc[3][1]=0;
break;
case 5:
curloc[0][0]=0;
curloc[0][1]=0;
curloc[1][0]=0;
curloc[1][1]=0;
curloc[2][0]=0;
curloc[2][1]=0;
curloc[3][0]=0;
curloc[3][1]=0;
break;
default:
return -1;
}
}
if (mod==2)
{
switch (a)
{
case 1:
printf(" []\n[][][]\n");
break;
case 2:
printf("[][][][]\n");
break;
case 3:
printf("[][]\n[][]\n");
break;
case 4:
printf(" []\n[][][]\n");
break;
case 5:
printf("[][]\n [][]\n");
break;
default:
return -1;
}
}
return 0;
}
- dc official App
어 왜 \n 날라가고 리터럴상수 문자열이 다 문자상수가 되지? - dc App
1. hilite.me가 뭡니까? 2. 그래서 코드상에서 뭐가 문제가 있는 걸까요.? - dc App