贪吃蛇代码(C++实现)

  • 格式:txt
  • 大小:7.76 KB
  • 文档页数:3
map[sum/100][sum%100]=0;
i++;
i%=ML;
}
}
else
{
T.body[T.head++]=sum;
T.head%=ML;
T.tail=(++T.tail)%ML;
}
}
void ddd()
{
int sum,i;
}
if(order=='w')
{
jud=order;
//printf("-->w\n");
if(map[sum/100-1][sum%100]!=-1)
{
for(i=T.tail;i!=T.head;)
{
temp=T.body[i];
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
ddd();
}
else
{
system("CLS");
printf("哈哈,你输了!最后得分:%d\n",T.length*10-10);
break;
}
}
else if (order=='s')
{
jud=order;
//printf("-->s\n");
if(map[sum/100+1][sum%100]!=-1)
{
for(i=T.tail;i!=T.head;)
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<conio.h>
#include<time.h>
#include<windows.h>
#define ML 100
using namespace std;
map[sum/100][sum%100]=0;
i++;
i%=ML;
}
}
else
{
T.body[T.head++]=sum;
T.head%=ML;
T.tail=(++T.tail)%ML;
}
}
int main()
{
memset(map,0,sizeof(map));
T.tail=(++T.tail)%ML;
}
}
void sss()
{
int sum,i;
sum=T.body[(T.head-1+ML)%ML]+100;
if(map[sum/100][sum%100]==1)
{
T.length++;
T.body[T.head++]=sum;
map[sum/100][sum%100]=-1;
i++;
i%=ML;
}
while(1)
{
sum=getnum();
if(map[sum/100][sum%100]==0)
{
map[sum/100][sum%100]=1;
break;
break;
}
}
else if(order=='a')
{
jud=order;
//printf("-->a\n");
if(map[sum/100][sum%100-1]!=-1)
{
for(i=T.tail;i!=T.head;)
memset(maze,' ',sizeof(maze));
int i,j,sum=0,k=0,temp;
for(i=1;i<20;i++)
for(j=1;j<20;j++)
{
card[k++]=i*100+j;
}
srand(time(0));
temp=rand()%10+1;
T_T=0;
char jud='s';
int TM=300,start;
while(1)
{
TM=300-T.length*15;
start=clock();
while(clock()-start<=TM&&!kbhit())
{
;
}
if(kbhit()&&(order=getch(),order=='w'||order=='s'||order=='a'||order=='d'))
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
www();
}
else
{
system("CLS");
printf("哈哈,你输了!最后得分:%d\n",T.length*10-10);
while(temp--)
random_shuffle(card,card+19*19);
for(i=0;i<=20;i++)
map[i][0]=map[20][i]=map[i][20]=map[0][i]=-1;
init();
T.length=1;
/*while(sum/100>19||sum%100>19||map[sum/100][sum%100]==-1)
sum=T.body[(T.head-1+ML)%ML]+1;
if(map[sum/100][sum%100]==1)
{
T.length++;
T.body[T.head++]=sum;
T.head%=ML;
map[sum/100][sum%100]=0;
for(i=T.tail;i!=T.head;)
break;
}
}
else if(order=='d')
{
jud=order;
//printf("-->d\n");
if(map[sum/100][sum%100+1]!=-1)
{
for(i=T.tail;i!=T.head;)
if(map[sum/100][sum%100]==1)
{
T.length++;
T.body[T.head++]=sum;
T.head%=ML;
map[sum/100][sum%100]=0;
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
sss();
}
else
{
system("CLS");
printf("哈哈,你输了!最后得分:%d\n",T.length*10-10);
{
srand(time(0));
sum=rand()%10000+101;
}*/
T.body[T.head++]=101;
//printf("%d\n",sum);
T.head%=ML;
sum=getnum();
map[sum/100][sum%100]=1;
{
sum=getnum();
if(map[sum/100][sum%100]==0)
{
map[sum/100][sum%100]=1;
break;
}
}
for(i=T.tail;i!=T.had;) { sum=T.body[i];
T.head%=ML;
map[sum/100][sum%100]=0;
for(i=T.tail;i!=T.head;)
{
sum=T.body[i];
map[sum/100][sum%100]=-1;
i++;
i%=ML;
}
while(1)
{
temp=T.body[i];
map[temp/100][temp%100]=0;
i++;
i%=ML;
}
aaa();
}
else
{
system("CLS");
printf("哈哈,你输了!最后得分:%d\n",T.length*10-10);
}
int card[400],T_T;

下载文档原格式

  / 3