我在编俄罗斯方块中 运行时 下落了几个方块后就出现这个
没有作适当的控制.
#include "Conio.h"
#include "graphics.h"
#include "math.h"
#include "stdio.h"
#include "stdlib.h"
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define SPACE 0x3920
#define ESC 0x011b
#define ENTER 0x1c0d
struct SHAPE
{int x[4],y[4];
}box_first[6][4]={ /* 方块初试坐标 */
200,200,200,200,20,40,60,80, 180,200,220,200,20,20,20,20, 200,200,200,200,20,40,60,80,
180,200,220,200,20,20,20,20, 200,200,200,220,20,40,60,40, 200,220,220,220,40,20,40,60,
200,180,200,220,40,60,60,60, 180,200,220,200,40,40,40,60, 200,200,200,220,20,40,60,60,
200,220,220,220,20,20,40,60, 200,200,220,240,40,60,40,40, 180,200,220,220,60,60,40,60,
200,200,200,220,20,40,60,20, 200,220,220,220,60,20,40,60, 200,200,220,240,40,60,60,60,
180,200,220,220,40,40,40,60, 200,200,220,220,20,40,40,60, 180,200,200,220,40,40,20,20,
200,200,220,220,20,40,40,60, 180,200,200,220,40,40,20,20, 180,180,200,200,40,60,20,40,
180,200,200,220,20,20,40,40, 180,180,200,200,40,60,20,40, 180,200,200,220,20,20,40,40
},box;
void initgr(void) /* BGI初始化 */
{
int gd = DETECT, gm = 0;
registerbgidriver(EGAVGA_driver);
initgraph(&gd, &gm, "");
}
main()
{ /************* 函数声明***************/
void initialize(void);
void begin(void);
void down(void);
void right(void);
void left(void);
void shape(void);
void cover(void);
void choic(void);
/*************************************/
initgr();
initialize();
while(1)
{int i;
i=bioskey(0);
if(i==ENTER)begin();
if(i==ESC)exit(0);
}
}
void initialize(void)/* 游戏范围 */
{
setcolor(LIGHTGRAY);
rectangle(9,9,391,461);
}
void begin(void) /* 产生随机方块 */
{ while(1)
{ int n,p;
randomize();
n=random(6);
p=random(4);
box.x[0]=box_first[n][p].x[0];
box.x[1]=box_first[n][p].x[1];
box.x[2]=box_first[n][p].x[2];
box.x[3]=box_first[n][p].x[3];
box.y[0]=box_first[n][p].y[0];
box.y[1]=box_first[n][p].y[1];
box.y[2]=box_first[n][p].y[2];
box.y[3]=box_first[n][p].y[3];
choic();
}
}
void left() /* 左 */
{ cover();
box.x[0]-=20;
box.x[1]-=20;
box.x[2]-=20;
box.x[3]-=20;
down();
}
void right()
{ cover();
box.x[0]+=20;
box.x[1]+=20;
box.x[2]+=20;
box.x[3]+=20;
down();
}
void shape()
{;
}
void down()
{
if(box.y[3]+10<460)
{ cover();
setcolor(LIGHTGRAY);
rectangle(box.x[0]-9,box.y[0]-8,box.x[0]+9,box.y[0]+10);
rectangle(box.x[1]-9,box.y[1]-8,box.x[1]+9,box.y[1]+10);
rectangle(box.x[2]-9,box.y[2]-8,box.x[2]+9,box.y[2]+10);
rectangle(box.x[3]-9,box.y[3]-8,box.x[3]+9,box.y[3]+10);
box.y[0]++;
box.y[1]++;
box.y[2]++;
box.y[3]++;
delay(1000);
choic();
}
else begin();
}
void cover()
{setcolor(BLACK);
rectangle(box.x[0]-9,box.y[0]-9,box.x[0]+9,box.y[0]+9);
rectangle(box.x[1]-9,box.y[1]-9,box.x[1]+9,box.y[1]+9);
rectangle(box.x[2]-9,box.y[2]-9,box.x[2]+9,box.y[2]+9);
rectangle(box.x[3]-9,box.y[3]-9,box.x[3]+9,box.y[3]+9);
}
void choic()
{
if(bioskey(1)!=0)
switch (bioskey(0))
{case ESC:exit(0);
break;
case LEFT:left();
break;
case RIGHT:right();
break;
case SPACE:shape();
break;
case DOWN:down();
break;
default:down();
break;
}
down();
}
修改了下 现在20次左右就停了
[此贴子已经被作者于2007-3-18 17:00:59编辑过]