zoukankan      html  css  js  c++  java
  • 控制台小游戏-贪吃蛇,c++和c#版

    说是c++版,其实只是用到了c++的cout和cin而已。这是我做的第二个控制台游戏,基本上每一行代码都加上了注释。

    游戏嘛,我觉得重要的是了解他的思想,所以后期学了面向对象之后这个游戏的代码我也没有重新封装。

    下面请看图

    代码如下:我是用dev c++写的

      1 //注释。 ---星辰 
      2 
      3 #include <iostream>
      4 #include<Windows.h>
      5 #include<ctime>
      6 #include<cstdlib>
      7 #include "conio.h"//非标准输入输出库函数 
      8 
      9 using namespace std;
     10 
     11 
     12 const int UP=72;//
     13 const int DOWN=80;//
     14 const int LEFT=75;//
     15 const int RIGHT=77;//
     16 
     17 int n=4;//n用来记录蛇身长度,初始为2节
     18 int guan;//用来记录关卡
     19 int T;//用来给记录蛇的移动速度
     20 int t1,t2,t3=0;//用来记录以用时间
     21 int HP=5;//记录蛇的生命值,初始化为6
     22 int food=0;//用来记录所吃到的食物数
     23 int x=12,y=12;//记录食物所在地
     24 
     25 struct snake
     26 {
     27     int x;//蛇身所在横坐标
     28     int y;//蛇身所在纵坐标
     29     int direction;//行走方向
     30 }p[81];
     31 
     32 
     33 struct map
     34 {
     35     int food;//此map[x][y]处是否有食物有的话food为1
     36     int star;//此map[x][y]处是否有星星的话值为1
     37     int barrier;//此map[x][y]处是否有障碍物有的话值为1
     38 }map[26][22];
     39 
     40 
     41 inline void c(int k)//改变输出字体的颜色
     42 {
     43     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), k);
     44 }
     45 
     46 inline int time()//用来计时
     47 {
     48     clock_t t=clock()/CLOCKS_PER_SEC;//记录当前程序已用时间
     49     return t;
     50 }
     51 
     52 inline void gotoxy(int x,int y) //移动坐标
     53 {
     54     COORD coord; 
     55     coord.X=x;
     56     coord.Y=y;
     57     SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
     58 }
     59 
     60 inline int random()//用来输出随机值
     61 {
     62     srand(t1+rand());//将随机数种子初始化
     63     return rand();//返回随机数
     64 }
     65 
     66 void ycgb(int);//隐藏光标
     67 void start();//绘制启动画面以及隔墙
     68 void guanka();//用来选择关卡并根据关卡设置蛇的移动速度
     69 void data();//用来记录游戏的各种状态数据
     70 int game();//游戏运行
     71 void show();//用来随机产生障碍物以及食物和生命药水以及用来判断游戏的各种参数(小星星是否吃到,是否撞墙)
     72 void key();//用户是否操作键盘
     73 void qp();//清除屏幕
     74 
     75 
     76 int main()
     77 {
     78     ycgb(0);//隐藏光标
     79     start();//绘制启动画面以及隔墙
     80     while(1)
     81     {
     82        guanka();//用来选择关卡并根据关卡设置蛇的移动速度
     83        ycgb(0);//隐藏光标
     84        if(!game()) break;//游戏运行
     85     }
     86 }
     87 
     88 void ycgb(int k)//隐藏光标
     89 {
     90     HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
     91     CONSOLE_CURSOR_INFO cci;
     92     GetConsoleCursorInfo(hOut,&cci);
     93     cci.bVisible=k;//赋1为显示,赋0为隐藏
     94     SetConsoleCursorInfo(hOut,&cci);
     95 }
     96 
     97 
     98 void start()//绘制墙/绘制启动画面以及隔墙
     99 {
    100     int i,j,z;
    101     for(i=0;i<25;i++)
    102     {
    103         cout<<"                                                                                ";
    104     }
    105     c(14);//调成红色
    106     for(z=0;z<20;z++)
    107     {
    108         if(z>=0)
    109         {
    110             gotoxy(12,z);
    111             cout<<"              ~--______-~                ~-___-~"       ";  
    112         }
    113         if(z>=1)
    114         {
    115             gotoxy(12,z-1);
    116             cout<<"            ~-_           _-~          ~-_       _-~    ";
    117         }
    118         if(z>=2)
    119         {
    120             gotoxy(12,z-2);
    121             cout<<"          \     ~-____-~     _-~    ~-_    ~-_-~    / ";
    122         }
    123         if(z>=3)
    124         {
    125             gotoxy(12,z-3);
    126             cout<<"         (     (         _-~    _--_    ~-_    _/   |  ";
    127         }
    128         if(z>=4)
    129         {
    130             gotoxy(12,z-4);
    131             cout<<"          /    /            _-~      ~-_        |   |  "; 
    132         }
    133         if(z>=5)
    134         {
    135             gotoxy(12,z-5);
    136             cout<<"           /    /              _----_           \  \ ";
    137         }
    138         if(z>=6)
    139         {
    140             gotoxy(12,z-6);
    141             cout<<"             /    /                            \ \   ";
    142         }
    143         if(z>=7)
    144         {
    145             gotoxy(12,z-7);
    146             cout<<"              /    /                          \\     ";
    147         }
    148         if(z>=8)
    149         {
    150             gotoxy(12,z-8);
    151             cout<<"                /    /                      \\       ";
    152         }
    153         if(z>=9)
    154         {
    155             gotoxy(12,z-9);
    156             cout<<"                 /     /                   \            ";
    157         }
    158         if(z>=10)
    159         {
    160             gotoxy(12,z-10);
    161             cout<<"                  |     |                \                ";
    162         }
    163         if(z>=11)
    164         {
    165             gotoxy(12,z-11);
    166             cout<<"                 \     \                                 ";
    167         }
    168         if(z>=12)
    169         {
    170             gotoxy(12,z-12);
    171             cout<<"        \_______      \                                  ";
    172         }
    173         if(z>=13)
    174         {
    175             gotoxy(12,z-13);
    176             cout<<" \____|__________/  \                                    "; 
    177         }
    178         if(z>=14)
    179         {
    180             gotoxy(12,z-14);
    181             cout<<"\/     /~     \_/ \                                     ";
    182         }
    183         if(z>=15)
    184         {
    185             gotoxy(12,z-15);
    186             cout<<"        _|__|  O|                                          ";
    187         }
    188         for(int k=15;k<z;k++)
    189         {
    190             gotoxy(12,k-15);
    191             cout<<"                                                           ";
    192         }
    193         Sleep(30);
    194     }
    195     Sleep(2000);
    196     c(0);//调成黑底色
    197     gotoxy(0,0);
    198     for(i=0;i<25;i++)
    199     {
    200         cout<<"                                                                                ";
    201     }
    202     c(252);//调整输出颜色 
    203     for(i=0,j=60;i<60;i++,j--)//if是为了异步输出 
    204     {
    205        if(j>20)
    206        {              
    207            gotoxy(2*(j-21),0);
    208            cout<<"";//输出第一行
    209        }                                            
    210        if(i<40)
    211        {
    212            gotoxy(2*i,23);
    213            cout<<"";// 输出最下面一行 
    214        }  
    215        if(j>22&&j<45)
    216        {
    217            gotoxy(78,j-22);
    218            cout<<"";//输出最右边列
    219        }    
    220        if(j>22&&j<45)
    221        {
    222            gotoxy(0,i-15);
    223            cout<<"";//输出第一列
    224        }
    225        if(i>37&&i<60)
    226        {
    227            gotoxy(54,i-37);
    228            Sleep(10);
    229            cout<<"";//输出中间那列
    230        } 
    231        Sleep(30);
    232      }
    233      gotoxy(56,11);
    234      cout<<"▉▉▉▉▉▉▉▉▉▉▉";                                            //56 
    235      gotoxy(19,0);    
    236      c(14);//调整输出颜色 
    237      cout<<"| | |贪 吃 蛇| | |";//输出标题 
    238      
    239      gotoxy(56,2);
    240      cout<<"已用时间:";
    241      gotoxy(75,2);
    242      cout<<"";
    243      gotoxy(56,4);
    244      cout<<"生命值:";
    245      gotoxy(56,6);
    246      cout<<"当前长度:";
    247      gotoxy(56,8);
    248      cout<<"已吃食物:";
    249      gotoxy(56,10);
    250      cout<<"第             关";
    251      gotoxy(64,12);
    252      cout<<"提示:";
    253      gotoxy(56,13);
    254      cout<<"向上:↑   向上:←"; 
    255      gotoxy(56,14);
    256      cout<<"向下:↓   向右:→";
    257      gotoxy(56,15);
    258      cout<<"暂停/开始:确定键 ";
    259      gotoxy(56,16);
    260      cout<<"重新选关 :Esc键";
    261      gotoxy(64,18);
    262      cout<<"注意!";
    263      gotoxy(56,19);
    264      cout<<"1:撞到障碍物或者墙生命";
    265      gotoxy(56,20);
    266      cout<<"  值减一 ";
    267      gotoxy(56,21);
    268      cout<<"2:吃到小星星生命值加一";  
    269 }
    270 void guanka()//用来选择关卡并根据关卡设置蛇的移动速度
    271 {
    272     ycgb(1);//显示光标
    273     n=4;//n用来记录蛇身长度,初始为3节
    274     HP=6;//记录蛇的生命值,初始化为6
    275     p[0].x=6;                    //
    276     p[0].y=10;                   //
    277     p[0].direction=RIGHT;        //
    278     p[1].x=4;                   //
    279     p[1].y=10;                  //     初始化蛇所在位置和移动方向   
    280     p[1].direction=RIGHT;       //
    281     p[2].x=2;                   //
    282     p[2].y=10;                  //
    283     p[2].direction=RIGHT;      //
    284     p[3].x=4;////////////////
    285     p[3].y=4;///////////////记录蛇尾的信息
    286     p[3].direction=RIGHT;////
    287     while(1)
    288     {
    289         gotoxy(15,3);
    290         cout<<"请输入关数(1-6):";
    291         cin>>guan;
    292         cin.get();
    293         if(guan==0)     //判断是否作弊
    294         {
    295             gotoxy(15,3);
    296             c(12);//变成红色
    297             cout<<"  作弊有害智商,需谨慎";
    298             gotoxy(15,5);
    299             c(14);//变成黄色
    300             cout<<"请输入你想要的蛇的生命值:";
    301             cin>>HP;
    302             cin.get();
    303             gotoxy(15,3);
    304             cout<<"                      ";
    305             gotoxy(15,5);
    306             cout<<"                                    ";
    307             continue;//返回选关处
    308         }
    309         if(guan<7&&guan>0) break;//判断关数是否溢出
    310         gotoxy(15,5);
    311         cout<<"输入错误!";
    312         gotoxy(32,3);
    313         cout<<"          ";
    314         
    315     }
    316     gotoxy(15,3);
    317     cout<<"                   ";
    318     switch (guan)
    319     {
    320         case 1:{T=600;break;}//
    321         case 2:{T=400;break;}//
    322         case 3:{T=200;break;}//    根据关数来设定蛇的移动速度
    323         case 4:{T=150;break;}//
    324         case 5:{T=100;break;}//
    325         case 6:{T=60;break;}//
    326     }
    327     qp();//清除屏幕
    328 }
    329 void data()//用来记录和判断游戏的各种状态数据
    330 {
    331     gotoxy(66,2);
    332     c(12);//调成红色
    333     cout<<t1;//程序已用时间
    334     switch (guan)
    335     {
    336     case 1:
    337         gotoxy(59,10);
    338         c(12);//调成红色
    339         cout<<"1";
    340         c(14);//调成黄色
    341         cout<<" 2 3 4 5 6";
    342         break;
    343     case 2:
    344         gotoxy(59,10);
    345         c(14);//调成黄色
    346         cout<<"1 ";
    347         c(12);//调成红色
    348         cout<<"2";
    349         c(14);//调成黄色
    350         cout<<" 3 4 5 6 ";
    351         break;
    352     case 3:
    353         gotoxy(59,10);
    354         c(14);//调成黄色
    355         cout<<"1 2 ";
    356         c(12);//调成红色
    357         cout<<"3";
    358         c(14);//调成黄色
    359         cout<<" 4 5 6 ";
    360         break;
    361     case 4:
    362         gotoxy(59,10);
    363         c(14);//调成黄色
    364         cout<<"1 2 3 ";
    365         c(12);//调成红色
    366         cout<<"4";
    367         c(14);//调成黄色
    368         cout<<" 5 6 ";
    369         break;
    370     case 5:
    371         gotoxy(59,10);
    372         c(14);//调成黄色
    373         cout<<"1 2 3 4 ";
    374         c(12);//调成红色
    375         cout<<"5";
    376         c(14);//调成黄色
    377         cout<<" 6 ";
    378         break;
    379     case 6:
    380         gotoxy(59,10);
    381         c(14);//调成黄色
    382         cout<<"1 2 3 4 5 ";
    383         c(12);//调成红色
    384         cout<<"6";
    385         break;
    386     }
    387     switch (HP)
    388     {
    389     case 1:
    390         gotoxy(65,4);
    391         c(10);//调成绿色
    392         cout<<""; 
    393         c(12);//调成红色
    394         cout<<"▂▃▅▆▇";
    395         break;
    396     case 2:
    397         gotoxy(65,4);
    398         c(10);//调成绿色
    399         cout<<"▁▂"; 
    400         c(12);//调成红色
    401         cout<<"▃▅▆▇";
    402         break;
    403     case 3:
    404         gotoxy(65,4);
    405         c(10);//调成绿色
    406         cout<<"▁▂▃";
    407         c(12);//调成红色
    408         cout<<"▅▆▇";
    409         break;
    410     case 4:
    411         gotoxy(65,4);
    412         c(10);//调成绿色
    413         cout<<"▁▂▃▅";
    414         c(12);//调成红色
    415         cout<<"▆▇";
    416         break;
    417     case 5:
    418         gotoxy(65,4);
    419         c(10);//调成绿色
    420         cout<<"▁▂▃▅▆";
    421         c(12);//调成红色
    422         cout<<"";
    423         break;
    424     case 6:
    425         gotoxy(65,4);
    426         c(10);//调成绿色
    427         cout<<"▁▂▃▅▆▇";
    428         break;
    429     default:
    430         gotoxy(65,4);
    431         c(10);//调成红色
    432         cout<<"!超级模式 !";
    433         break;
    434     }
    435     gotoxy(66,6);
    436     c(12);//调成红色
    437     cout<<n-1;//输出蛇的当前长度
    438     gotoxy(66,8);
    439     cout<<food;//输出蛇当前已经吃到食物
    440 }
    441 void qp()//用来清除屏幕
    442 {
    443     for(int i=1;i<23;i++)
    444     {
    445        gotoxy(2,i);
    446        cout<<"                                                    ";
    447     } 
    448     map[x][y].food=0;//将食物清空
    449     map[x][y].barrier=0;//将障碍物清除
    450     map[x][y].star=0;//将星星清除 
    451 }
    452 
    453 void show()//用来随机产生障碍物以及食物和生命药水以及用来判断游戏的各种参数
    454 {
    455     int a,b,e,f; //a,b用来表示小星星的坐标   c,d代表障碍物坐标
    456     if(map[x][y].food==0)//判断食物是不是被吃掉
    457     { 
    458         while(1)
    459         {                                                                                                  
    460             x=random()%26;//产生随机横坐标
    461             y=random()%22;//产生随机纵坐标
    462             if(map[x][y].barrier==0&&map[x][y].star==0) break;//当此处无其他元素是才生效 
    463         }
    464         map[x][y].food=1;//随机出现食物
    465         gotoxy(2*(x+1),y+1);//定位到食物出现的位置
    466         c(11);//调成黄色
    467         cout<<"";//打印出食物
    468     }
    469     if(t1/20>0&&t1%12==0&&t1>t3&&map[(p[0].x-1)/2][p[0].y-1].food==0&&map[(p[0].x-1)/2][p[0].y-1].star==0)
    470     {
    471         while(1)
    472         {                                                                                                  
    473             e=random()%26;//产生随机横坐标
    474             f=random()%22;//产生随机纵坐标
    475             if(map[e][f].food==0&&map[e][f].star==0) break;//当此处无其他元素是才生效 
    476         }
    477         gotoxy(2*(e+1),f+1);//定位到障碍物出现的位置
    478         map[e][f].barrier=1;//随机出现障碍物
    479         c(12);//调成黄色
    480         cout<<"";//打印出障碍物
    481         t3=t1;//以免产生多个障碍物
    482         if(HP<7)
    483         {
    484           gotoxy(18,24);
    485           c(15);//调成白色
    486           cout<<"温馨提示:在选关的时候输入0可以开启作弊模式";
    487         }
    488     }
    489     if(t1/25>0&&t1%15==0&&t1>t3&&map[(p[0].x-1)/2][p[0].y-1].food==0&&map[(p[0].x-1)/2][p[0].y-1].barrier==0)//减少星星出现的几率 
    490     {
    491         while(1)
    492         {                                                                                                  
    493             a=random()%26;//产生随机横坐标
    494             b=random()%22;//产生随机纵坐标
    495             if(map[a][b].barrier==0&&map[a][b].food==0) break;//当此处无其他元素是才生效 
    496         }
    497         map[a][b].star=1;//随机出现小星星(吃到星星长度减1)
    498         gotoxy(2*(a+1),b+1);//定位到星星出现的位置(吃到星星长度减1)
    499         c(14);//调成黄色
    500         cout<<"";//打印出星星(吃到星星长度减1)
    501         t3=t1;//以免产生多个障碍物
    502         if(HP<7)
    503         {
    504            gotoxy(18,24);
    505            cout<<"                                            ";
    506         }
    507     }
    508     for(int i=0;i<n;i++)
    509     {
    510         if(map[(p[i].x-1)/2][p[i].y-1].food==1)//判断蛇是否吃到食物
    511         {
    512             ++n;//让蛇长度加1
    513             food++;//将食物数加1
    514             map[(p[i].x-1)/2][p[i].y-1].food=0;//让食物标示归零
    515             break;
    516         }
    517     }
    518     if(map[(p[0].x-1)/2][p[0].y-1].star==1)//判断蛇是否吃到星星
    519     {
    520         map[(p[0].x-1)/2][p[0].y-1].star=0;//让星星标示归零
    521         if(HP<6)
    522            ++HP;//将生命值加1
    523     }
    524     t1=time()-t2;//刷新游戏运行时间
    525 }
    526 void key()//用户是否操作键盘
    527 {
    528     if(kbhit())//判断是否按键
    529     {              
    530         int ch=getch();
    531         if(ch==224)//判断按的是不是方向键
    532         {
    533            ch=getch();               
    534            if((ch==72||ch==75||ch==80||ch==77)&&(ch+p[0].direction!=152)&&ch!=p[0].direction)  //判断按键是否是方向键,并且是不是蛇移动方向的反方向
    535                   p[0].direction=ch;//如果不是就改变蛇头方向
    536            else rewind(stdin); 
    537         }
    538         else if(ch==13)//判断用户是否暂停
    539         {
    540             clock_t a,b;
    541             a=time();//记录当前程序已用时间
    542             gotoxy(20,1);
    543             c(15);//调成白色
    544             cout<<"已暂停,按确定键开始";
    545             while(1)
    546             {
    547                 if(kbhit()&&getch()==13)////判断是否按键且是否解除暂停
    548                 {
    549                     gotoxy(20,1);
    550                     cout<<"                     ";//清除"已暂停,按确定键开始"这行字                     
    551                     break;
    552                 } 
    553             }
    554             b=time();//记录当前程序已用时间
    555             t2+=(b-a);//将暂停加到t2上供t1减去
    556         }
    557         else if(ch==27)//判断是否重新选关
    558         {
    559             guanka();//用来选择关卡并根据关卡设置蛇的移动速度
    560             game();//开始游戏        
    561         }
    562         else rewind(stdin); 
    563     }    
    564 }
    565 int game()
    566 {
    567     int i;
    568     int ch=RIGHT;//向右
    569     t2=time();//记录当前程序已用时间
    570     while(1)
    571     {
    572         t1=time()-t2;//刷新游戏运行时间
    573         data();//用来记录游戏的各种状态数据
    574         gotoxy(p[0].x,p[0].y);//转到蛇头位置
    575         c(12);//改成红色
    576         cout<<"";//打印蛇头
    577         for(i=1;i<n-1;i++)
    578         {
    579             gotoxy(p[i].x,p[i].y);//转到当前蛇身位置
    580             c(14);//改成黄色
    581             cout<<"";//打印蛇身
    582         }
    583         gotoxy(p[n-2].x,p[n-2].y);//转到当前蛇尾位置
    584         c(12);//改成红色
    585         cout<<"";//打印蛇尾
    586         Sleep(T);//控制蛇的移动速度
    587         t1=time()-t2;//刷新游戏运行时间
    588         gotoxy(p[n-2].x,p[n-2].y);//移到蛇尾所在地
    589         cout<<" ";//清除上个循环的蛇尾
    590         for(i=n-1;i>0;i--) p[i]=p[i-1];//移动蛇
    591         key();//用户是否操作键盘
    592         switch (p[0].direction)
    593         {
    594             case UP:{p[0].y-=1;break;}//改变蛇头坐标,移动蛇头
    595             case DOWN:{p[0].y+=1;break;}//改变蛇头坐标,移动蛇头
    596             case LEFT:{p[0].x-=2;break;}//改变蛇头坐标,移动蛇头
    597             case RIGHT:{p[0].x+=2;break;}//改变蛇头坐标,移动蛇头
    598         }
    599         if(p[0].x==0)//当蛇撞到左墙时
    600         {
    601             cout<<"a";
    602             --HP;//将生命值减一
    603             p[0].x=52;//将其穿墙
    604         }
    605         if(p[0].x==54)//当蛇撞到右墙时
    606         {
    607             cout<<"a";
    608             --HP;//将生命值减一
    609             p[0].x=2;//将其穿墙
    610         }
    611         if(p[0].y==0)//当蛇撞到上墙时
    612         {
    613             cout<<"a";
    614             --HP;//将生命值减一
    615             p[0].y=22;//将其穿墙
    616         }
    617         if(p[0].y==23)//当蛇撞到下墙时
    618         {
    619             cout<<"a";
    620             --HP;//将生命值减一
    621             p[0].y=1;//将其穿墙
    622         }
    623         for(i=1;i<n-1;i++)
    624         {
    625            if(p[0].x==p[i].x&&p[0].y==p[i].y) i=n+1;//判断蛇是否撞到自
    626         }
    627         if(i>=n)//当蛇撞到自己
    628         {
    629             cout<<"a";
    630             HP=0;//将蛇死亡  
    631         }
    632         if(map[(p[0].x-1)/2][p[0].y-1].barrier==1)//当蛇障碍物时
    633         {
    634             cout<<"a";
    635             --HP;//将生命值减一
    636             map[(p[0].x-1)/2][p[0].y-1].barrier=0;
    637         }
    638         if(HP==0)
    639         {
    640             gotoxy(25,5);
    641             c(15);//调成白色
    642             cout<<"aaa游戏结束!!!";
    643             Sleep(3000);//延时
    644             return 1;
    645             break;
    646         }
    647         if(n==81)
    648         {
    649             gotoxy(25,5);
    650             c(15);//调成白色
    651             cout<<"aaa恭喜你过关!!!";
    652             Sleep(3000);//延时
    653             return 1;
    654             break;
    655         }
    656         show();//用来随机产生障碍物以及食物和生命药水以及用来判断游戏的各种参数(小星星是否吃到,是否撞墙)
    657     }
    658     return 0;
    659 }
    显示代码


    下面是c#版的,完全是从c++版的移植过来的,也就改了改界面颜色而已

    下面看图:

    其他就没有什么变化了,下面是代码

      1 using System;
      2 using System.Collections.Generic;
      3 using System.Linq;
      4 using System.Text;
      5 using System.Threading.Tasks;
      6 using System.Windows.Input;
      7 using System.Threading;
      8 using System.Runtime.InteropServices;
      9 
     10 namespace ConsoleApplication3
     11 {
     12 
     13 
     14     class Game
     15     {
     16         public struct Snake
     17         {
     18             public int x;//蛇身所在横坐标
     19             public int y;//蛇身所在纵坐标
     20             public ConsoleKey direction;//行走方向
     21         }
     22 
     23         public struct Map
     24         {
     25             public int food;//此map[x][y]处是否有食物有的话food为1
     26             public int star;//此map[x][y]处是否有星星的话值为1
     27             public int barrier;//此map[x][y]处是否有障碍物有的话值为1
     28         }
     29 
     30         Thread readKeyThread;
     31 
     32         Snake[] p = new Snake[81];
     33         Map[,] map = new Map[26, 22];
     34 
     35         const ConsoleKey UP = ConsoleKey.UpArrow;//
     36         const ConsoleKey DOWN = ConsoleKey.DownArrow;//
     37         const ConsoleKey LEFT = ConsoleKey.LeftArrow;//
     38         const ConsoleKey RIGHT = ConsoleKey.RightArrow;//
     39 
     40         int n = 4;//n用来记录蛇身长度,初始为2节
     41         int guan;//用来记录关卡
     42         int T;//用来给记录蛇的移动速度
     43         int t1 = 0, t2 = 0, t3 = 0;//用来记录以用时间
     44         int HP = 5;//记录蛇的生命值,初始化为6
     45         int food = 0;//用来记录所吃到的食物数
     46         int x = 12, y = 12;//记录食物所在地
     47         bool pause = false;//记录是否暂停;
     48 
     49         public void c(ConsoleColor k)//改变输出字体的颜色
     50         {
     51             Console.ForegroundColor = k;
     52         }
     53 
     54         public int time()//用来计时
     55         {
     56             DateTime dt = System.DateTime.Now;//记录当前程序已用时间
     57             return dt.Second;
     58         }
     59 
     60         public void gotoxy(int x, int y) //移动坐标
     61         {
     62             Console.SetCursorPosition(x, y);
     63         }
     64 
     65         public int random()//用来输出随机值
     66         {
     67 
     68             Random rd = new Random();
     69             return rd.Next();//返回随机数
     70         }
     71 
     72         public void ycgb(bool k)//隐藏光标
     73         {
     74             Console.CursorVisible = k; //隐藏光标
     75         }
     76 
     77         public void Sleep(int s)
     78         {
     79             System.Threading.Thread.Sleep(s);
     80         }
     81 
     82         public void start()//绘制墙/绘制启动画面以及隔墙
     83         {
     84             readKeyThread = new Thread(new ThreadStart(key));
     85             c(ConsoleColor.Yellow);//改成黄色
     86             int i, j, z;
     87             for (i = 0; i < 25; i++)
     88             {
     89                 Console.Write("                                                                                ");
     90             }
     91             for (z = 0; z < 20; z++)
     92             {
     93                 if (z >= 0)
     94                 {
     95                     gotoxy(12, z);
     96                     Console.Write("              ~--______-~                ~-___-~"       ");
     97                 }
     98                 if (z >= 1)
     99                 {
    100                     gotoxy(12, z - 1);
    101                     Console.Write("            ~-_           _-~          ~-_       _-~    ");
    102                 }
    103                 if (z >= 2)
    104                 {
    105                     gotoxy(12, z - 2);
    106                     Console.Write("          \     ~-____-~     _-~    ~-_    ~-_-~    / ");
    107                 }
    108                 if (z >= 3)
    109                 {
    110                     gotoxy(12, z - 3);
    111                     Console.Write("         (     (         _-~    _--_    ~-_    _/   |  ");
    112                 }
    113                 if (z >= 4)
    114                 {
    115                     gotoxy(12, z - 4);
    116                     Console.Write("          /    /            _-~      ~-_        |   |  ");
    117                 }
    118                 if (z >= 5)
    119                 {
    120                     gotoxy(12, z - 5);
    121                     Console.Write("           /    /              _----_           \  \ ");
    122                 }
    123                 if (z >= 6)
    124                 {
    125                     gotoxy(12, z - 6);
    126                     Console.Write("             /    /                            \ \   ");
    127                 }
    128                 if (z >= 7)
    129                 {
    130                     gotoxy(12, z - 7);
    131                     Console.Write("              /    /                          \\     ");
    132                 }
    133                 if (z >= 8)
    134                 {
    135                     gotoxy(12, z - 8);
    136                     Console.Write("                /    /                      \\       ");
    137                 }
    138                 if (z >= 9)
    139                 {
    140                     gotoxy(12, z - 9);
    141                     Console.Write("                 /     /                   \            ");
    142                 }
    143                 if (z >= 10)
    144                 {
    145                     gotoxy(12, z - 10);
    146                     Console.Write("                  |     |                \                ");
    147                 }
    148                 if (z >= 11)
    149                 {
    150                     gotoxy(12, z - 11);
    151                     Console.Write("                 \     \                                 ");
    152                 }
    153                 if (z >= 12)
    154                 {
    155                     gotoxy(12, z - 12);
    156                     Console.Write("        \_______      \                                  ");
    157                 }
    158                 if (z >= 13)
    159                 {
    160                     gotoxy(12, z - 13);
    161                     Console.Write(" \____|__________/  \                                    ");
    162                 }
    163                 if (z >= 14)
    164                 {
    165                     gotoxy(12, z - 14);
    166                     Console.Write("\/     /~     \_/ \                                     ");
    167                 }
    168                 if (z >= 15)
    169                 {
    170                     gotoxy(12, z - 15);
    171                     Console.Write("        _|__|  O|                                          ");
    172                 }
    173                 for (int k = 15; k < z; k++)
    174                 {
    175                     gotoxy(12, k - 15);
    176                     Console.Write("                                                           ");
    177                 }
    178                 Sleep(30);
    179             }
    180             Sleep(2000);
    181             c(ConsoleColor.Gray);//调成白色
    182             gotoxy(0, 0);
    183             for (i = 0; i < 25; i++)
    184             {
    185                 Console.Write("                                                                                ");
    186             }
    187             //c(252);//调整输出颜色 
    188             for (i = 0, j = 60; i < 60; i++, j--)//if是为了异步输出 
    189             {
    190                 if (j > 20)
    191                 {
    192                     gotoxy(2 * (j - 21), 0);
    193                     Console.Write("");//输出第一行
    194                 }
    195                 if (i < 40)
    196                 {
    197                     gotoxy(2 * i, 23);
    198                     Console.Write("");// 输出最下面一行 
    199                 }
    200                 if (j > 22 && j < 45)
    201                 {
    202                     gotoxy(78, j - 22);
    203                     Console.Write("");//输出最右边列
    204                 }
    205                 if (j > 22 && j < 45)
    206                 {
    207                     gotoxy(0, i - 15);
    208                     Console.Write("");//输出第一列
    209                 }
    210                 if (i > 37 && i < 60)
    211                 {
    212                     gotoxy(54, i - 37);
    213                     Sleep(10);
    214                     Console.Write("");//输出中间那列
    215                 }
    216                 Sleep(30);
    217             }
    218             gotoxy(56, 11);
    219             Console.Write("▉▉▉▉▉▉▉▉▉▉▉");                                            //56 
    220             gotoxy(19, 0);
    221             c(ConsoleColor.Red);//调整输出颜色 
    222             Console.Write("| | |贪 吃 蛇| | |");//输出标题 
    223 
    224             gotoxy(56, 2);
    225             Console.Write("已用时间:");
    226             gotoxy(75, 2);
    227             Console.Write("");
    228             gotoxy(56, 4);
    229             Console.Write("生命值:");
    230             gotoxy(56, 6);
    231             Console.Write("当前长度:");
    232             gotoxy(56, 8);
    233             Console.Write("已吃食物:");
    234             gotoxy(56, 10);
    235             Console.Write("第             关");
    236             gotoxy(64, 12);
    237             Console.Write("提示:");
    238             gotoxy(56, 13);
    239             Console.Write("向上:↑   向上:←");
    240             gotoxy(56, 14);
    241             Console.Write("向下:↓   向右:→");
    242             gotoxy(56, 15);
    243             Console.Write("暂停/开始:确定键 ");
    244             gotoxy(56, 16);
    245             Console.Write("重新选关 :Esc键");
    246             gotoxy(64, 18);
    247             Console.Write("注意!");
    248             gotoxy(56, 19);
    249             Console.Write("1:撞到障碍物或者墙生命");
    250             gotoxy(56, 20);
    251             Console.Write("  值减一 ");
    252             gotoxy(56, 21);
    253             Console.Write("2:吃到小星星生命值加一");
    254         }
    255 
    256         public void guanka()//用来选择关卡并根据关卡设置蛇的移动速度
    257         {
    258             ycgb(true);//显示光标
    259             n = 4;//n用来记录蛇身长度,初始为3节
    260             HP = 6;//记录蛇的生命值,初始化为6
    261 
    262             p[0].x = 6;                    //
    263             p[0].y = 10;                   //
    264             p[0].direction = RIGHT;        //
    265             p[1].x = 4;                   //
    266             p[1].y = 10;                  //     初始化蛇所在位置和移动方向   
    267             p[1].direction = RIGHT;       //
    268             p[2].x = 2;                   //
    269             p[2].y = 10;                  //
    270             p[2].direction = RIGHT;      //
    271             p[3].x = 4;////////////////
    272             p[3].y = 4;///////////////记录蛇尾的信息
    273             p[3].direction = RIGHT;////
    274             while (true)
    275             {
    276                 gotoxy(15, 3);
    277                 Console.Write("请输入关数(1-6):");
    278                 guan = Console.Read() - 48;
    279                 //Console.Write("关卡:{0}", guan);
    280                 if (guan == 0)     //判断是否作弊
    281                 {
    282                     gotoxy(15, 3);
    283                     c(ConsoleColor.Red);//变成红色
    284                     Console.Write("  作弊有害智商,需谨慎");
    285                     gotoxy(15, 5);
    286                     c(ConsoleColor.Yellow);//变成黄色
    287                     Console.Write("请输入你想要的蛇的生命值:");
    288                     HP = Console.Read(); ;
    289 
    290                     gotoxy(15, 3);
    291                     Console.Write("                      ");
    292                     gotoxy(15, 5);
    293                     Console.Write("                                    ");
    294                     continue;//返回选关处
    295                 }
    296                 if (guan < 7 && guan > 0) break;//判断关数是否溢出
    297                 gotoxy(15, 5);
    298                 Console.Write("输入错误!");
    299                 gotoxy(32, 3);
    300                 Console.Write("          ");
    301             }
    302             gotoxy(15, 3);
    303             Console.Write("                   ");
    304             switch (guan)
    305             {
    306                 case 1: { T = 600; break; }//
    307                 case 2: { T = 400; break; }//
    308                 case 3: { T = 200; break; }//    根据关数来设定蛇的移动速度
    309                 case 4: { T = 150; break; }//
    310                 case 5: { T = 100; break; }//
    311                 case 6: { T = 60; break; }//
    312             }
    313             qp();//清除屏幕
    314         }
    315 
    316         void data()//用来记录和判断游戏的各种状态数据
    317         {
    318             c(ConsoleColor.Red);//调成红色
    319             gotoxy(66, 2);
    320             Console.Write("{0}", t1);//程序已用时间
    321             switch (guan)
    322             {
    323                 case 1:
    324                     gotoxy(59, 10);
    325                     c(ConsoleColor.Red);//调成红色
    326                     Console.Write("1");
    327                     c(ConsoleColor.Yellow);//调成黄色
    328                     Console.Write(" 2 3 4 5 6");
    329                     break;
    330                 case 2:
    331                     gotoxy(59, 10);
    332                     c(ConsoleColor.Yellow);//调成黄色
    333                     Console.Write("1 ");
    334                     c(ConsoleColor.Red);//调成红色
    335                     Console.Write("2");
    336                     c(ConsoleColor.Yellow);//调成黄色
    337                     Console.Write(" 3 4 5 6 ");
    338                     break;
    339                 case 3:
    340                     gotoxy(59, 10);
    341                     c(ConsoleColor.Yellow);//调成黄色
    342                     Console.Write("1 2 ");
    343                     c(ConsoleColor.Red);//调成红色
    344                     Console.Write("3");
    345                     c(ConsoleColor.Yellow);//调成黄色
    346                     Console.Write(" 4 5 6 ");
    347                     break;
    348                 case 4:
    349                     gotoxy(59, 10);
    350                     c(ConsoleColor.Yellow);//调成黄色
    351                     Console.Write("1 2 3 ");
    352                     c(ConsoleColor.Red);//调成红色
    353                     Console.Write("4");
    354                     c(ConsoleColor.Yellow);//调成黄色
    355                     Console.Write(" 5 6 ");
    356                     break;
    357                 case 5:
    358                     gotoxy(59, 10);
    359                     c(ConsoleColor.Yellow);//调成黄色
    360                     Console.Write("1 2 3 4 ");
    361                     c(ConsoleColor.Red);//调成红色
    362                     Console.Write("5");
    363                     c(ConsoleColor.Yellow);//调成黄色
    364                     Console.Write(" 6 ");
    365                     break;
    366                 case 6:
    367                     gotoxy(59, 10);
    368                     c(ConsoleColor.Yellow);//调成黄色
    369                     Console.Write("1 2 3 4 5 ");
    370                     c(ConsoleColor.Red);//调成红色
    371                     Console.Write("6");
    372                     break;
    373             }
    374             switch (HP)
    375             {
    376                 case 1:
    377                     gotoxy(65, 4);
    378                     c(ConsoleColor.Green);//调成绿色
    379                     Console.Write("");
    380                     c(ConsoleColor.Red);//调成红色
    381                     Console.Write("▂▃▅▆▇");
    382                     break;
    383                 case 2:
    384                     gotoxy(65, 4);
    385                     c(ConsoleColor.Green);//调成绿色
    386                     Console.Write("▁▂");
    387                     c(ConsoleColor.Red);//调成红色
    388                     Console.Write("▃▅▆▇");
    389                     break;
    390                 case 3:
    391                     gotoxy(65, 4);
    392                     c(ConsoleColor.Green);//调成绿色
    393                     Console.Write("▁▂▃");
    394                     c(ConsoleColor.Red);//调成红色
    395                     Console.Write("▅▆▇");
    396                     break;
    397                 case 4:
    398                     gotoxy(65, 4);
    399                     c(ConsoleColor.Green);//调成绿色
    400                     Console.Write("▁▂▃▅");
    401                     c(ConsoleColor.Red);//调成红色
    402                     Console.Write("▆▇");
    403                     break;
    404                 case 5:
    405                     gotoxy(65, 4);
    406                     c(ConsoleColor.Green);//调成绿色
    407                     Console.Write("▁▂▃▅▆");
    408                     c(ConsoleColor.Red);//调成红色
    409                     Console.Write("");
    410                     break;
    411                 case 6:
    412                     gotoxy(65, 4);
    413                     c(ConsoleColor.Green);//调成绿色
    414                     Console.Write("▁▂▃▅▆▇");
    415                     break;
    416                 default:
    417                     gotoxy(65, 4);
    418                     c(ConsoleColor.Red);//调成红色
    419                     Console.Write("!超级模式 !");
    420                     break;
    421             }
    422             gotoxy(66, 6);
    423             c(ConsoleColor.Red);//调成红色
    424             Console.Write("{0}", n - 1);//输出蛇的当前长度
    425             gotoxy(66, 8);
    426             Console.Write("{0}", food);//输出蛇当前已经吃到食物
    427         }
    428         void qp()//用来清除屏幕
    429         {
    430             for (int i = 1; i < 23; i++)
    431             {
    432                 gotoxy(2, i);
    433                 Console.Write("                                                    ");
    434             }
    435             map[x, y].food = 0;//将食物清空
    436             map[x, y].barrier = 0;//将障碍物清除
    437             map[x, y].star = 0;//将星星清除 
    438         }
    439 
    440         void show()//用来随机产生障碍物以及食物和生命药水以及用来判断游戏的各种参数
    441         {
    442             int a, b, e, f; //a,b用来表示小星星的坐标   c,d代表障碍物坐标
    443             if (map[x, y].food == 0)//判断食物是不是被吃掉
    444             {
    445                 while (true)
    446                 {
    447                     x = random() % 26;//产生随机横坐标
    448                     y = random() % 22;//产生随机纵坐标
    449                     if (map[x, y].barrier == 0 && map[x, y].star == 0) break;//当此处无其他元素是才生效 
    450                 }
    451                 map[x, y].food = 1;//随机出现食物
    452                 gotoxy(2 * (x + 1), y + 1);//定位到食物出现的位置
    453                 c(ConsoleColor.Yellow);//调成黄色
    454                 Console.Write("");//打印出食物
    455             }
    456             if (t1 / 20 > 0 && t1 % 12 == 0 && t1 > t3 && map[(p[0].x - 1) / 2, p[0].y - 1].food == 0 && map[(p[0].x - 1) / 2, p[0].y - 1].star == 0)
    457             {
    458                 while (true)
    459                 {
    460                     e = random() % 26;//产生随机横坐标
    461                     f = random() % 22;//产生随机纵坐标
    462                     if (map[e, f].food == 0 && map[e, f].star == 0) break;//当此处无其他元素是才生效 
    463                 }
    464                 gotoxy(2 * (e + 1), f + 1);//定位到障碍物出现的位置
    465                 map[e, f].barrier = 1;//随机出现障碍物
    466                 c(ConsoleColor.Yellow);//调成黄色
    467                 Console.Write("");//打印出障碍物
    468                 t3 = t1;//以免产生多个障碍物
    469                 if (HP < 7)
    470                 {
    471                     gotoxy(18, 24);
    472                     c(ConsoleColor.White);//调成白色
    473                     Console.Write("温馨提示:在选关的时候输入0可以开启作弊模式");
    474                 }
    475             }
    476             if (t1 / 25 > 0 && t1 % 15 == 0 && t1 > t3 && map[(p[0].x - 1) / 2, p[0].y - 1].food == 0 && map[(p[0].x - 1) / 2, p[0].y - 1].barrier == 0)//减少星星出现的几率 
    477             {
    478                 while (true)
    479                 {
    480                     a = random() % 26;//产生随机横坐标
    481                     b = random() % 22;//产生随机纵坐标
    482                     if (map[a, b].barrier == 0 && map[a, b].food == 0) break;//当此处无其他元素是才生效 
    483                 }
    484                 map[a, b].star = 1;//随机出现小星星(吃到星星长度减1)
    485                 gotoxy(2 * (a + 1), b + 1);//定位到星星出现的位置(吃到星星长度减1)
    486                 c(ConsoleColor.Red);//调成红色
    487                 Console.Write("");//打印出星星(吃到星星长度减1)
    488                 t3 = t1;//以免产生多个障碍物
    489                 if (HP < 7)
    490                 {
    491                     gotoxy(18, 24);
    492                     Console.Write("                                            ");
    493                 }
    494             }
    495             for (int i = 0; i < n; i++)
    496             {
    497                 if (map[(p[i].x - 1) / 2, p[i].y - 1].food == 1)//判断蛇是否吃到食物
    498                 {
    499                     ++n;//让蛇长度加1
    500                     food++;//将食物数加1
    501                     map[(p[i].x - 1) / 2, p[i].y - 1].food = 0;//让食物标示归零
    502                     break;
    503                 }
    504             }
    505             if (map[(p[0].x - 1) / 2, p[0].y - 1].star == 1)//判断蛇是否吃到星星
    506             {
    507                 map[(p[0].x - 1) / 2, p[0].y - 1].star = 0;//让星星标示归零
    508                 if (HP < 6)
    509                     ++HP;//将生命值加1
    510             }
    511             t1 = time() - t2;//刷新游戏运行时间
    512         }
    513 
    514         void key()//用户是否操作键盘
    515         {
    516             while (true)//判断是否按键
    517             {
    518                 ConsoleKey ch = Console.ReadKey().Key;
    519                 if (ch == ConsoleKey.Enter)//判断用户是否暂停
    520                 {
    521                     pause = true;
    522                     int a, b;
    523                     a = time();//记录当前程序已用时间
    524                     gotoxy(20, 1);
    525                     c(ConsoleColor.White);//调成白色
    526                     Console.Write("已暂停,按确定键开始");
    527                     while (true)
    528                     {
    529                         gotoxy(0, 24);//将光标设置到最后一行,防止用户乱输入数据
    530                         ConsoleKey temp = Console.ReadKey().Key;
    531                         if (temp == ConsoleKey.Enter)////判断是否按键且是否解除暂停
    532                         {
    533                             pause = false;
    534                             gotoxy(20, 1);
    535                             Console.Write("                     ");//清除"已暂停,按确定键开始"这行字                     
    536                             break;
    537                         }
    538                         else
    539                         {
    540                             gotoxy(Console.CursorLeft - 1, Console.CursorTop);//将位置移到用户输入的非正常数据
    541                             Console.Write(" ");//清除这个数据
    542                         }
    543                     }
    544                     b = time();//记录当前程序已用时间
    545                     t2 += (b - a);//将暂停加到t2上供t1减去
    546                 }
    547                 else if (ch == ConsoleKey.Escape)//判断是否重新选关
    548                 {
    549                     guanka();//用来选择关卡并根据关卡设置蛇的移动速度
    550                     game();//开始游戏        
    551                 }
    552                 else if ((ch == RIGHT || ch == LEFT || ch == DOWN || ch == UP) && ch != p[0].direction && (int)ch - 2 != (int)p[0].direction && (int)ch + 2 != (int)p[0].direction)  //判断按键是否是方向键,并且是不是蛇移动方向的反方向
    553                     p[0].direction = ch;//如果不是就改变蛇头方向
    554             }
    555         }
    556 
    557         public bool game()
    558         {
    559             readKeyThread.Start();//启动按键获取
    560 
    561             int i;
    562             //ConsoleKey ch = RIGHT;//向右
    563             t2 = time();//记录当前程序已用时间
    564             while (true)
    565             {
    566                 if (pause) continue;//如果暂停了
    567 
    568                 t1 = time() - t2;//刷新游戏运行时间
    569                 data();//用来记录游戏的各种状态数据
    570                 gotoxy(p[0].x, p[0].y);//转到蛇头位置
    571                 c(ConsoleColor.Yellow);//改成黄色
    572                 Console.Write("");//打印蛇头
    573                 for (i = 1; i < n - 1; i++)
    574                 {
    575                     gotoxy(p[i].x, p[i].y);//转到当前蛇身位置
    576                     c(ConsoleColor.Red);//改成红色
    577                     Console.Write("");//打印蛇身
    578                 }
    579                 gotoxy(p[n - 2].x, p[n - 2].y);//转到当前蛇尾位置
    580                 c(ConsoleColor.Yellow);//改成红色
    581                 Console.Write("");//打印蛇尾
    582                 Sleep(T);//控制蛇的移动速度
    583                 t1 = time() - t2;//刷新游戏运行时间
    584                 gotoxy(p[n - 2].x, p[n - 2].y);//移到蛇尾所在地
    585                 Console.Write(" ");//清除上个循环的蛇尾
    586                 for (i = n - 1; i > 0; i--) p[i] = p[i - 1];//移动蛇
    587                 switch (p[0].direction)
    588                 {
    589                     case UP: { p[0].y -= 1; break; }//改变蛇头坐标,移动蛇头
    590                     case DOWN: { p[0].y += 1; break; }//改变蛇头坐标,移动蛇头
    591                     case LEFT: { p[0].x -= 2; break; }//改变蛇头坐标,移动蛇头
    592                     case RIGHT: { p[0].x += 2; break; }//改变蛇头坐标,移动蛇头
    593                 }
    594                 if (p[0].x == 0)//当蛇撞到左墙时
    595                 {
    596                     Console.Write("a");
    597                     --HP;//将生命值减一
    598                     p[0].x = 52;//将其穿墙
    599                 }
    600                 if (p[0].x == 54)//当蛇撞到右墙时
    601                 {
    602                     Console.Write("a");
    603                     --HP;//将生命值减一
    604                     p[0].x = 2;//将其穿墙
    605                 }
    606                 if (p[0].y == 0)//当蛇撞到上墙时
    607                 {
    608                     Console.Write("a");
    609                     --HP;//将生命值减一
    610                     p[0].y = 22;//将其穿墙
    611                 }
    612                 if (p[0].y == 23)//当蛇撞到下墙时
    613                 {
    614                     Console.Write("a");
    615                     --HP;//将生命值减一
    616                     p[0].y = 1;//将其穿墙
    617                 }
    618                 for (i = 1; i < n - 1; i++)
    619                 {
    620                     if (p[0].x == p[i].x && p[0].y == p[i].y) i = n + 1;//判断蛇是否撞到自
    621                 }
    622                 if (i >= n)//当蛇撞到自己
    623                 {
    624                     Console.Write("a");
    625                     HP = 0;//将蛇死亡  
    626                 }
    627                 if (map[(p[0].x - 1) / 2, p[0].y - 1].barrier == 1)//当蛇障碍物时
    628                 {
    629                     Console.Write("a");
    630                     --HP;//将生命值减一
    631                     map[(p[0].x - 1) / 2, p[0].y - 1].barrier = 0;
    632                 }
    633                 if (HP == 0)
    634                 {
    635                     readKeyThread.Abort();//停止按键检测
    636                     gotoxy(25, 5);
    637                     c(ConsoleColor.White);//调成白色
    638                     Console.Write("aaa游戏结束!!!");
    639                     Sleep(3000);//延时
    640                     return true;
    641                 }
    642                 if (n == 81)
    643                 {
    644                     readKeyThread.Abort();//停止按键检测
    645                     gotoxy(25, 5);
    646                     c(ConsoleColor.White);//调成白色
    647                     Console.Write("aaa恭喜你过关!!!");
    648                     Sleep(3000);//延时
    649                     return true;
    650                 }
    651                 show();//用来随机产生障碍物以及食物和生命药水以及用来判断游戏的各种参数(小星星是否吃到,是否撞墙)
    652             }
    653         }
    654 
    655     }
    656 
    657     class Program
    658     {
    659         static void Main(string[] args)
    660         {
    661             Game game = new Game();
    662             game.ycgb(false);//隐藏光标
    663             game.start();//绘制启动画面以及隔墙
    664             while (true)
    665             {
    666                 game.guanka();//用来选择关卡并根据关卡设置蛇的移动速度
    667                 game.ycgb(false);//隐藏光标
    668                 if (!game.game()) break;//游戏运行
    669             }
    670         }
    671     }
    672 }
    显示代码
  • 相关阅读:
    如何在SharePointDesigner订制页面里判断用户权限
    为SharePoint 2010中的FBA创建自定义登录页面
    javascript中的this到底指什么?
    用JAVASCRIPT实现静态对象、静态方法和静态属性
    简单的HoverMenu效果
    JavaScript 调用sharepoint内置webservice 更新item
    域中搜索用户email
    服务控制管理器错误
    SQL Server 2008/2005不能修改表结构的解决方法
    类集对枚举的支持
  • 原文地址:https://www.cnblogs.com/AfterTheRainOfStars/p/3702581.html
Copyright © 2011-2022 走看看