回复:(anlogo)把所有程序贴出来才看得明白~~
我把程序又改了一下,以下面这个为准,但是还是有同样的问题~
/*这就是关键部分,程序还没有写完,但是这些已经能够测试蛇的移动了,可以编译,问题就是蛇尾不会移动!!!
说明:蛇每一节的尺寸为10*10的正方形,目前该程序完成的功能仅为初始画出蛇并默认向右移动*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define esc 0x011b
#define left 0x4b00
#define right 0x4d00
#define up 0x4800
#define down 0x5000
#define maxsize 1000
struct therange
{
int top;
int bottom;
int leftside;
int rightside;
}range;
struct thesnake
{
int x[maxsize];
int y[maxsize];
int len;
int life;
int direction;
}snake;
void drawrange()/*画边界*/
{
range.top=50;
range.bottom=400;
range.leftside=50;
range.rightside=400;
setcolor(4);
bar(40,40,50,410);
bar(50,400,410,410);
bar(40,40,410,50);
bar(400,50,410,410);
}
main()
{
int x;
int y;
int i,j;
int startplace;
int gdrive,gmode;
gdrive=DETECT;
initgraph(&gdrive,&gmode,"");
setbkcolor(2);
drawrange();
startplace=250;/*起始位置*/
snake.len=2;/*蛇的最后一节的相对位置*/
snake.x[0]=startplace;/*蛇头x坐标*/
snake.y[0]=startplace;/*蛇头y坐标*/
snake.x[snake.len]=snake.x[0]-30;/*蛇尾的x坐标,开始为一个三节长的蛇*/
snake.y[snake.len]=snake.x[0];/*蛇尾的y坐标*/
setcolor(0);/*蛇身的颜色*/
bar(snake.x[snake.len],snake.y[snake.len],snake.x[0],snake.y[0]);/*画出初始三节的蛇*/
while(!kbhit())
{
delay(700000);
snake.x[0]+=10;/*新的蛇头的x坐标*/
setcolor(0);/*画出新的蛇头*/
bar(snake.x[0],snake.y[0],snake.x[0]+10,snake.y[0]+10);
setcolor(2);/*用背景色画蛇尾*/
bar(snake.x[snake.len],snake.y[snake.len],snake.x[snake.len]+10,snake.y[snake.len]+10);
snake.x[snake.len]+=10;/*画完当前蛇尾后自动保存下一次循环蛇尾的位置*/
}
getch();
closegraph();
}
[此贴子已经被作者于2007-7-27 21:05:54编辑过]