这个作品不是自动走
是和走迷宫一样
WSAD操控
有个bug是有时蛇走到食物上面蛇会消失,食物还在,大佬在评论区给我说一下原因吧。
#include <iostream>
#include <ctime>
#include <unistd.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <set>
#include <cstdlib>
#define qp system("clear")
#define ioi(x) (sleep(x))
#define r(x) (rand()%x)
#define c cout
#define end endl;
using namespace std;
int main()
{
int x,y;
int she1,she2;
int shes1,shes2;
int da1,da2;
x=r(6)+1;
y=r(7)-1;
int chang;
char m;
chang=10;
m='m';
c<<"欢迎来到贪吃蛇(w上s下a左d右)\n"<<"*是10m,$是30m"<<end
char map[8][8]={
{'#','#','#','#','#','#','#','#'},
{'#',' ',' ',' ',' ',' ',' ','#'},
{'#',' ',' ',' ',' ',' ',' ','#'},
{'#',' ',' ',' ',' ',' ',' ','#'},
{'#',' ',' ',' ',' ',' ',' ','#'},
{'#',' ',' ',' ',' ',' ',' ','#'},
{'#',' ',' ',' ',' ',' ',' ','#'},
{'#','#','#','#','#','#','#','#'}
};
for(int i=0;i<=7;i++)
{
for(int j=0;j<=7;j++)
{
c<<map[i][j];
}
c<<end
};
map[x][y]='*';
ioi(2);
int tou1,tou2;
tou1=2;
tou2=2;
int chi;
map[tou1][tou2]='@';
while(chang<700)
{
if(chang==80||chang==120||chang==170||chang==240||chang==300||chang==360||chang==410||chang==480||chang==550)
{
da1=r(6)+1;
da2=r(6)+1;
map[da1][da2]='$';
}
qp;
c<<chang<<m<<end
for(int i=0;i<=7;i++)
{
for(int j=0;j<=7;j++)
{
c<<map[i][j];
}
c<<end
}
char jianpan;
cin>>jianpan;
if((jianpan=='w')&&(map[tou1-1][tou2]!='#'))
{ if(map[tou1-1][tou2]=='*')
{
chang=chang+10;
}
if(map[tou1-1][tou2]=='$')
{
chang=chang+30;
}
tou1=tou1-1;
map[tou1][tou2]='@';
map[tou1+1][tou2]=' ';
qp;
c<<chang<<m<<end
for(int i=0;i<=7;i++)
{
for(int j=0;j<=7;j++)
{
c<<map[i][j];
}
c<<end
}
}
else if((jianpan=='a')&&(map[tou1][tou2-1]!='#'))
{ if(map[tou1][tou2-1]=='*')
{
chang=chang+10;
}
if(map[tou1][tou2-1]=='$')
{
chang=chang+30;
}
tou2=tou2-1;
map[tou1][tou2]='@';
map[tou1][tou2+1]=' ';
qp;
c<<chang<<m<<end
for(int i=0;i<=7;i++)
{
for(int j=0;j<=7;j++)
{
c<<map[i][j];
}
c<<end
}
}
else if((jianpan=='d')&&(map[tou1][tou2+1]!='#'))
{ if(map[tou1][tou2+1]=='*')
{
chang=chang+10;
}
if(map[tou1][tou2+1]=='$')
{
chang=chang+30;
}
tou2=tou2+1;
map[tou1][tou2]='@';
map[tou1][tou2-1]=' ';
qp;
c<<chang<<end
for(int i=0;i<=7;i++)
{
for(int j=0;j<=7;j++)
{
c<<map[i][j];
}
c<<end
}
}
else if((jianpan=='s')&&(map[tou1+1][tou2]!='#'))
{ if(map[tou1+1][tou2]=='*')
{
chang=chang+10;
}
if(map[tou1+1][tou2]=='$')
{
chang=chang+30;
}
tou1=tou1+1;
map[tou1][tou2]='@';
map[tou1-1][tou2]=' ';
qp;
c<<chang<<end
for(int i=0;i<=7;i++)
{
for(int j=0;j<=7;j++)
{
c<<map[i][j];
}
c<<end
}
}
qp;
int x1,y1;
x1=r(6)+1;
y1=r(6)+1;
map[x1][y1]='*';
c<<chang<<m<<end
for(int i=0;i<=7;i++)
{
for(int j=0;j<=7;j++)
{
c<<map[i][j];
}
c<<end
}
}
return 0;
}