那位能帮我看看该怎么做!
#include<graphics.h>
#include<stdlib.h>
#include<time.h>
struct project{
int left,top,right,bottom;
};
struct project A[6],food;
void build(struct project t[6]);
void inputdata(struct project t[6]);
void Process(void);
void conversion(struct project t[6]);
void delete(struct project t[6]);
void appearfood(struct project *f);
int eatfood(struct project t[6],struct project *f);
void deletefood(struct project *f);
int main(void)
{
int gdriver=DETECT,gmode;
srand(time(NULL));
initgraph(&gdriver,&gmode,"c:\\tc");
inputdata(A);
build(A);
Process();
getch();
closegraph();
return 0;
}
void inputdata(struct project t[11])
{
int i;
for(i=1;i<=5;i++)
{
t[i].left=100+i*10-10;
t[i].top=100;
t[i].right=100+i*10;
t[i].bottom=100+10;
}
}
void build(struct project t[6])
{
int i;
setcolor(2);
for(i=1;i<=5;i++)
rectangle(t[i].left,t[i].top,t[i].right,t[i].bottom);
}
void Process(void)
{
char KEY;
appearfood(&food); /*appear food*/
while(1)
{
if(eatfood(A,&food)) /*如果成功吃掉食物,将食物删除*/
deletefood(&food);
if(kbhit())
{
KEY=getch();
if(KEY==115) /*KEY=s*/
{
delete(A);
conversion(A);
A[5].left=A[5].left;
A[5].top=A[5].top+10;
A[5].right=A[5].right;
A[5].bottom=A[5].bottom+10;
build(A);
}
if(KEY==100) /*KEY==d*/
{
delete(A);
conversion(A);
A[5].left=A[5].left+10;
A[5].top=A[5].top;
A[5].right=A[5].right+10;
A[5].bottom=A[5].bottom;
build(A);
}
if(KEY==119) /*KEY=w*/
{
delete(A);
conversion(A);
A[5].left=A[5].left;
A[5].top=A[5].top-10;
A[5].right=A[5].right;
A[5].bottom=A[5].bottom-10;
build(A);
}
if(KEY==97) /*KEY==97*/
{
delete(A);
conversion(A);
A[5].left=A[5].left-10;
A[5].top=A[5].top;
A[5].right=A[5].right-10;
A[5].bottom=A[5].bottom;
build(A);
}
if(KEY==27) /*KEY=esc*/
break; /*break only exit one while sentence*/
} /*if*/
} /*while*/
} /*Process function*/
void conversion(struct project t[6])
{
int i;
for(i=2;i<=5;i++)
t[i-1]=t[i];
}
void delete(struct project t[6])
{
setcolor(0);
rectangle(t[1].left,t[1].top,t[1].right,t[1].bottom);
}
void appearfood(struct project *f) /*食物出现函数*/
{
setfillstyle(1,3);
f->left=rand()%600;
f->top=rand()%400;
f->right=f->left+10;
f->bottom=f->top+10;
bar(f->left,f->top,f->right,f->bottom);
}
int eatfood(struct project t[6],struct project *f) /*吃食物函数*/
{
int flag=0;
if(t[10].left==f->left||t[10].top==f->top||t[10].right==f->right||t[10].bottom==f->bottom)
flag=1;
return flag;
}
void deletefood(struct project *f) /*删除食物函数*/
{
setfillstyle(1,0);
bar(f->left,f->top,f->right,f->bottom);
}
那位大哥哥能帮我看看该怎么做啊!