跪求C语言snake代码,运行环境:vc++6.0或代码块。网站上的东西以前都是在tc环境下运行的。
# include & ltstdlib.h & gt
# include & lttime.h & gt
# include & ltconio.h & gt
typedef结构蛇
{
int a;
int b;
struct snake * u;
struct snake * n;
}snake,* snake 1;
typedef结构食品
{
int a;
int b;
}食物;
void main()
{
char c,c0 = ' d
int i,j,k,n=1,t,at;
蛇p,q;
snake *dd,*dd0,*dd1,* dd2
食物f;
srand(time(NULL));
p.u = NULL
p.n = & ampq;
p . a = 5;p . b = 6;q . a = 5;q . b = 5;
q.u = & ampp;q.n = NULL
dd = dd2 = & ampq;
f . a =(rand()% 15+1);
f . b =(rand()% 15+1);
while(1)
{
srand(time(NULL));
系统(“cls”);
for(I = 0;我& lt17;i ++)
{
for(j = 0;j & lt17;j++)
{
如果(i == 0)
printf("▁”);
else if(i == 16)
printf("▔”);
else if(j == 0)
printf("▕”);
else if(j == 16)
printf("▏”);
else if(I = = p . a & amp;& ampj == p.b)
printf("■");
else if(I = = f . a & amp;& ampj == f.b)
printf("★");
其他
{
t = 0;
dd = dd2
for(k = 0;k & ltn;k++)
{
if(I = = DD-& gt;a & amp& ampj = = DD-& gt;b)
{
printf("□");
t = 1;
打破;
}
DD = DD-& gt;u;
}
如果(t == 0)
printf(" ");
}
} printf(" \ n ");
}
at = 0;
dd = dd2
for(I = 0;我& ltn;i++)
{
if(p . a = = DD-& gt;a & amp& ampp . b = = DD-& gt;b)
{
printf("游戏结束!!\ n ");
退出(0);
}
DD = DD-& gt;u;
}
if(p . a = = f . a & amp;& ampp.b == f.b)
{
dd = dd2
at = 1;
f . a =(rand()% 15+1);
f . b =(rand()% 15+1);
for(I = 0;我& ltn;i++)
{
if(f . a = = DD-& gt;a & amp& ampf . b = = DD-& gt;b)
{
f . a = dd2-& gt;a;
f . b = dd2-& gt;b;
打破;
}
}
n++;
}
if(kbhit())
{
c = getch();
dd = dd2
if(c = = ' w ' & amp;& ampc0!= 's ')
{
if(at == 1)
{
dd0 =(snake 1)malloc(sizeof(snake));
dd0->;a = dd2-& gt;a;dd0->;b = dd2-& gt;b;
dd0->;n =空;dd0->;u = dd2
dd2 = dd0
}
dd = dd2
for(I = 0;我& ltn;i++)
{
DD 1 = DD-& gt;u;
DD-& gt;b = DD 1->;b;
DD-& gt;a = DD 1-& gt;a;
DD = DD-& gt;u;
}
如果(p.a == 1)
p . a = 15;
其他
p . a =(p . a-1)% 15;
}
else if(c = = ' s ' & amp;& ampc0!= 'w ')
{
if(at == 1)
{
dd0 =(snake 1)malloc(sizeof(snake));
dd0->;a = dd2-& gt;a;dd0->;b = dd2-& gt;b;
dd0->;n =空;dd0->;u = dd2
dd2 = dd0
}
dd = dd2
for(I = 0;我& ltn;i++)
{
DD 1 = DD-& gt;u;
DD-& gt;b = DD 1->;b;
DD-& gt;a = DD 1-& gt;a;
DD = DD-& gt;u;
}
p . a =(p . a % 15)+1;
}
else if(c = = ' a ' & amp;& ampc0!= 'd ')
{
if(at == 1)
{
dd0 =(snake 1)malloc(sizeof(snake));
dd0->;a = dd2-& gt;a;dd0->;b = dd2-& gt;b;
dd0->;n =空;dd0->;u = dd2
dd2 = dd0
}
dd = dd2
for(I = 0;我& ltn;i++)
{
DD 1 = DD-& gt;u;
DD-& gt;b = DD 1->;b;
DD-& gt;a = DD 1-& gt;a;
DD = DD-& gt;u;
}
if(p.b == 1)
p . b = 15;
其他
p . b =(p . b-1)% 15;
}
else if(c = = ' d ' & amp;& ampc0!= 'a ')
{
if(at == 1)
{
dd0 =(snake 1)malloc(sizeof(snake));
dd0->;a = dd2-& gt;a;dd0->;b = dd2-& gt;b;
dd0->;n =空;dd0->;u = dd2
dd2 = dd0
}
dd = dd2
for(I = 0;我& ltn;i++)
{
DD 1 = DD-& gt;u;
DD-& gt;b = DD 1->;b;
DD-& gt;a = DD 1-& gt;a;
DD = DD-& gt;u;
}
p . b =(p . b % 15)+1;
}
其他
{
转QQ;
}
c0 = c;
}
其他
{
QQ:if(c0 = = ' w ')
{
if(at == 1)
{
dd0 =(snake 1)malloc(sizeof(snake));
dd0->;a = dd2-& gt;a;dd0->;b = dd2-& gt;b;
dd0->;n =空;dd0->;u = dd2
dd2 = dd0
}
dd = dd2
for(I = 0;我& ltn;i++)
{
DD 1 = DD-& gt;u;
DD-& gt;b = DD 1->;b;
DD-& gt;a = DD 1-& gt;a;
DD = DD-& gt;u;
}
如果(p.a == 1)
p . a = 15;
其他
p . a =(p . a-1)% 15;
}
else if(c0 == 's ')
{
if(at == 1)
{
dd0 =(snake 1)malloc(sizeof(snake));
dd0->;a = dd2-& gt;a;dd0->;b = dd2-& gt;b;
dd0->;n =空;dd0->;u = dd2
dd2 = dd0
}
dd = dd2
for(I = 0;我& ltn;i++)
{
DD 1 = DD-& gt;u;
DD-& gt;b = DD 1->;b;
DD-& gt;a = DD 1-& gt;a;
DD = DD-& gt;u;
}
p . a =(p . a % 15)+1;
}
else if(c0 == 'a ')
{
if(at == 1)
{
dd0 =(snake 1)malloc(sizeof(snake));
dd0->;a = dd2-& gt;a;dd0->;b = dd2-& gt;b;
dd0->;n =空;dd0->;u = dd2
dd2 = dd0
}
dd = dd2
for(I = 0;我& ltn;i++)
{
DD 1 = DD-& gt;u;
DD-& gt;b = DD 1->;b;
DD-& gt;a = DD 1-& gt;a;
DD = DD-& gt;u;
}
if(p.b == 1)
p . b = 15;
其他
p . b =(p . b-1)% 15;
}
else if(c0 == 'd ')
{
if(at == 1)
{
dd0 =(snake 1)malloc(sizeof(snake));
dd0->;a = dd2-& gt;a;dd0->;b = dd2-& gt;b;
dd0->;n =空;dd0->;u = dd2
dd2 = dd0
}
dd = dd2
for(I = 0;我& ltn;i++)
{
DD 1 = DD-& gt;u;
DD-& gt;b = DD 1->;b;
DD-& gt;a = DD 1-& gt;a;
DD = DD-& gt;u;
}
p . b =(p . b % 15)+1;
}
}
fflush(stdin);
dd = & ampq;
_ sleep(0);
}
}
望采纳并加分。