贪吃蛇找食物C++

这个作品不是自动走
是和走迷宫一样
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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值