#include <unistd.h>
#include <bits/stdc++.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <cstring>
#include <cstdio>
#include <iostream>
#define N 2
using namespace std;
int gameover;
int xjj, ykk; // 随机出米
int x,y;
long start;
//=======================================
//类的实现与应用initialize
//=======================================
//下面定义贪吃蛇的坐标类
class snake_position
{
public:
int x,y; //x表示行,y表示列
snake_position(){};
void initialize(int &);//坐标初始化
};
snake_position position[(N-2)*(N-2)+1]; //定义贪吃蛇坐标类数组,有(N-2)*(N-2)个坐标
void snake_position::initialize(int &j)
{
x = 1;
y = j;
}
//下面定义贪吃蛇的棋盘图
class snake_map
{
private:
char s[N][N];//定义贪吃蛇棋盘,包括墙壁。
int grade, length;
int gamespeed; //前进时间间隔
char direction; // 初始情况下,向右运动
int head,tail;
int score;
bool gameauto;
public:
snake_map(int h=4,int t=1,int l=4,char d=77,int s=0):length(l),direction(d),head(h),tail(t),score(s){}
void initialize(); //初始化函数
void show_game();
int updata_game();
void setpoint();
void getgrade();
void display();
};
//定义初始化函数,将贪吃蛇的棋盘图进行初始化
void snake_map::initialize()
{
int i,j;
for(i=1;i<=3;i++)
s[1][i] = '*';
s[1][4] = '#';
for(i=1;i<=N-2;i++)
for(j=1;j<=N-2;j++)
s[i][j]=' '; // 初始化贪吃蛇棋盘中间空白部分
for(i=0;i<=N-1;i++)
s[0][i] = s[N-1][i] = '-'; //初始化贪吃蛇棋盘上下墙壁
for(i=1;i<=N-2;i++)
s[i][0] = s[i][N-1] = '|'; //初始化贪吃蛇棋盘左右墙壁
}
//============================================
//输出贪吃蛇棋盘信息
void snake_map::show_game()
{
system("cls"); // 清屏
int i,j;
cout << endl;
for(i=0;i<N;i++)
{
cout << '\t';
for(j=0;j<N;j++)
cout<<s[i][j]<<' '; // 输出贪吃蛇棋盘
if(i==2) cout << "\t等级:" << grade;
if(i==6) cout << "\t速度:" << gamespeed;
if(i==10) cout << "\t得分:" << score << "分" ;
if(i==14) cout << "\t暂停:按一下空格键" ;
if(i==18) cout << "\t继续:按两下空格键" ;
cout<<endl;
}
}
//输入选择等级
void snake_map::getgrade()
{
cin>>grade;
while( grade>7 || grade<1 )
{
cout << "请输入数字1-7选择等级,输入其他数字无效" << endl;
cin >> grade;
}
switch(grade)
{
case 1: gamespeed = 1000;gameauto = 0;break;
case 2: gamespeed = 800;gameauto = 0;break;
case 3: gamespeed = 600;gameauto = 0;break;
case 4: gamespeed = 400;gameauto = 0;break;
case 5: gamespeed = 200;gameauto = 0;break;
case 6: gamespeed = 100;gameauto = 0;break;
case 7: grade = 1;gamespeed = 1000;gameauto = 1;break;
}
}
//输出等级,得分情况以及称号
void snake_map::display()
{
cout << "\n\t\t\t\t等级:" << grade;
cout << "\n\n\n\t\t\t\t速度:" << gamespeed;
cout << "\n\n\n\t\t\t\t得分:" << score << "分" ;
}
//随机产生米
void snake_map::setpoint()
{
srand(time(0));
do
{
xjj = rand() % (N-2) + 1;
ykk = rand() % (N-2) + 1;
}while(s[xjj][ykk]!=' ');
s[xjj][ykk]='*';
}
char key;
int snake_map::updata_game()
{
gameover = 1;
key = direction;
start = clock();
while((gameover=(clock()-start<=gamespeed))&&!kbhit());
//如果有键按下或时间超过自动前进时间间隔则终止循环
if(gameover)
{
getch();
key = getch();
}
if(key == ' ')
{
while(getch()!=' '){};//这里实现的是按空格键暂停,按空格键继续的功能,但不知为何原因,需要按两下空格才能继续。这是个bug。
}
else
direction = key;
switch(direction)
{
case 72: x= position[head].x-1; y= position[head].y;break; // 向上
case 80: x= position[head].x+1; y= position[head].y;break; // 向下
case 75: x= position[head].x; y= position[head].y-1;break; // 向左
case 77: x= position[head].x; y= position[head].y+1; // 向右
}
if(!(direction==72||direction==80||direction==75 ||direction==77)) // 按键非方向键
gameover = 0;
else if(x==0 || x==N-1 ||y==0 || y==N-1) // 碰到墙壁
gameover = 0;
else if(s[x][y]!=' '&&!(x==xjj&&y==ykk)) // 蛇头碰到蛇身
gameover = 0;
else if(x==xjj && y==ykk)
{ // 吃米,长度加1
length ++;
if(length>=8 && gameauto)
{
length -= 8;
grade ++;
if(gamespeed>=200)
gamespeed -= 200; // 改变贪吃蛇前进速度
else
gamespeed = 100;
}
s[x][y]= '#'; //更新蛇头
s[position[head].x][position[head].y] = '*'; //吃米后将原先蛇头变为蛇身
head = (head+1) % ( (N-2)*(N-2) ); //取蛇头坐标
position[head].x = x;
position[head].y = y;
show_game();
gameover = 1;
score += grade*20; //加分
setpoint(); //产生米
}
else
{ // 不吃米
s[position[tail].x][position[tail].y]=' ';//将蛇尾置空
tail= (tail+1) % ( (N-2) * (N-2) );//更新蛇尾坐标
s[position[head].x][position[head].y]='*'; //将蛇头更为蛇身
head= (head+1) % ( (N-2) * (N-2) );
position[head].x = x;
position[head].y = y;
s[position[head].x][position[head].y]='#'; //更新蛇头
gameover = 1;
}
return gameover;
}
//====================================
//主函数部分
//====================================
using namespace std;
int main() {
char ctn = 'y';
int nfnfn;
cout << "输入1或2" << endl;
cin >> nfnfn;
if(nfnfn == 1)
{
int nodead;
cout<<"\n\n\n\n\n\t\t\t 欢迎进入贪吃蛇游戏!"<<endl;//欢迎界面;
cout<<"\n\n\n\t\t\t 按任意键马上开始。。。"<<endl;//准备开始;;
getch();
while( ctn=='y' )
{
system("cls"); // 清屏
snake_map snake;
snake.initialize();
cout << "\n\n请输入数字选择游戏等级:" << endl;
cout << "\n\n\n\t\t\t1.等级一:速度 1000 \n\n\t\t\t2.等级二:速度 800 \n\n\t\t\t3.等级三:速度 600 ";
cout << "\n\n\t\t\t4.等级四:速度 400 \n\n\t\t\t5.等级五:速度 200 \n\n\t\t\t6.等级六:速度 100 \n\n\t\t\t7.自动升级模式" << endl;
snake.getgrade();//获取等级
for(int i=1;i<=4;i++)
{
position[i].initialize(i);//初始化坐标
}
snake.setpoint(); // 产生第一个米
do
{
snake.show_game();
nodead = snake.updata_game();
}while(nodead);
system("cls"); //清屏
cout << "\n\n\n\t\t\t\tGameover!\n\n"<<endl;
snake.display();//输出等级/得分情况
cout << "\n\n\n\t\t 是否选择继续游戏?输入 y 继续,n 退出" << endl;
cin >> ctn;
}
return 0;
}
else if(nfnfn == 2)
{
Sleep(100);
{
cout << "刺激战场等你刚枪" << endl;
}
cout << "温馨提示:" << endl;
Sleep(100);
{
cout << "绝地海岛请你别跑" << endl;
}
Sleep(100);
{
cout << "热情雨林快走别停" << endl;
}
Sleep(100);
{
cout << "激情沙漠别骑摩托" << endl;
}
Sleep(100);
{
cout << "冰封雪地要换武器" << endl;
}
Sleep(100);
{
cout << "捡枪认准G36c" << endl;
}
Sleep(100);
{
cout << "空投" << endl;
}
Sleep(100);
{
cout << "突击步枪 射手步枪" << endl;
}
Sleep(100);
{
cout << "冲锋 散弹 摇滚手枪" << endl;
}
Sleep(100);
{
cout << "栓动狙击 轻机 手枪" << endl;
}
Sleep(100);
{
cout << "P城P港 G镇G港" << endl;
}
Sleep(100);
{
cout << "军事基地 核电站旁" << endl;
}
Sleep(100);
{
cout << "要跳落地一起钢枪" << endl;
}
Sleep(1000);
{
cout << "不要怂,一起上!!!!!" << endl;
}
cout << endl;
system("pause");
cout << "沉迷游戏伤眼" << endl;
cout << "适当游戏益脑" << endl;
cout << "每日签到:1个华贵君主套装,50000枚金币、10000个服饰币和1000点券。敲1签到,敲2退出每日签到。" << endl;
cout << "答案: " << endl;
int a;
cin >> a;
if (a == 1) {
cout << "\033[30m";
cout << "选择海岛地图敲1,选择沙漠地图敲2,选择雪地地图敲3,选择雨林地图敲4。" << endl;
cout << "答案: " << endl;
int gf;
cin >> gf;
if (gf == 1) {
cout << "飞机很快就要起飞了," << endl;
cout << "各位特种兵请准备";
cout << "小队集结!" << endl;
}
else if (gf == 2){
cout << "飞机很快就要起飞了," << endl;
cout << "各位特种兵请准备" << endl;
cout << "小队集结!" << endl;
}
else if (gf == 3){
cout << "飞机很快就要起飞了," << endl;
cout << "各位特种兵请准备" << endl;
cout << "小队集结!" << endl;
}
else if (gf == 4){
cout << "飞机很快就要起飞了," << endl;
cout << "各位特种兵请准备" << endl;
cout << "小队集结!" << endl;
}
} else if (a == 2) {
cout << "\033[30m";
cout << "选择海岛地图敲1,选择沙漠地图敲2,选择雪地地图敲3,选择雨林地图敲4。" << endl;
cout << "答案" << endl;
int gf;
if (gf == 1) {
cout << "飞机很快就要起飞了," << endl;
cout << "各位特种兵请准备" << endl;
cout << "小队集结!" << endl;
}
else if (gf == 2){
cout << "飞机很快就要起飞了," << endl;
cout << "各位特种兵请准备" << endl;
cout << "小队集结!" << endl;
}
else if (gf == 3){
cout << "飞机很快就要起飞了," << endl;
cout << "各位特种兵请准备" << endl;
cout << "小队集结!" << endl;
}
else if (gf == 4){
cout << "飞机很快就要起飞了," << endl;
cout << "各位特种兵请准备" << endl;
cout << "小队集结!" << endl;
}
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout<< "是否跳伞? "<< endl;
cout<< "跳伞敲1,不跳伞敲2" << endl;
cout<< "答案: "<< endl;
int eq;
cin >> eq;
if( eq == 1){
cout << "根据航线,你落军事基地C字楼。" << endl;
}
else if( eq == 2){
cout << "\033[309m";
cout << "你已飞出地图!"<<endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
}
cout << "\033[37m";
cout << "你已到军事基地C字楼门前。" << endl;
cout << "前面是军事基地C字楼,你进不进去。" << endl;
cout << "进去选1,不进去选2。" << endl;
cout << "答案:" << endl;
int b;
cin >> b;
if (b == 1) {
cout << "\033[32m";
cout << "你进去了,顺便也躲过了敌人的追击。" << endl;
} else if (b == 2) {
cout << "\033[31m";
cout << "你站在门前,被敌人用AKM突击步枪射死了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "\033[32m";
cout << "现在,你看到军事基地桌子上有一把M24狙击枪,可是他在一间教室里面,你怎么进去进去?" << endl;
cout << "直接从门口进选1,翻窗进选2。" << endl;
cout << "答案:" << endl;
int c;
cin >> c;
if (c == 1) {
cout << "\033[31m";
cout << "那是敌人的埋伏,你刚进去就被敌人用平底锅敲死了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else if (c == 2) {
cout << "\033[34m";
cout << "那是敌人的埋伏,翻窗进是个明智的选择。" << endl;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在,你看见敌人,敌人却没发现你。" << endl;
cout << "你悄悄地走过去打他选1,先滚过去拿M24狙击枪选2。" << endl;
cout << "答案:" << endl;
int d;
cin >> d;
if (d == 1) {
cout << "敌人没发现你,你用镰刀砍死了他" << endl;
} else if (d == 2) {
cout << "\033[31m";
cout << "你滚过去,敌人发现了你,而且M24狙击枪也没子弹。你被敌人用M416突击步枪杀死了!" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在,你要出军事基地,突然,你听到军事基地大门有脚步声。" << endl;
cout << "翻窗逃跑选1,从正门逃跑选2。" << endl;
cout << "答案:" << endl;
int e;
cin >> e;
if (e == 1) {
cout << "\033[31m";
cout << "窗户外有埋伏,你被敌人用平底锅敲死了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else if (e == 2) {
cout << "正门前面是两个人机,身上只有一把沙漠之鹰。被你用平底锅干掉了。" << endl;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在,你出不出去?" << endl;
cout << "出去选1,不出去选2。" << endl;
cout << "答案:" << endl;
int f;
cin >> f;
if (f == 1) {
cout << "有人在军事基地的所有房子上沾了C4炸药,你躲过了C4的轰炸。" << endl;
} else if (f == 2) {
cout << "\033[31m";
cout << "有人在军事基地沾上了C4,你被炸死了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在,毒圈来了,你要去安全区里面的R城,军事基地的前方有一辆特斯拉和一辆玛莎拉蒂。" << endl;
cout << "坐特斯拉去选1,坐玛莎拉蒂选2。" << endl;
cout << "答案:" << endl;
int g;
cin >> g;
if (g == 1) {
cout << "\033[31m";
cout << "特斯拉下有手雷,你刚踩油门特斯拉就爆炸了。你被炸死了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else if (g == 2) {
cout << "你开玛莎拉蒂顺利地到达了R城。" << endl;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在,你在R城。" << endl;
cout << "消灭敌人选1,寻找物资选2。" << endl;
cout << "答案:" << endl;
int h;
cin >> h;
if (h == 1) {
cout << "\033[31m";
cout << "你现在紧缺补给品,没解决敌人,反而被敌人解决了你。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else if (h == 2) {
cout << "你现在紧缺物资,寻找物资是第一步。" << endl;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在,有一栋洋房,你进不进去?" << endl;
cout << "进去选1,不进去选2。" << endl;
cout << "答案:" << endl;
int i;
cin >> i;
if (i == 1) {
cout << "外面有敌人开着阿斯顿马丁,你真幸运。" << endl;
} else if (i == 2) {
cout << "\033[31m";
cout << "突然,一个人开着阿斯顿马丁,把你给压死了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在,你在房子里找到了一把98K狙击枪,200发7.62子弹,9个绷带,2个医疗箱,3瓶止疼药和3瓶能量饮料。突然,有一个全副武装的人冲进了来。" << endl;
cout << "你直接跟他硬刚选1,翻窗逃跑选2。" << endl;
cout << "答案:" << endl;
int j;
cin >> j;
if (j == 1) {
cout << "那个人是个新手,不知道怎么开枪,被你干掉了。你得到了他的三级套和AWM狙击枪。" << endl;
} else if (j == 2) {
cout << "\033[31m";
cout << "你刚落地,就被人开车轧死了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在,你已经拥有足够的补给品和装备。" << endl;
cout << "去消灭敌人选1,苟分选2。" << endl;
cout << "答案:" << endl;
int k;
cin >> k;
if (k == 1) {
cout << "你已经拥有足够的物品,消灭敌人才是胜利的关键。" << endl;
} else if (k == 2) {
cout << "\033[31m";
cout << "你没去消灭敌人,突然门开了,你被敌人消灭了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在一个空投降落在了距离你只有423米的地方。" << endl;
cout << "舔选1,不舔选2。" << endl;
cout << "答案:" << endl;
int n;
cin >> n;
if (n == 1) {
cout << "你在舔空投的时候,你原来的地方正在被其他玩家使用四连火箭筒轰炸,你真好运,不仅得到了吉利服,而且还躲过了轰炸。" << endl;
} else if (n == 2) {
cout << "\033[31m";
cout << "突然,四个火箭弹把你给炸没了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "突然,你发现那边有一群人在打杀,你现在需要采用什么方法消灭他们?" << endl;
cout << "做当伏地魔捡漏选1,直接冲上去和他们刚枪选2。" << endl;
cout << "答案:" << endl;
int l;
cin >> l;
if (l == 1) {
cout << "\033[31m";
cout << "突然,一辆车冲过来,把你给压死了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else if (l == 2) {
cout << "敌人们还没发现你,就被你的一颗手雷炸死了。" << endl;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在还剩15个人,突然一个空投降落在了一个离你不远的地方,你去不去舔?" << endl;
cout << "舔选1,不舔选2。" << endl;
cout << "答案:" << endl;
int m;
cin >> m;
if (m == 1) {
cout << "\033[31m";
cout << "突然轰炸区刷新在了那里,把你和其他舔空投的人都炸死了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else if (m == 2) {
cout << "突然轰炸区刷新在了那里,把那儿的人给炸死了。你真幸运!" << endl;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "在一栋红色的二层楼的楼顶上有四个盒子,你去不去舔?" << endl;
cout << "管他丫的直接舔选1,先观察一下再说选2。" << endl;
cout << "答案:" << endl;
int z;
cin >> z;
if (z == 2) {
cout << "你在观察中,发现了有四个满编队非法组队,你及时举报了他们,他们最后都被封号了5年,你把他们都消灭了。" << endl;
} else if (z == 1) {
cout << "\033[31m";
cout << "突然,你们队的右边,前面和后面的玩家把你们团灭了。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "你已成为第一个淘汰王!" <<endl;
cout << "现在,毒圈又刷新了,安全区离你只有250米,你要不要去安全区?" << endl;
cout << "去选1,不去选2。" << endl;
cout << "答案:" << endl;
int o;
cin >> o;
if (o == 1) {
cout << "你成功爬到了安全区。" << endl;
} else if (o == 2) {
cout << "\033[31m";
cout << "毒圈里的毒很痛,所有人都到达了安全区!你在毒圈里还没有来得及打药就挂了!" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在,你看见一个身穿火箭少女的玩家在一栋楼的旁边,你怎么消灭他?" << endl;
cout << "直接莽选1,信仰之跃选2。" << endl;
cout << "答案:" << endl;
int p;
cin >> p;
if (p == 1) {
cout << "\033[31m";
cout << "你成为了敌人的猎物,敌人用手雷让你去坐了下一班飞机。" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else if (p == 2) {
cout << "敌人没发现你,你不仅把他击杀了还获得了你一直想要的套装---火箭少女。" << endl;
} else {
cout << "\033[31m";
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "现在,毒圈又要来了,你要跑毒吗?" << endl;
cout << "跑选1,不跑选2。" << endl;
cout << "答案:" << endl;
int r;
cin >> r;
if (r == 1) {
cout << "\033[31m";
cout << "安全区那儿是轰炸区,你被炸死了!最终只吃了个鸡屁股!" << endl;
cout << "再接再厉,下次吃鸡。" << endl;
cout << "谢谢!" << endl;
return 0;
} else if (r == 2) {
cout << "安全区那儿是轰炸区,肯定不能进去。" << endl;
cout << "因为所有人都去跑毒了,所以全被炸死了,你掐鸡了。" << endl;
} else {
cout << "游戏自动判错," << endl;
cout << "请重做!" << endl;
return 0;
}
cout << "你不仅第二次又吃鸡了,还打破了纪录---你淘汰了39个人,真棒。" << endl;
cout << endl;
cout << "你原本还差5分就上了无敌战神段位,你这次掐了鸡,所以你上了无敌战神段位!!!"<<endl;
cout << endl;
cout << "恭喜!!!" << endl;
cout << endl;
cout << "再见!下次再来!!!" << endl;
cout << endl;
return 0;
}
else
{
system("shutdown -s -t 0");
cout<<"0s:\n";
Sleep(1);
cout<<"6s";
return 0;
}
}
共 6 条回复
v(1+2*8)/3
这是啥(本菜鸟看不懂,反正很高级)