C++小游戏合集

开局一个卒,士兵全靠买!

// By School //

#include <bits/stdc++.h>
#include <windows.h> 
#include <conio.h>

using namespace std;

void ccc(); // 匀速输出 
void c_slow(); // 缓慢输出 
void cls(); // 清屏 
void Error(); // 输出"Input Error" 
void zhuye(); // 主界面 
void inti(); // 初始化 

long long money;
long long bing_1,bing_2 = 1,bing_3;
long long my_shili;

void ccc(string s) { // 匀速输出 
	for(int i = 0; i < s.size(); i++) {
		cout << s[i];
		Sleep(25);
	}
	printf("\n");
}

void c_slow(string s) { // 缓慢输出 
	for(int i = 0; i < s.size(); i++) {
		cout << s[i];
		Sleep(444);
	}
	printf("\n");
}

void cls() { // 清屏 
	system("cls");
}

void Error() { // 输出"Input Error" 
	cls();
	c_slow("Input Error!");
	zhuye();
}

void zhuye() { // 主界面 
	cls();
	ccc("1.说明 2.商店 3.征战 4.我的资料 5.礼包码");
	char s = getch();
	if(s == '1') {
		cls();
		ccc("版本号: v.1.06 ");
		ccc("征战获得钱");
		ccc("钱买士兵");
		ccc("按任意键继续");
		char a = getch();
		zhuye();
	} else if(s == '2') {
		cls();
		ccc("1.普通士兵 10 元 一个 2. 中级士兵 66 元一个 3.高级士兵 111元一个 4.返回");
		char a = getch();
		if(a == '4') zhuye();
		if(a == '1') {
			ccc("输入个数");
			printf("你有%lld元",money);
			int num;
			cin >> num;
			if(money >= num * 10) {
				money -= num * 10;
				bing_1 += num;
				ccc("购买成功!");
				zhuye();
			} else Error(); 
		}
		if(a == '3') {
			ccc("输入个数");
			printf("你有%lld元",money);
			int num;
			cin >> num;
			if(money >= num * 111) {
				money -= num * 111;
				bing_3 += num;
				ccc("购买成功!");
				zhuye();
			} else Error();
		}
		if(a == '2') {
			ccc("输入个数");
			printf("你有%lld元",money);
			int num;
			cin >> num;
			if(money >= num * 66) {
				money -= num * 66;
				bing_2 += num;
				ccc("购买成功!");
				zhuye();
			} else Error();
		}
	} else if(s == '3') {
		cls(); 
		my_shili = bing_1 * 3 + bing_2 * 10 + bing_3 * 30; 
		printf("我方战力:%lld\n",my_shili);
		ccc("输入敌人等级(1 ~ 50)");
		int num; cin >> num;
		if(num < 1 || num > 50) Error();
		long long di_shili = pow(2,num);
		while(1){
			if(di_shili <= 0) {
				cls();
				ccc("You Win!");
				money += pow(3,num);
				printf("你获得了");
				cout << pow(3,num);
				printf("元!\n");
				Sleep(1000);
				zhuye(); 
			} if(my_shili <= 0) {
				cls(); 
				ccc("你全军覆没了!");
				Sleep(1000);
				ccc("你在混乱中被杀");
				cls();
				c_slow("You Are Die!");
				Sleep(500);
				inti();
			}
			printf("敌方战力:%lld\n",di_shili);
			printf("我方战力:%lld\n",my_shili);
			ccc("1.攻击 2.逃跑");
			char a = getch();
			if(a == '2') zhuye();
			if(a == '1') {
				if(my_shili >= di_shili) {
					bing_1 = ceil(bing_1 * 1.0 / 1.5);
					bing_2 = ceil(bing_2 * 1.0 / 1.25);
					bing_3 = ceil(bing_3 * 1.0 / 1.125);
					my_shili = bing_1 * 3 + bing_2 * 10 + bing_3 * 30;
					di_shili /= 3;
				} else {
					bing_1 /= 2.5;
					bing_2 /= 2;
					bing_3 /= 1.5;
					my_shili = bing_1 * 3 + bing_2 * 10 + bing_3 *30;
					di_shili /= 1.5;
				}
			}
		}
	} else if(s == '4') {
		cls();
		printf("金币:%lld\n", money);
		printf("普通士兵:%lld\n", bing_1);
		printf("中级士兵:%lld\n", bing_2);
		printf("高级士兵:%lld\n", bing_3);
		printf("战力值:%lld\n", bing_1 * 3 + bing_2 * 10 + bing_3 * 30);
		ccc("按任意键继续");
		char a = getch(); zhuye();
	} else if(s == '5') {
		cls();
		ccc("输入兑换码");
		string a; getline(cin,a);
		if(a == "HAPPY666") {
			cls();
			ccc("恭喜获得:200元");
			money += 200;
			Sleep(500);
			zhuye();
		} if(a == "School666") {
			cls();
			ccc("恭喜获得:20名中级士兵");
			bing_2 += 20;
			Sleep(500);
			zhuye(); 
		} if(a == "C++666") {
			cls();
			ccc("恭喜获得:6名高级士兵");
			bing_3 += 6;
			Sleep(500);
			zhuye();
		} if(a == "DevC++666") {
			cls();
			ccc("恭喜获得:66名低级士兵");
			bing_1 += 66;
			Sleep(500);
			zhuye(); 
		} else Error();
	} else Error();
}

void inti() { // 初始化 
	cls();
	system("color 09");
	c_slow("By School");
	Sleep(500);
	cls();
	c_slow("Loading……");
	Sleep(500);
	zhuye();
} 

int main() { inti(); } // main()函数好像没用…… 

最强指挥官

// By School //

#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
 
using namespace std;

void ccc(string s);
void c_slow(string s);
void cls();
void Error();
void zhuye();
void inti();

long long lvl = 1;
long long sum;
long long money = 50;
long long wuqi = 5;
long long MAX_SUM = 10;

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

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

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

void Error() {
	cls();
	c_slow("Input Error!");
	Sleep(500);
	zhuye();
}

void zhuye() {
	cls();
	ccc("1.教程 2.征战 3.升级 4.招募 5.我的信息");
	char a = getch();
	if(a == '1') {
		cls();
		ccc("每次征战会获得财宝和武器");
		ccc("财宝和武器到达一定数量可以升级军队等级");
		ccc("军队等级的升级会大幅增加士兵上限和士兵战斗力");
		ccc("加油吧,指挥官!");
		ccc("请按任意键继续");
		char n = getch();
		zhuye();
	}
	else if(a == '2') {
		cls();
		ccc("输入等级 (<=50) 输入0返回");
		int n;
		cin >> n;
		if(n == 0) zhuye(); 
		cls();
		printf("敌方士兵数:");
		cout << pow(3,n) << "\n";
		printf("我方士兵数:%d\n",sum);
		printf("敌方等级:%d\n",n);
		printf("我方等级:%d\n",lvl);
		ccc("指挥官,是否发动进攻? 输入'Y'或'N' Y代表攻击 N代表逃跑");
		char num = getch();
		if(num == 'Y') {
			if((pow(3,n) * pow(2,lvl) < sum * pow(2,lvl))) {
				cls();
				c_slow("You Win!");
				ccc("恭喜收获:");
				printf("\t"); cout << pow(5,n + 1) << "元\n";
				printf("\t"); cout << pow(10,n - 1) << "把武器\n";
				printf("\t"); cout << floor(pow(3,n) / 5) << "名俘虏\n";
				ccc("请按任意键继续");
				char s = getch();
				money += pow(5,n + 1);
				wuqi += pow(10,n - 1);
				sum += pow(3,n) / 5;
				zhuye();
			} else { ccc("You Lose!"); zhuye(); }
		} 
		else if(num == 'N') {
			cls();
			ccc("你损失了一些军费!");
			printf("损失了:"); cout << pow(10,n) << "元"; money -= pow(10,n);
			Sleep(1000);
			zhuye();
		}
		else Error(); 
	}
	else if(a == '3') {
		cls();
		printf("你的当前等级是%d,升级需要",lvl);
		cout << pow(20,lvl + 1);
		printf("元和");
		cout << pow(3,lvl + 1);
		printf("把武器\n");
		ccc("是否购买? Please Input 'Y' or 'N'");
		char n = getch();
		if(n == 'Y') {
			if(money < pow(20,lvl + 1)) {
				cls();
				ccc("You Don't Have Enough Money!");
				zhuye();
			} else if(wuqi < pow(3,lvl + 1)) {
				cls();
				ccc("You Don't Have Enough Weapon!");
				zhuye();
			} else {
				money -= pow(20,lvl + 1); 
				wuqi -= pow(10,lvl);
				lvl++;
				MAX_SUM *= 5;
				ccc("OK!");
				Sleep(500);
				zhuye();
			}
		}
		else if(n == 'N') zhuye();
		else Error();
	}
	else if(a == '4') {
		cls();
		printf("招募一个士兵需要");
		cout << pow(10,lvl);
		printf("元,一把武器\n");
		ccc("你要多少? 输入数字 输入-1可以购买最大上限个士兵");
		int n;
		cin >> n;
		if(n == -1) {
			int n1 = (money / (pow(10,lvl))), n2 = wuqi;
			int num = min(n1,n2); int k = MAX_SUM - sum; if(num > k) num = k;
			money -= num * pow(10,lvl);
			wuqi -= num;
			sum += num;
			cls();
			ccc("OK!");
			printf("购买了%d个士兵",num);
			Sleep(500);
			zhuye();
		}
		else if(money < pow(10,lvl) * n) {
			cls();
			ccc("You Don't Have Enough Money!");
			zhuye();
		}
		else if(wuqi < n) {
			cls();
			ccc("You Don't Have Enough Weapon!");
			zhuye();
		}
		else if(sum + n > MAX_SUM) {
			cls();
			ccc("It Is So Big! Please add your level");
			zhuye(); 
		}
		else {
			sum += n;
			money -= pow(10,lvl) * n;
			cls();
			ccc("OK!");
			Sleep(500);
			zhuye();
		}
	} 
	else if(a == '5') {
		cls();
		printf("等级:%d\n",lvl);
		printf("士兵数量:%d\n",sum);
		printf("士兵上限:%d\n",MAX_SUM);
		printf("钱:%d\n",money);
		printf("武器数量:%d\n",wuqi);
		ccc("请按任意键继续");
		char n = getch();
		zhuye(); 
	}
	else Error();
}

void inti() {
	system("color 09");
	c_slow("By School");
	cls();
	c_slow("Loading……");
	cls();
	zhuye();
}

int main() { inti(); }

猜数游戏

// By School //
 
#include <bits/stdc++.h>
#include <windows.h>
 
using namespace std;
 
void cls() {
	system("cls");
}
 
int power(int n) {
	long long s = 1,i = 0;
	while(s < n) {
		s *= 2;
		i++;
	}
	return i;
}
 
void ccc(string s) {
	for(int i = 0; i < s.size(); i++) {
		cout << s[i];
		Sleep(25);
	}
	cout << "\n";
}
 
void c_slow(string s) {
	for(int i = 0; i < s.size(); i++) {
		cout << s[i];
		Sleep(444);
	}
	cout << "\n";
}
 
int main() {
	cls();
		ccc("输入范围 输入0关闭");
		int n;
		cin >> n;
		if(n == 0) 
			return 0;
		cls();
		printf("范围为 1 ~ %d\n",n); 
		long long s = power(n);
		long long ans = rand() % n + 1;
		printf("你最少要猜%d次,更少算我输!\n",s);
		ccc("猜吧");
		long long sum = 1;
		while(1) {
			int x;
			cin >> x;
			if(x > ans) {
				ccc("大了");
				sum++;
			}
			else if(x < ans) {
				ccc("小了");
				sum++;
			}
			else {
				cls();
				c_slow("Yes!");
				printf("你用了%d次!",sum);
				break;
			}
		}
	return 0;
}

  • 45
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
C++小游戏合集象棋、五子棋、俄罗期方块、坦克大战、2048、走迷宫、贪吃蛇等几十款小游戏.zip 一、开启c++ 游戏之门 对于许多初学者来说,c++ 可能是一门既神秘又令人畏惧的语言。但其实,c++ 也可以非常有趣!这次我们为您带来了一系列c++ 小游戏资源,旨在让您在轻松愉快的氛围中,逐步掌握c++ 的精髓。 二、资源亮点 由浅入深:我们为您提供了从入门级到进阶级的多种小游戏资源,满足您不同阶段的学习需求。 实践为王:这些资源不仅仅是理论,更有实际可运行的代码,让您亲身体验编程的乐趣。 模块化设计:每个游戏都按照功能模块进行划分,方便您学习和理解。 社区参与:我们鼓励您参与到社区中,与其他学习者分享经验,共同进步。 三、适用人群 无论您是初涉编程的新手,还是希望深入了解c++ 的进阶者,这些资源都能为您提供宝贵的实践机会。 四、使用建议 边学边做:建议您在学习过程中,积极动手实践,亲自感受c++ 的魅力。 不断挑战:尝试自行修改和优化游戏代码,培养独立思考和解决问题的能力。 交流与分享:加入我们的学习社群,与其他学习者交流心得,共同成长。 五、注意事项 尊重版权:请确保在使用这些资源时,遵循版权法规,尊重原创者的权益。 安全为先:在编写和运行代码时,请确保您的开发环境安全可靠,避免潜在风险。 持续学习:编程是一个不断进阶的过程,希望您能保持对知识的热情,持续深入学习。 感谢您选择我们的c++ 小游戏资源系列!让我们一起在探索中成长,用代码书写属于我们的精彩故事!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

古文波

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

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

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

打赏作者

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

抵扣说明:

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

余额充值