大家好,今天zty带来的是能量的1.0.3版本,此版本可以存档(自动的),用于保存战绩,在运行时会跳出主菜单,而不是直接开始游戏,辅助游戏的函数大小总和已经超过了游戏主体,zty这么辛苦,不妨点一个小小的赞吧。
先赞后看,养成习惯
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");
cd();
}
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<<"第"<<lun<<"轮"<<endl<<"1:波 2:海啸 3:天雷 4:能量 5:防(波) 6:防(海啸) 0:退出游戏 能量:"<<neng<<endl;
return;
}
void cd() {//游戏菜单
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();
case 2:
ckzj(zong,sheng,bai);
case 3:
return;
}
}
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();
}
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");
cd();
} 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");
cd();
}
}
return;
}
int main() {
cout<<"欢迎游玩“能量”小游戏\n";
Bling();
drcd();
cd();
return 0;
}
作者:zty郑桐羽呀
联系方式:(不挂了,有事私信)