俄罗斯方块编程的方块变形边界问题,求各位大佬
#include <stdio.h>#include <graphics.h>
#include <conio.h>
#define DOWN (0X8000+72)
#define SHANG (0X8000+80)
#define KEY_ENT 13
#define LEFT (0X8000+75)
#define RINT (0X8000+77)
IMAGE img;
IMAGE GAME;
void elsfklp(struct block *lp);
void elsfklp(struct block *lp);
int getkey()
{
int ch = getch();
if (ch==224)
{
return 0x8000+getch();
}
else if (ch==0)
{
return 0x4000+getch();
}
return ch;
}
int cloler[]={BLACK,YELLOW,RED};
char game[7][4][4][4]=
{
//正L
0,1,0,0,
0,1,0,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,1,
0,1,0,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,0,1,0,
0,0,1,0,
0,0,0,0,
0,0,0,1,
0,1,1,1,
0,0,0,0,
//反L
0,0,1,0,
0,0,1,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,1,0,0,
0,1,1,1,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,1,0,0,
0,1,0,0,
0,0,0,0,
0,1,1,1,
0,0,0,1,
0,0,0,0,
//田
0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,
//T
0,0,0,0,
0,0,1,0,
0,1,1,1,
0,0,0,0,
0,0,0,0,
0,0,1,0,
0,0,1,1,
0,0,1,0,
0,0,0,0,
0,1,1,1,
0,0,1,0,
0,0,0,0,
0,0,0,0,
0,0,1,0,
0,1,1,0,
0,0,1,0,
//一
0,0,0,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,1,
0,0,0,0,
0,0,0,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,0,0,
0,0,0,0,
0,1,1,1,
0,0,0,0,
//h
0,0,0,0,
0,0,1,0,
0,0,1,1,
0,0,0,1,
0,0,0,0,
0,0,1,1,
0,1,1,0,
0,0,0,0,
0,0,0,0,
0,0,1,0,
0,0,1,1,
0,0,0,1,
0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0,
//反h
0,0,0,0,
0,0,1,0,
0,1,1,0,
0,1,0,0,
0,0,0,0,
0,1,1,0,
0,0,1,1,
0,0,0,0,
0,0,1,0,
0,1,1,0,
0,1,0,0,
0,0,0,0,
0,1,1,0,
0,0,1,1,
0,0,0,0,
0,0,0,0,
};
struct block
{
int x;//x坐标
int y;//y坐标
int tyle;//类型
int bian;//方向
int cloler1;//颜色
};
int border(struct block *lp,int x,int y)
{
int i,j;
for (i=0;i<4;i++)
{
for (j=0;j<4;j++)
{
if (game[lp->tyle][lp->bian][i][j])
{
if (lp->x+j+x<0 || lp->x+j+x>=20 || lp->y+i+x>=19)
{
return 0;
}
}
}
}
return 1;
}
void inti(void)
{
struct block lp;
lp.x=5;
lp.y=5;
lp.tyle=0;
lp.bian=0;
lp.cloler1=3;
int ch;
initgraph(700,500);
loadimage(&GAME,"456.jpg",700,500,true);
BeginBatchDraw();
while(1)
{
putimage(0,0,&GAME);
fillrectangle(10,10,410,410);
/* bar(100,100,200,200);*/
elsfklp(&lp);
FlushBatchDraw();
ch=getkey();
switch(ch)
{
case DOWN:
lp.bian++;
break;
case SHANG:
if (border(&lp,0,1))
{
lp.y++;
}
break;
case LEFT:
if (border(&lp,-1,0))
{
lp.x--;
}
break;
case RINT:
if (border(&lp,1,0))
{
lp.x++;
}
break;
}
}
EndBatchDraw();
closegraph();
}
void elsfklp(struct block *lp)
{
int i,j;
setcolor(cloler[lp->cloler1]);
for (i=0;i<4;i++)
{
for (j=0;j<4;j++)
{
if (game[lp->tyle][lp->bian][j][i])
{
bar3d(10+(lp->x+i)*20+1,10+(lp->y+j)*20+1,10+(lp->x+i+1)*20-1,10+(lp->y+j+1)*20-1,2,true);
}
}
}
}
int tupian()
{
IMAGE img;
int x=50;
int ch;
int i;
int pos=0;
char game[][30]={"开始游戏","继续游戏","帮助","设置","结束游戏"};
MOUSEMSG mlous;
int point[]={200,200,150,250,250,200,200};
loadimage(&img,"123.jpg",700,500,true);
BeginBatchDraw();
while(1)
{
putimage(0,0,&img);
settextstyle(50,20,"华文行楷");
for (i=0;i<5;i++)
{
setcolor(GREEN);
if (pos==i)
{
setbkmode(OPAQUE);
}
else
{
setbkmode(TRANSPARENT);
}
outtextxy(x,50+50*i,game[i]);
}
FlushBatchDraw();
ch=getkey();
switch(ch)
{
case SHANG:
if (pos<4)
{
pos++;
}
break;
case DOWN:
if (pos>0)
{
pos--;
}
case KEY_ENT:
EndBatchDraw();
inti();
break;
}
}
while(1)
{
mlous=GetMouseMsg();
switch(mlous.uMsg)
{
case WM_LBUTTONDOWN:
break;
}
//
//
}
closegraph();
return 0;
}
int main()
{
// while(1)
// {
// int ch;
// ch=getch();
// printf("%d",ch);
// }
initgraph(700,500);
tupian();
return 0;
}