📄 square.c
字号:
case 2:
move=psqr->intx>0 && desk[psqr->inty][psqr->intx-1]==0 &&
desk[psqr->inty+1][psqr->intx]==0;
break;
case 3:
move=psqr->intx>0 && desk[psqr->inty][psqr->intx-1]==0 &&
desk[psqr->inty+1][psqr->intx-1]==0 && desk[psqr->inty+2][psqr->intx-1]==0;
}
break;
case 4:
switch(psqr->num)
{
case 0:
case 2:
move=psqr->intx>0 && desk[psqr->inty][psqr->intx-1]==0 &&
desk[psqr->inty+1][psqr->intx-1]==0 && desk[psqr->inty+2][psqr->intx]==0;
break;
case 1:
case 3:
move=psqr->intx>0 && desk[psqr->inty][psqr->intx]==0 &&
desk[psqr->inty+1][psqr->intx-1]==0;
}
break;
case 5:
switch(psqr->num)
{
case 0:
case 2:
move=psqr->intx>0 && desk[psqr->inty][psqr->intx]==0 &&
desk[psqr->inty+1][psqr->intx-1]==0 && desk[psqr->inty+2][psqr->intx-1]==0;
break;
case 1:
case 3:
move=psqr->intx>0 && desk[psqr->inty][psqr->intx-1]==0 &&
desk[psqr->inty+1][psqr->intx]==0;
}
break;
case 6:
switch(psqr->num)
{
case 0:
case 2:
move=psqr->intx>0 && desk[psqr->inty][psqr->intx-1]==0 &&
desk[psqr->inty+1][psqr->intx-1]==0 &&
desk[psqr->inty+2][psqr->intx-1]==0 &&
desk[psqr->inty+3][psqr->intx-1]==0;
break;
case 1:
case 3:
move=psqr->intx>0 && desk[psqr->inty][psqr->intx-1]==0;
}
}
if(move)
{
display_sqr(erase);
psqr->intx--;
display_sqr(draw);
}
return 0;
case down:
switch(psqr->kind)
{
case 0:
move=psqr->inty<18 && desk[psqr->inty+2][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0;
break;
case 1:
switch(psqr->num)
{
case 0:
move=psqr->inty<18 && desk[psqr->inty+2][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0 && desk[psqr->inty+2][psqr->intx+2]==0;
break;
case 1:
move=psqr->inty<17 && desk[psqr->inty+3][psqr->intx]==0 &&
desk[psqr->inty+3][psqr->intx+1]==0;
break;
case 2:
move=psqr->inty<18 && desk[psqr->inty+1][psqr->intx]==0 &&
desk[psqr->inty+1][psqr->intx+1]==0 && desk[psqr->inty+2][psqr->intx+2]==0;
break;
case 3:
move=psqr->inty<17 && desk[psqr->inty+3][psqr->intx]==0 &&
desk[psqr->inty+1][psqr->intx+1]==0;
}
break;
case 2:
switch(psqr->num)
{
case 0:
move=psqr->inty<18 && desk[psqr->inty+2][psqr->intx]==0 &&
desk[psqr->inty+1][psqr->intx+1]==0 && desk[psqr->inty+1][psqr->intx+2]==0;
break;
case 1:
move=psqr->inty<17 && desk[psqr->inty+3][psqr->intx]==0 &&
desk[psqr->inty+3][psqr->intx+1]==0;
break;
case 2:
move=psqr->inty<18 && desk[psqr->inty+2][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0 && desk[psqr->inty+2][psqr->intx+2]==0;
break;
case 3:
move=psqr->inty<17 && desk[psqr->inty+1][psqr->intx]==0 &&
desk[psqr->inty+3][psqr->intx+1]==0;
}
break;
case 3:
switch(psqr->num)
{
case 0:
move=psqr->inty<18 && desk[psqr->inty+2][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0 && desk[psqr->inty+2][psqr->intx+2]==0;
break;
case 1:
move=psqr->inty<17 && desk[psqr->inty+2][psqr->intx]==0 &&
desk[psqr->inty+3][psqr->intx+1]==0;
break;
case 2:
move=psqr->inty<18 && desk[psqr->inty+1][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0 &&desk[psqr->inty+1][psqr->intx+2]==0;
break;
case 3:
move=psqr->inty<17 && desk[psqr->inty+3][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0;
}
break;
case 4:
switch(psqr->num)
{
case 0:
case 2:
move=psqr->inty<17 && desk[psqr->inty+2][psqr->intx]==0 &&
desk[psqr->inty+3][psqr->intx+1]==0;
break;
case 1:
case 3:
move=psqr->inty<18 && desk[psqr->inty+2][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0 && desk[psqr->inty+1][psqr->intx+2]==0;
}
break;
case 5:
switch(psqr->num)
{
case 0:
case 2:
move=psqr->inty<17 && desk[psqr->inty+3][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0;
break;
case 1:
case 3:
move=psqr->inty<18 && desk[psqr->inty+1][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0 && desk[psqr->inty+2][psqr->intx+2]==0;
}
break;
case 6:
switch(psqr->num)
{
case 0:
case 2:
move=psqr->inty<16 && desk[psqr->inty+4][psqr->intx]==0;
break;
case 1:
case 3:
move=psqr->inty<19 && desk[psqr->inty+1][psqr->intx]==0 &&
desk[psqr->inty+1][psqr->intx+1]==0 && desk[psqr->inty+1][psqr->intx+2]==0 &&
desk[psqr->inty+1][psqr->intx+3]==0;
}
}
if(move)
{
display_sqr(erase);
psqr->inty++;
display_sqr(draw);
return 0;
}
else
{
if(new==FALSE){new=TRUE;frozen();
del();}
return 1;
}
}
return 0;
}
void frozen()
{
register int y,x;
for(y=0;y<4;y++)
for(x=0;x<4;x++)
if(psqr->intx+x<10 && psqr->inty+y<20 && psqr->matrix[y][x]!=0)
{
desk[psqr->inty+y][psqr->intx+x]=1;
putimage((psqr->intx+x)*brd.spc,(psqr->inty+y)*brd.spc,buf[gray],COPY_PUT);
}
}
void del()
{
void *buff;
int full=FALSE,cnt=0,y=19;
unsigned int size;
register int x=0,ty;
while(y!=-1)
{
full=desk[y][0];
for(x=1;x<10;x++)
full=full&&desk[y][x];
switch(full)
{
case FALSE:
y--;
x=0;
break;
case TRUE:
putimage(brd.startx,brd.starty+brd.spc*y,buf[lin],COPY_PUT);
cnt++;
ty=y;
for(ty=y;ty>=0;ty--)
for(x=0;x<10;x++)
if(!ty)
desk[ty][x]=0;
else
desk[ty][x]=desk[ty-1][x];
/*play_sound*/
delay(250);
for(ty=y;ty>=0;ty--)
for(x=0;x<10;x++)
putimage(brd.startx+brd.spc*x,brd.starty+brd.spc*ty,buf[desk[ty][x]>0?2:0],COPY_PUT);
full=FALSE;
}
}
if(cnt)
update(cnt*cnt*10+cnt*10,cnt);
}
void display_psqr()
{
register int x,y;
int tmpx=brd.startx+200+225,tmpy=brd.starty+50;
setviewport(0,0,639,479,1);
for(y=0;y<4;y++)
for(x=0;x<4;x++)
putimage(tmpx+brd.spc*x,tmpy+brd.spc*y,buf[pnxtsqr->matrix[y][x]],COPY_PUT);
}
void turnover()
{
int turn=FALSE;
register int y,x;
switch(psqr->kind)
{
case 0:
break;
case 1:
switch(psqr->num)
{
case 0:
turn=psqr->inty<18 && desk[psqr->inty+2][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0 && desk[psqr->inty][psqr->intx+1]==0
&& desk[psqr->inty+1][psqr->intx+2]==0;
break;
case 1:
if(psqr->intx>=8){display_sqr(erase);psqr->intx=7;}
turn=psqr->inty<18 && psqr->intx<8 && desk[psqr->inty][psqr->intx]==0 &&
desk[psqr->inty][psqr->intx+2]==0 && desk[psqr->inty+1][psqr->intx+2]==0;
break;
case 2:
turn=psqr->inty<18 && desk[psqr->inty+1][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx]==0;
break;
case 3:
if(psqr->intx>=8){display_sqr(erase);psqr->intx=7;}
turn=psqr->intx<8 && desk[psqr->inty+1][psqr->intx+1]==0 &&
desk[psqr->inty+1][psqr->intx+2]==0;
}
break;
case 2:
switch(psqr->num)
{
case 0:
turn=psqr->inty<18 && desk[psqr->inty+2][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0;
break;
case 1:
if(psqr->intx>=8){display_sqr(erase);psqr->intx=7;}
turn=psqr->intx<8 && desk[psqr->inty+1][psqr->intx+1]==0 &&
desk[psqr->inty+1][psqr->intx+2]==0 && desk[psqr->inty][psqr->intx+2]==0;
break;
case 2:
turn=psqr->inty<18 && desk[psqr->inty][psqr->intx]==0 &&
desk[psqr->inty][psqr->intx+1]==0 && desk[psqr->inty+2][psqr->intx+1]==0;
break;
case 3:
if(psqr->intx>=8){display_sqr(erase);psqr->intx=7;}
turn=psqr->intx<8 && desk[psqr->inty][psqr->intx+2]==0 &&
desk[psqr->inty][psqr->intx+1]==0;
}
break;
case 3:
switch(psqr->num)
{
case 0:
turn=psqr->inty<18 && desk[psqr->inty+2][psqr->intx+1]==0;
break;
case 1:
if(psqr->intx>=8){display_sqr(erase);psqr->intx=7;}
turn=psqr->intx<8 && desk[psqr->inty][psqr->intx]==0 &&
desk[psqr->inty+1][psqr->intx+2]==0;
break;
case 2:
turn=psqr->inty<18 && desk[psqr->inty+1][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx]==0;
break;
case 3:
if(psqr->intx>=8){display_sqr(erase);psqr->intx=7;}
turn=psqr->intx<8 && desk[psqr->inty][psqr->intx+1]==0 &&
desk[psqr->inty+1][psqr->intx+2]==0;
}
break;
case 4:
switch(psqr->num)
{
case 0:
case 2:
if(psqr->intx>=8){display_sqr(erase);psqr->intx=7;}
turn=psqr->intx<8 && desk[psqr->inty][psqr->intx+1]==0 &&
desk[psqr->inty][psqr->intx+2]==0;
break;
case 1:
case 3:
turn=psqr->inty<18 && desk[psqr->inty][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx+1]==0;
}
break;
case 5:
switch(psqr->num)
{
case 0:
case 2:
if(psqr->intx>=8){display_sqr(erase);psqr->intx=7;}
turn=psqr->intx<8 && desk[psqr->inty][psqr->intx]==0 &&
desk[psqr->inty+1][psqr->intx+2]==0;
break;
case 1:
case 3:
turn=psqr->inty<18 && desk[psqr->inty+1][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx]==0;
}
break;
case 6:
switch(psqr->num)
{
case 0:
case 2:
if(psqr->intx>=6){display_sqr(erase);psqr->intx=6;}
turn=psqr->intx<7 && desk[psqr->inty][psqr->intx+1]==0 &&
desk[psqr->inty][psqr->intx+2]==0 && desk[psqr->inty][psqr->intx+3]==0;
break;
case 1:
case 3:
turn=psqr->inty<17 && desk[psqr->inty+1][psqr->intx]==0 &&
desk[psqr->inty+2][psqr->intx]==0 && desk[psqr->inty+3][psqr->intx]==0;
}
}
if(turn)
{
display_sqr(erase);
psqr->num=++psqr->num%4;
for(y=0;y<4;y++)
for(x=0;x<4;x++)
psqr->matrix[y][x]=wboard[psqr->kind][psqr->num][y][x];
display_sqr(draw);
}
}
void update(int s,int l)
{
char *str=NULL;
struct viewporttype vp;
getviewsettings(&vp);
score+=s;
lines+=l;
level=(lines/50)%10;
speed=level;
setviewport(350+textwidth("SPEED:"),150,350+textwidth("SPEED:OO")+40,250,1);
clearviewport();
setcolor(GREEN);
sprintf(str,"%d",speed);
outtextxy(4,0,str);
outtextxy(4,30,str);
sprintf(str,"%d",score);
outtextxy(4,60,str);
sprintf(str,"%d",lines);
outtextxy(4,90,str);
setviewport(vp.top,vp.left,vp.right,vp.bottom,1);
}
void openbuf()
{
FILE *fp;
char *filename=NULL;
int f_len[]={258,258,258,2190};
int i=0;
for(;i<4;i++)
{
sprintf(filename,"buf%d.dzb",i);
fp=fopen(filename,"rb");
if(fp==NULL){ outtext("Failed to open data files!");exit(-1);}
buf[i]=(char*)malloc(f_len[i]);
if(buf[i]==NULL){outtext("Failed to allocate memory!");exit(-1);}
fread(buf[i],sizeof(char),f_len[i],fp);
fclose(fp);
}
}
int main()
{
init();
openbuf();
begin();
getch();
closegraph();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -