C++打怪小游戏

这是一款用C++代码写出来的打怪游戏。

上图片👇

在这里插入图片描述![](https://i-blog.csdnimg.cn/direct/6a4497c784ff4ba7a3332bc97d433789.png
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

一个11岁小朋友,爆肝532行,11小时完成代码,内部14个函数,5个结构体,三连帮助一下!😘😘😘

// 古文波原创 // 
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>

using namespace std;

int now_zombies = 0;
int now_WuQi = 0;
bool fuli;

struct Me {
	int HP;
	int Attack;
	int Lvl;
	int Exp;
	int EXP_MAX;
	int QH;
} My;

struct zombie {
	int HP;
	int Attack;
	string Name;
	int hard;
} a[10007];

struct WU {
	string name;
	int add_Att;
	int add_HP;
	int kind;
	bool have;
} w[10007];

struct Ku {
	int wuqi_id;
	int fangjv_id;
	int zuoqi_id;
} WuQi_Ku;

struct SheZhi {
	bool Fast;
	bool Buff;
} SZ;

void cls() {
	system("cls");
}

void new_(int hp, int att, string name, int Hard) {
	int t = ++now_zombies;
	a[t].HP = hp;
	a[t].Attack = att;
	a[t].Name = name;
	a[t].hard = Hard;
}

void _new(string n, int add_1, int add_2, int kinds) {
	int t = ++now_WuQi;
	w[t].name = n;
	w[t].add_Att = add_1;
	w[t].add_HP = add_2;
	w[t].kind = kinds;
	w[t].have = false;
}

int Me_Attack(int x) {
	int r = rand() % 100 + 1;
	int attack = 1;
	if(r <= 20) {
		attack = My.Attack * 2;
		printf("你:暴击!对敌方造成%d点高额伤害", attack); 
		return attack;
	}
	if(r >= 21 && r <= 25) {
		attack = My.Attack * 5;
		printf("你:大招!对敌方造成%d点爆炸伤害", attack);
		return attack;
	}
	if(r >= 26 && r <= 95) {
		attack = My.Attack;
		printf("你:对敌方造成%d点伤害", attack);
		return attack;
	}
	if(r >= 96 && r <= 100) {
		attack = x / 2;
		printf("你:使用毒素攻击!敌方血量减半");
		return attack;
	}
} 

int Di_Attack(int x, int att) {
	int r = rand() % 100 + 1;
	int attack = 1;
	if(r <= 20) {
		attack = att * 2;
		printf("敌:暴击!对你造成%d点高额伤害", attack); 
		return attack;
	}
	if(r >= 21 && r <= 25) {
		attack = att * 5;
		printf("敌:大招!对你造成%d点爆炸伤害", attack);
		return attack;
	}
	if(r >= 26 && r <= 95) {
		attack = att;
		printf("敌:对你造成%d点伤害", attack);
		return attack;
	}
	if(r >= 96 && r <= 100) {
		attack = x / 2;
		printf("敌:使用毒素攻击!你的血量减半");
		return attack;
	}
} 

int Zombie_Attack(int att) {
	int r = rand() % 100 + 1;
	printf("怪物对你造成%d点伤害", att);
	if(r <= 20) {
		printf("\n攻击被格挡,伤害减半");
		att /= 2; 
	}
	if(r >= 21 && r <= 25) {
		printf("\n攻击被闪避");
		att = 0;
	}
	return att;
}

void ccc(string s) {
	for(int i = 0; i < s.size(); i++) {
		cout << s[i];
		Sleep(20);
	}
	cout << "\n";
}

void slow(string s) {
	int f;
	if(SZ.Fast) f = 1;
	else f = 2;
	for(int i = 0; i < s.size(); i++) {
		cout << s[i];
		Sleep(150 * f);
	}
	cout << "\n";
}

void Game() {
	srand((unsigned)time(NULL));
	cls();
	ccc("欢迎英雄回家!");
	Sleep(1000);
	cls();
	ccc("请选择你想要操作:");
	ccc("1.关卡 2.查看我的信息 3.强化 4.双人对战 5.装备区 6.更新日志 7.新手福利 8.自定义设置");
	string s;
	cin >> s;
	if(s == "1") {
		cls();
		int t = 0, r = 0;
		for(int i = 1; i <= 3; i++) {
			cout << "已加载" << i * 30 << "%~\n";
			t = r;
			r = rand() % 6 + 1;
			if(r == t) r = rand() % 6 + 1; 
			if(r == 1) printf("主线关卡和双人对战获胜均可获得经验值~\n");
			if(r == 2) printf("强化可以增加20%的属性~\n");
			if(r == 3) printf("毒素非常厉害,可以让怪物血量砍半~\n");
			if(r == 4) printf("可以在主页看到自己的等级~\n");
			if(r == 5) printf("Boss关卡难度很高,可以重复打之前的关卡升级再打~\n");
			if(r == 6) printf("对方的攻击是可能被格挡或闪避的哦~\n"); 
			slow("->->->");
			cls();
		}
		ccc("选择关卡");
		for(int i = 1; i <= now_zombies; i++) {
			printf("%d. ", i);
			cout << a[i].Name;
			cout << "\t";
			if(i < 6 || i > 9) cout << "\t";
			cout << "难度:";
			for(int j = 1; j <= a[i].hard; j++) cout << "☆";
			cout << "\n";
		}
		int x;
		cin >> x;
		if(x < 1 || x > now_zombies) {
			cls();
			system("color 04");
			slow("Error!");
			Sleep(1000);
			system("color 09");
			Game();
		}
		else {
			cls();
			slow("战斗准备中~~~");
			cout << "\n";
			int zombie_HP = a[x].HP;
			int zombie_Attack = a[x].Attack;
			int My_HP = My.HP;
			int My_Attack = My.Attack;
			while(1) {
				zombie_HP -= Me_Attack(zombie_HP);
				printf("\n怪物还剩%d点血\n\n", zombie_HP);
				Sleep(1000);
				if(zombie_HP <= 0) {
					cls();
					slow("获得胜利!");
					Sleep(1000);
					My.Exp += 100 << x;
					My.QH += 5 << x - 1; 
					if(My.Exp >= My.EXP_MAX) {
						cls();
						slow("升级了");
						My.Exp -= My.EXP_MAX;
						My.EXP_MAX <<= 1;
						My.Lvl++;
						My.Attack *= 1.5;
						My.HP *= 1.5; 
						printf("你现在%d级", My.Lvl);
						Sleep(1000);
						break;
					}
					break;
				}
				My_HP -= Zombie_Attack(zombie_Attack);
				printf("\n你还剩%d点血\n\n", My_HP);
				Sleep(1000);
				if(My_HP <= 0) {
					cls();
					slow("You Die!");
					My.Exp /= 2;
					break;
				}
			}
			Game();
		}
	}
	if(s == "2") {
		cls();
		ccc("基本信息如下");
		printf("\n等级:%d\n经验值:%d\n经验值上限:%d\n攻击力:%d\n生命值:%d\n\n", My.Lvl, My.Exp, My.EXP_MAX, My.Attack, My.HP);
		ccc("请按任意键继续~~~");
		char c = getch();
		Game();
	}
	if(s == "3") {
		cls();
		printf("你有%d个强化点,强化需要10强化点\n", My.QH);
		Sleep(1000);
		if(My.QH < 10) {
			ccc("强化点不足,无法进行强化");
			Game();
		}
		ccc("输入:1. 强化攻击 2. 强化生命");
		char c = getch();
		if(c == '1') My.Attack = My.Attack * 6 / 5;
		else My.HP = My.HP * 6 / 5; 
		My.QH -= 10;
		cls();
		slow("强化成功!");
		Game();
	}
	if(s == "4") {
		cls();
		for(int i = 1; i <= 3; i++) {
			cout << "正在联网寻找对手";
			slow("->->->");
			cls();
		}
		int r = rand() % 10 + 1;
		cout << "你 VS ";
		if(r == 1) cout << "烟柳一枝花";
		if(r == 2) cout << "英雄小五";
		if(r == 3) cout << "笑的很甜蜜";
		if(r == 4) cout << "北风吹";
		if(r == 5) cout << "别打了";
		if(r == 6) cout << "你干嘛~";
		if(r == 7) cout << "牢大坠机啦!";
		if(r == 8) cout << "秋风萧瑟";
		if(r == 9) cout << "为神马0505";
		if(r == 10) cout << "江洋大盗重彪脸";
		Sleep(1000);
		cls();
		int My_HP = My.HP;
		int Di_Att = (rand() % (My.Lvl * 15) + 10) / 5 * 5;
		int Di_HP = My.Lvl * 100 - Di_Att;
		while(1) {
			Di_HP -= Me_Attack(Di_HP);
			printf("\n敌方还剩%d点血\n\n", Di_HP);
			Sleep(1000);
			if(Di_HP <= 0) {
				cls();
				slow("Win!!!");
				My.Exp += pow(10, My.Lvl + 1) * 2;
				My.QH += 5 << My.Lvl - 1; 
				if(My.Exp >= My.EXP_MAX) {
					cls();
					slow("升级了");
					My.Exp -= My.EXP_MAX;
					My.EXP_MAX <<= 1;
					My.Lvl++;
					My.Attack *= 1.5;
					My.HP *= 1.5; 
					printf("你现在%d级", My.Lvl);
					Sleep(1000);
					break;
					}
				Game(); 
			}
			My_HP -= Di_Attack(My_HP, Di_Att);
			printf("\n你还剩%d点血\n\n", My_HP);
			Sleep(1000);
			if(My_HP <= 0) {
				cls();
				slow("Lose!!!");
				Game();
			}
		}
	}
	if(s == "5") {
		cls();
		ccc("您有如下装备");
		cout << "\n";
		bool f = false;
		for(int i = 1; i <= now_WuQi; i++) {
			if(w[i].have) {
				cout << w[i].name << "\n\n";
				f = true;
			}
		}
		if(!f) {
			Sleep(1000);
			ccc("啊嘞?空空如也");
		}
		cout << "\n";
		ccc("已装备:");
		int t1 = WuQi_Ku.wuqi_id, t2 = WuQi_Ku.fangjv_id, t3 = WuQi_Ku.zuoqi_id;
		cout << "武器:" << w[t1].name << "\n";
		cout << "防具:" << w[t2].name << "\n";
		cout << "坐骑:" << w[t3].name << "\n";
		ccc("你要装上装备吗?(Y/N)");
		char c = getch();
		if(c == 'Y') {
			cls();
			ccc("装上哪个编号的?");
			for(int i = 1; i <= now_WuQi; i++) {
				cout << i << ". " << w[i].name;
				printf(" 攻击加成:%d 生命加成:%d 拥有状态:", w[i].add_Att, w[i].add_HP);
				if(w[i].have) cout << "Yes";
				else cout << "No";
				cout << "\n";
			}
			int x;
			cin >> x;
			if(!w[x].have) {
				cls();
				ccc("你未拥有");
				Sleep(1000);
				Game();
			}
			if(w[x].kind == 1) {
				WuQi_Ku.wuqi_id = x;
				My.Attack += w[x].add_Att;
				My.HP += w[x].add_HP;
			}
			if(w[x].kind == 2) {
				WuQi_Ku.fangjv_id = x;
				My.Attack += w[x].add_Att;
				My.HP += w[x].add_HP;
			}
			if(w[x].kind == 3) {
				WuQi_Ku.zuoqi_id = x;
				My.Attack += w[x].add_Att;
				My.HP += w[x].add_HP;
			}
			Game();
		}
		else Game(); 
	}
	if(s == "6") {
		cls();
		ccc("v1.0.0 最基本的游戏");
		ccc("v1.0.3 加载画面修改");
		ccc("v1.1.2 新增强化功能");
		ccc("v1.1.5 修复已知问题,初始化界面修改");
		ccc("v1.1.9 增加关卡到10个");
		ccc("v1.3.1 增加双人对战模式");
		ccc("v1.4.9 增加武器库功能");
		ccc("v1.5.1 新增新人福利活动");
		ccc("v1.6.3 新增自定义设置"); 
		ccc("请按任意键继续~~~"); 
		char c = getch();
		Game();
	}
	if(s == "7") {
		cls();
		if(fuli) {
			slow("已领取~");
			Sleep(1000);
			Game();
		}
		ccc("推出新人福利活动!十件超强装备随机派送!");
		ccc("请按任意键领取");
		char c = getch();
		cls();
		slow("恭喜获得");
		int r = rand() % now_WuQi + 1;
		cout << w[r].name << "!";
		ccc("奖励已经发放到武器库~");
		w[r].have = true;
		fuli = true;
		Sleep(3000);
		Game(); 
	}
	if(s == "8") {
		cls();
		ccc("可设置:1.快速加载 2.外挂模式(关闭将初始化)");
		int x;
		cin >> x;
		if(x == 1) {
			if(SZ.Fast) {
				ccc("已关闭快速加载");
				SZ.Fast = false;
			}
			else {
				ccc("已开启快速加载");
				SZ.Fast = true;
			}
			Sleep(1000);
		}
		if(x == 2) {
			if(SZ.Buff) {
				ccc("已关闭外挂模式");
				SZ.Buff = false;
				My.Attack = 10;
				My.HP = 100;
			}
			else {
				ccc("已开启外挂模式");
				SZ.Buff = true;
				My.Attack = 114514;
				My.HP = 114514;
			}
			Sleep(1000);
		}
		Game();
	}
}

void My_inti() {
	My.Attack = 10;
	My.HP = 100;
	My.Lvl = 1;
	My.Exp = 0;
	My.EXP_MAX = 1000;
	My.QH = 0;
}

void zombies_inti() {
	new_(100, 10, "Cai XuKun", 1);
	new_(250, 25, "Lao Da", 2);
	new_(500, 30, "Ri Ben", 3);
	new_(600, 50, "Lao Liu", 3);
	new_(1000, 88, "Little Boss", 4);
	new_(1200, 100, "Chinese Teacher", 5);
	new_(500, 300, "Maths Teacher", 5);
	new_(2000, 50, "English Teacher", 5);
	new_(1500, 150, "I Have No NAME", 5);
	new_(3000, 300, "BIG BOSS!!!", 7);
}

void WuQi_inti() {
	w[0].name = "Null";
	_new("Qing Hong Sword", 30, -10, 1);
	_new("Green Dragon Crescent Blade", 50, 0, 1);
	_new("AK-47", 20, 0, 1);
	_new("Rattan Beetle", -10, 150, 2);
	_new("Chi Tu Horse", 10, 100, 3);
	_new("Gold Beetle", 0, 100, 2);
	_new("Di Du Horse", -10, 150, 3);
	_new("Ba Zu KA", 200, -50, 1);
	WuQi_Ku.wuqi_id = WuQi_Ku.fangjv_id = WuQi_Ku.zuoqi_id = 0;
}

void inti() {
	zombies_inti();
	My_inti();
	WuQi_inti();
	system("color 09");
	slow("By GuWenBo");
	Sleep(1000);
	cls();
	for(int i = 1; i <= 2; i++) {
		cls();
		cout << "Loading~~~\n";
		slow("->->->");
	}
	Sleep(300);
	Game();
}

int main() { inti();}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

古文波

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值