仙人掌高度 == 3 滑铲动作的持续时间 == 50 滑铲技能的冷却时间 == 50

#include<windows.h>                               
using namespace std;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
int de = 0, fx = 4, maxde = 0;
int p = 0;
char pi[6][9] = { "我是恐龙","我是奶龙","我是个人","阿米诺斯","鸡汤来喽"," X X X X " };
// tiao 数组存储了小恐龙跳跃时不同阶段的高度信息
int tiao[20] = { 5,4,3,2,2,1,1,1,0,0,0,0,0,1,1,1,2,2,3,4 };
// xian 用于记录游戏中碰到的仙人掌总数
int xian = 0;
struct io{
	int shopping;
	int sum;
};
// xk用于标记是否需要生成仙人掌
// huachan用于标记是否正在进行滑铲动作
bool xk = 1, huachan = 0;
// huachantime 记录滑铲动作的持续时间
// huachancdtime 记录滑铲技能的冷却时间
int huachantime = 50, huachancdtime = 50;
double huachanshouyi = 0,huachancdshouyi = 0;
io shop[2]={{100,0},{50,0}};
bool piflag[6]={1,0,0,0,0,0};
int jinbishu=0;
int pijin[6]={0,5,10,20,50,100};
int huachanxiaohaoshu=20;
bool fanbei=0;
int fanbeitime=50,fanbeicdtime=100;
// 随机数生成函数,用于生成指定范围内的随机整数 , l 是随机数范围的下限,r 是随机数范围的上限
int rand_(int l, int r) {
    std::srand(static_cast<unsigned int>(std::time(nullptr)));
    int random_num = std::rand() % r + l;
    return random_num;
}
// 绘制恐龙皮肤的函数
// x_ 是当前绘制位置的 x 坐标,y_ 是恐龙的基准 y 坐标
void pifu(int x_, int y_) { 
    // 每个汉字由两个字符组成
    // 根据是否处于滑铲状态决定显示皮肤文字还是空白
    if (x_ == y_ && huachan == 0) cout << pi[p][0] << pi[p][1];
    else if (x_ == y_ && huachan == 1) cout << "  ";
    if (x_ == y_ + 1 && huachan == 0) cout << pi[p][2] << pi[p][3];
    else if (x_ == y_ + 1 && huachan == 1) cout << "  ";
    if (x_ == y_ + 2) cout << pi[p][4] << pi[p][5];
    if (x_ == y_ + 3) cout << pi[p][6] << pi[p][7];
}
// 显示游戏提示信息的函数
void tishi() {
    system("cls");
    cout << "-------------------------" << endl;
    cout << "           说明          " << endl;
    cout << "     游戏内按空格跳跃    " << endl;
    cout << " “X”是仙人掌,碰到会死 " << endl;
    cout << "跳跃请长按“空格”到跳起为止" << endl;
    cout << " 可以按对应键释放不同技能" << endl; 
    cout << "禁止装逼,不然让你飞起来" << endl;
    cout << "-------------------------" << endl;
    system("pause");
    system("cls");
}
int shang(double x){
	if(int(x)-x>0){
		return int(x+1);
	}
	else return x;
}
void SetConsoleFullScreen() {
    INPUT inputs[4] = {};

    
// 按下 Alt 键
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_MENU;

// 按下 Enter 键
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = VK_RETURN;

// 释放 Enter 键
inputs[2].type = INPUT_KEYBOARD;
inputs[2].ki.wVk = VK_RETURN;
inputs[2].ki.dwFlags = KEYEVENTF_KEYUP;

}
void quan() {
    SetConsoleFullScreen();
}
// 检测按键输入的函数
// h__ 是需要检测的按键字符
bool shuru_(char h__) {
    for (int i = 0; i <= 255; ++i) {
        if (GetAsyncKeyState(i) & 0x8000) {
            if (i == h__) {
                return 1;
            }
        }
    }
    return 0;
}
// 显示游戏开始界面的函数
void chu() {
	system("cls");
    system("color 0f");
    SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
    cout << "----------------------" << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN);
    cout << "         傻恐龙       " << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
    cout << "       按 s 开始      " << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE);
    cout << "      按 h 换角色     " << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN);
    cout << "     按 n 退出游戏    " << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
    cout << "   按 t 查看游戏说明  " << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE);
    cout << "   按 k 查看技能说明  " << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED);
    cout << "    按 m 查看得分     " << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_RED);
    cout << "   按 c 进行技能升级  " << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    cout << "    按 p 进入商店     " << endl; 
    SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
    cout << "----------------------" << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
}
// 显示历史最高得分和碰到的仙人掌总数的函数
void maxd() {
	SetConsoleTextAttribute(hConsole, FOREGROUND_RED);
    cout << "最高分:" << maxde << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN);
    cout << "仙人掌个数:" << xian << endl;
    SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED);
    cout << "金币个数 : " <<  jinbishu << endl;
	SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
	cout << "不死图腾个数:"<<shop[0].sum<<endl;
	SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
    system("pause");
}
// 显示换皮肤界面的函数
void huan() {
    cout << "1.我  2.我  3.我  4.阿  5.鸡  6.X" << endl;
    cout << "  是    是    是    米    汤    X" << endl;
    cout << "  恐    奶    个    诺    来    X" << endl;
    cout << "  龙    龙    人    斯    喽    X" << endl;
    cout << "  2号 5 个,3 号 10 个,4 号 20 个  " << endl;/*0,5,10,20,50,100*/
    cout << "    5 号 50 个,6 号 100 个    " << endl;
    cout << "当前金币:" << jinbishu << endl;
    cout << "   输入皮肤序号(默认为 1)  " << endl;
}
// 绘制游戏界面并判断是否死亡的函数
// flag_ 标记是否需要绘制仙人掌,y__ 是仙人掌的高度,o_ 是仙人掌的 x 坐标,tiao_ 是恐龙当前的跳跃高度
int ch(bool flag_, int y__, int o_, int tiao_) {
    // 根据得分情况改变控制台颜色和调整游戏难度
    int k = tiao_;
    int j_ = 60;
    int u_i_ = 1;
    if (de % 500 == 0 && de % 1000 != 0) system("color 0f");
    if (de % 1000 == 0) system("color f0");
    if (de % 1000 == 900) system("color 6e");
    if (de % 1000 == 400) system("color e6");
    if (de % 2000 >= 1900 && de % 2000 <= 1999) {
        j_ = 40;
        system("color 7f");
    }
    if (de % 500 == 0 && de % 1000 != 0 && de % 3000 <= 2999 && de % 3000 >= 2000) {
        system("color 40");
        j_ = 50;
        y__ = 3;
    }
    cout << "得分:" << de << endl;
    cout << "滑铲冷却时间:" << huachancdtime << endl;
    if((piflag[0]==1 & piflag[1]==1 & piflag[2]==1 & piflag[3]==1 & piflag[4]==1 & piflag[5]==1)){
    	cout << "翻倍冷却时间:"<< fanbeicdtime<<endl;
    	if(fanbei==1) cout << "翻倍剩余时间:" << fanbeitime << endl;
    	else cout << endl;
	}
    if(huachan==1) cout << "滑铲剩余时间:" << huachantime << endl;
    else cout << endl;
    // 双重循环遍历游戏界面的每个位置进行绘制
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < j_; j++) {
            if (j == 4) pifu(i, k);
            if (flag_ == 1 && xk == 1) {
                if (i >= 9 - y__ && i <= 8 && j == o_) {
                    if (i == k + 3 && j == 4 && huachan == 0) {
                        u_i_ = 0;
                    }
                    else if (i == k + 3 && j == 4 && huachan == 1) {
                        xk = 0;
                        xian += y__;
                    }
                    cout << 'X';
                }
            }
            if (i == 9) cout << '-';
            else cout << ' ';
        }
        cout << endl;
    }
    if(u_i_ == 0 & shop[0].sum >= 1){
		u_i_=1;
		shop[0].sum--;
	}
    return u_i_;
}

void r(){
    std::ifstream inFile("game_data.txt");
    if (inFile.is_open()) {
        inFile >> maxde >> xian >> jinbishu >>p >> piflag[0] >> piflag[1]>> piflag[2]>> piflag[3]>> piflag[4]>> piflag[5] >> shop[0].sum>>huachanshouyi>>huachancdshouyi>>huachanxiaohaoshu;
        inFile.close();
    }
}
int shangdian(){
	system("cls");
	cout << "-------商店-------"<<endl;
	cout << "1.不死图腾        "<<endl;
	cout << "效果:免疫一次死亡"<<endl;
	cout << "价格:100金币     "<<endl;
	cout << "                  "<<endl;
	cout << "2.仙人掌          "<<endl;
	cout << "效果:用于技能升级"<<endl;
	cout << "价格:50金币      "<<endl;
	cout << "------------------"<<endl;
	int f=0;
	cout << endl;
	cout << "请输入想要买的物品序号(不买东西输入0):"<< endl;
	cin >> f;
	return f;
}

void w(){ 
    std::ofstream outFile("game_data.txt");
    if (outFile.is_open()) {
        outFile << maxde << " " << xian << " " << jinbishu<< " " << p<<" "<<piflag[0]<<" "<<piflag[1]<<" "<<piflag[2]<<" "<<piflag[3]<<" "<<piflag[4]<<" "<<piflag[5]<<" "<<shop[0].sum<<' '<<huachanshouyi<<' '<<huachancdshouyi<<' '<<huachanxiaohaoshu;
        outFile.close();
    }
}

void jieshao() {
    system("cls");
    cout << "-------------------------------------------------------------------------------" << endl;
    cout << "         技能说明        " << endl;
    SetConsoleTextAttribute(hConsole,FOREGROUND_GREEN);
    cout << " 技能名称:滑铲" << endl;
    cout << " 技能按键:S" << endl;
    cout << " 技能效果:在滑铲期间,小恐龙可以穿过仙人掌而不死亡,并且可以获得碰到的仙人掌" << endl;
    cout << " 技能持续时间:" << huachantime << " 个游戏帧" << endl;
    cout << " 技能冷却时间:" << huachancdtime << " 个游戏帧" << endl;
    cout << " 技能特殊效果:如果滑铲结束时玩家离仙人掌太近,将获得额外 20 个游戏帧的滑铲"<<endl;
    if(!(piflag[0]==1 & piflag[1]==1 & piflag[2]==1 & piflag[3]==1 & piflag[4]==1 & piflag[5]==1)) goto S;
    SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN);
    cout << " 技能名称:翻倍" << endl;
    cout << " 技能按键:F" << endl;
    cout << " 技能效果:在翻倍期间,玩家得分翻倍" << endl;
    cout << " 技能持续时间:" << fanbeitime << " 个游戏帧" << endl;
    cout << " 技能冷却时间:" << fanbeicdtime << " 个游戏帧" << endl;
    cout << " 技能特殊效果:无法升级,但可以锁住时间,即不会更换天气"<<endl;
    S : ;
    SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
    cout << "-------------------------------------------------------------------------------" << endl;
    system("pause");
    system("cls");
}
void shengji(){
	if(huachancdtime<=10){
		cout << "-----满级-----"<<endl;
		goto loop; 
	}
	cout <<huachanxiaohaoshu<< " 仙人掌 进行一次升级"<<endl;
	cout << "是否升级:"<<endl;
	cout << "升级输入 y ,不升级输入 n"<<endl;
	loop : ;
}
int main() {
	quan();
	r();
    while (1){
        chu();
        char w_;
        cin >> w_;
        if(w_=='p'){
        	int s=shangdian()-1;
        	if(s==-1) continue;
        	else
        	{
        		if(jinbishu>=shop[s].shopping){
        			system("cls");
        			jinbishu-=shop[s].shopping;
        			shop[s].sum++;
        			xian+=shop[1].sum;
        			shop[1].sum=0;
        			cout<< "购买成功"<<endl;
        			Sleep(1000);
				}
				else{
					system("cls");
					cout << "-----ERROR-----";
					Sleep(1500);
				}
			}
		} 
        if (w_ == 'k') {
            system("cls");
            jieshao();
            continue;
        }
        if( w_=='c'){
        	system("cls");
        	shengji();
        	char c;
        	cin >> c;
        	if(c=='y'){
        		system("cls");
        		cout << "稍等 . . ."<<endl;
        		if(huachanxiaohaoshu<=xian){
        			xian-=huachanxiaohaoshu;
        			huachanshouyi += 1.0/100;
        			huachancdshouyi+=0.5/100;
        			Sleep(1000);
        			system("cls");
        			cout << "升级成功!"<<endl;
					huachanxiaohaoshu+=10;
				}
				else{
					Sleep(1000);
					system("cls");
        			cout << "升级失败!距离升级剩余:"<<huachanxiaohaoshu-xian<<" 个仙人掌"<<endl;
				}
				system("pause");
			}
			else{
				system("cls");
				cout << "取消成功!"<<endl;
				system("pause");
			}
		}

        if (w_ == 'h') {
            system("cls");
            huan();
            if(huachancdtime<=10){
            	Sleep(2000);
            	continue;
			}
            int r__;
            cin >> r__;
            system("cls");
            int p_ = r__ - 1;

            if (jinbishu >= pijin[p_] | piflag[p_]==1) {
                cout << "更换成功";
                p = p_ ;
                if(piflag[p_]==0){
                	jinbishu-=pijin[p_];
                	piflag[p_]=1;
				}
            }
            else cout << "更换失败";
            Sleep(1000);
            system("cls");
        }

        if (w_ == 'm') {
            system("cls");
            maxd();
            system("cls");
        }

        if (w_ == 't') {
            tishi();
        }

        if (w_ == 'n') {
        	w();
            system("cls");
            SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN);
            cout << "感谢您的使用 !"<<endl;
            SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
            return 0;
        }

        if (w_ == 's') {
            de = 0;
            bool ti = 0;
            int ao = 0;
            bool u = 1, o = 1;
            int r = 49;
            int r_u_ = rand_(1, 3);
            while(u == 1){

                if ((shuru_('s') || shuru_('S')) && huachancdtime == 0 && huachan == 0) {
                    huachan = 1;
                }
                if (huachan == 1 && huachantime > 0) {
                    huachantime--;
                }
                if (huachan == 1 && huachantime == 0) {
                    huachan = 0;
                    huachancdtime = 100;
                    huachantime = 80;
                }
                if((piflag[0]==1 & piflag[1]==1 & piflag[2]==1 & piflag[3]==1 & piflag[4]==1 & piflag[5]==1)){
                	if ((shuru_('f') | shuru_('F')) && fanbeicdtime == 0 && fanbei == 0){
                	    fanbei = 1;
                	}
                	if (fanbei == 1 && fanbeitime > 0) {
                	    fanbeitime--;
                	}
                	if (fanbei == 1 && fanbeitime == 0) {
                    	fanbei = 0;
                    	fanbeicdtime = 50;
                    	fanbeitime = 10;
                	}
				}
         if (de % 3000 < 2999 && de % 3000 > 2500) r_u_ = 3;

                if (shuru_(' ') == 1 & ti == 0 & huachan==0) {
                    ti = 1;
                }

                if (o == 0) {
                    r = 49 + rand_(2, 4);
                    o = 1;
                    xk = 1;
                    r_u_ = rand_(1, 3);
                }


                if (o == 1) {
                    u = ch(1, r_u_, r, tiao[ao]);
                    r--;
                    if (r <= 0) o = 0;
                }
                else u = ch(0, 0, 0, tiao[ao]);

                if (huachan == 1) {
                    Sleep(5);
                }
                else {
                    Sleep(40);
                }
                system("cls");
                de++;
				if(fanbei==1) de+=2;
        
                if (u == 0) {
                    system("color 0f");
                    system("cls");
                    cout << "得分:" << de;
                    maxde = max(maxde, de);
                    Sleep(2000);
                    system("cls");
                }
                if (ti == 1 && ao <= 18) ao++;
                if (ti == 1 && ao == 19) {
                    ao = 0;
                    ti = 0;
                }
                
                if (huachancdtime > 0) huachancdtime--;
                if(fanbeicdtime>0&(piflag[0]==1&piflag[1]==1&piflag[2]==1&piflag[3]==1&piflag[4]==1&piflag[5]==1))fanbeicdtime--; 
                if(huachantime==2){
                	if(r<=15){
                		huachantime+=20;
					}
				}
            }
            jinbishu+=de/100;
        }
        huachantime=70+70*huachanshouyi;
        huachancdtime=shang(100-100*huachancdshouyi);
    }
    return 0;
}

7 comments

  • 1