[C++] 小游戏 能量 1.0.4版本 zty出品

  大家好,今天的最后一篇文章就带来能量的1.0.4版本吧,这个版本主要修复了bug,并且增加了一些小细节,废话不多说

先赞后看 养成习惯

CODE:

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int zong,sheng,bai;
void yxzt();
void cd();
void ckzj();
void ckzj(int zong,int sheng,int bai) {//查看战绩
	system("cls");
	cout<<"================================================================================\n\n\t   总场数:"<<zong;
	cout<<"\t\t胜场数:"<<sheng;
	cout<<"\t\t败场数:"<<bai;
	cout<<"\n\n\n================================================================================";
	system("pause");
	return;
}
void drcd() { //读入存档
	string line;
	fstream myFile;
	int s=0;
	myFile.open("能量存档.txt", ios::in);  // read,读
	if (myFile.is_open()) {
		while(getline(myFile, line)) {
			string str(line);
			s++;
			if(s==1)
				bai = atoi(str.c_str());
			if(s==2)
				sheng = atoi(str.c_str());
			if(s==3)
				zong = atoi(str.c_str());
		}
		myFile.close();
	}
}
int rgzz(int lun, int dineng, int neng) {//人工智障系统
	while(1) {
		int dichu=0;
		if(lun==1) {
			return 4;
		}
		if(dineng>=3) {
			return 3;
		}
		srand(time(0));
		dichu=rand()%5+1;
		if(dineng==1&&dichu==2||dineng<=2&&dichu==3) continue;
		else if(dineng<1&&dichu<4) continue;
		else if(neng>2&&dichu==6) continue;
		else if(neng<1&&dichu>4) continue;
		else if(neng==0 && (dichu==5 || dichu==6)) continue;
		else return dichu;
	}
}
void ts(int lun,int neng) { //战斗提示
	cout<<"\n第"<<lun<<"轮"<<endl<<"1:波  2:海啸  3:天雷  4:能量  5:防(波)  6:防(海啸) 0:退出游戏  能量:"<<neng<<endl;
	return;
}
void cd() {//游戏菜单
	while(1) {
		system("cls");
		system("color 8E");
		cout<<"\n\n================================================================================\n\t\t  1,开始游戏     2,查看战绩     3,退出游戏\n\n================================================================================";
		int xuan;
		cin>>xuan;
		switch(xuan) {
			case 1:
				yxzt();
				break;
			case 2:
				ckzj(zong,sheng,bai);
				break;
			case 3:
				return;
				break;
			default:
				printf("无该选项!\n\n\n");
				Sleep(300);
		}
	}

}
void bccd(int zong,int sheng,int bai) { //保存存档
	char line[256];
	fstream myFile;
	myFile.open("能量存档.txt", ios::out);
	if (myFile.is_open()) {
		myFile<<bai<<"\n";
		myFile<<sheng<<"\n";
		myFile<<zong<<"\n";
		myFile.close();
	}
}
void Bling() { //开始动画
	for(int i=0; i<=3; i++) {
		system("color 1A");
		Sleep(40);
		system("color 2B");
		Sleep(40);
		system("color 3C");
		Sleep(40);
		system("color 4D");
		Sleep(40);
		system("color 5D");
		Sleep(40);
		system("color 6E");
		Sleep(40);
		system("color 7F");
		Sleep(40);
	}
}
void yxzt() { //游戏主体
	system("cls");
	system("color 8E");
	int neng=0,dineng=0,lun=0;
	while(1) {
		int gong=0,fang=0,digong=0,difang=0,chu=0,dichu=0;
		lun++;
		ts(lun,neng);
		cin>>chu;
		switch(chu) { //玩家控制
			case 1:
				if(neng>=1) {
					gong=1;
					neng--;
					cout<<"我:\n波"<<endl;
				} else {
					cout<<"没有足够的能量"<<endl;;
					lun--;
					continue;
				}
				break;
			case 2:
				if(neng>=2) {
					gong=2;
					neng-=2;
					cout<<"我:\n海啸"<<endl;
				} else {
					cout<<"没有足够的能量"<<endl;
					lun--;
					continue;
				}
				break;
			case 3:
				if(neng>=3) {
					gong=3;
					neng-=3;
					cout<<"我:\n天雷"<<endl;
				} else {
					cout<<"没有足够的能量"<<endl;
					lun--;
					continue;
				}
				break;
			case 4:
				neng++;
				cout<<"我:\n能量"<<endl;
				break;
			case 5:
				fang=1;
				cout<<"我:\n波防"<<endl;
				break;
			case 6:
				fang=2;
				cout<<"我:\n海啸防"<<endl;
				break;
			case 0:
				cd();
			default:
				printf("无该选项!\n\n\n");
				Sleep(300);
		}
		dichu=rgzz(lun,dineng,neng);
		cout<<"敌:"<<endl;
		switch(dichu) { //机器控制
			case 1:
				digong=1;
				dineng--;
				cout<<"波"<<endl;
				break;
			case 2:
				digong=2;
				dineng-=2;
				cout<<"海啸"<<endl;
				break;
			case 3:
				digong=3;
				dineng-=3;
				cout<<"天雷"<<endl;
				break;
			case 4:
				dineng++;
				cout<<"能量"<<endl;
				break;
			case 5:
				difang=1;
				cout<<"波防"<<endl;
				break;
			case 6:
				difang=2;
				cout<<"海啸防"<<endl;
				break;
		}
		if((gong==difang&&gong!=0) || chu==dichu || (digong==fang&&digong!=0)) continue;//判断游戏是否结束
		else if((gong>digong&&gong!=difang) || (dichu==4&&gong>0) || (dichu==4&&gong!=0)) {
			cout<<"YOU WIN!\n\n";
			zong++;
			sheng++;
			bccd(zong,sheng,bai);
			system("pause");
			return;
		} else if((digong>gong&&digong!=fang) || (digong!=fang&&digong!=0) || (chu==4&&digong>0)) {
			cout<<"YOU DIE!\n\n";
			zong++;
			bai++;
			bccd(zong,sheng,bai);
			system("pause");
			return;
		}
	}
	return;
}
int main() {
	system("title 能量 1.0.4  zty出品");
	system("mode con cols=80 lines=20");
	cout<<"欢迎游玩“能量”小游戏\n";
	Bling();
	drcd();
	cd();
	return 0;
}

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值