c++游戏火龙征战V1.0.2

终于完成了第一章!

不愧是我

更新内容:

1.第一章boss
2.商店有了退出按键
3.窗口名字" 
4.一些小bug

#include
#include 
#include 
using namespace std;
int zhangjie=0;
long long yuanatk=10,yuandef=10,HP=100,money=0,maxHP=100;
long long wuqiatk=0,kuijiadef=0;
long long atk=yuanatk+wuqiatk,def=yuandef+kuijiadef;
bool dun=false;
bool kuijia=false;
bool huifu=false;
int liliang=0,wudi=0,xuebao=0; 
int bag=0;
int lv=0;
int exp_=0;
int xiaoguaiexp=0;
int daguaiexp=0;
int xiaoguailv=1;
int daguailv=1;
int shaguaishu=0;
string name; 

void init(){
	zhangjie=0;
	yuanatk=10,yuandef=10,HP=100,money=0,maxHP=100;
	wuqiatk=0,kuijiadef=0;
	atk=yuanatk+wuqiatk,def=yuandef+kuijiadef;
	dun=false;
	kuijia=false;
	huifu=false;
	liliang=0,wudi=0,xuebao=0; 
    bag=0;
    lv=0;
 	exp_=0;
	xiaoguaiexp=0;
	daguaiexp=0;
	xiaoguailv=1;
	daguailv=1;
	shaguaishu=0;
	name=" "; 
}
void zhangjieinit(){
	xiaoguaiexp=0;
	daguaiexp=0;
	xiaoguailv=1;
	daguailv=1;
}
int lvexp[10005]={0,   2,   3,   5 ,  7,   11,  13,  17,  19,  23,  
				  29,  31,  37,  41,  43,  47,  53,  59,  61,  67,
				  71,  73,  79,  83,  89,  97,  101, 103, 107, 109,
				  113, 127, 137, 139, 149, 151, 157, 163, 167, 173,
				  179, 181, 193, 197, 199, 211, 223, 227, 229, 233,
				  239, 241, 251, 257, 263, 269, 271, 277, 281, 283,
				  293, 307, 311, 313, 317, 331, 337, 347, 349, 353,
				  359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
				  421, 431, 433, 439, 443, 449, 457, 461, 463, 467,
				  479, 487, 491, 499, 503, 509, 521, 523, 541, 547,
				  557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
			   	  613, 617, 619, 631, 641, 643, 647, 653, 659, 661,
			      673, 677, 683, 691, 701, 709, 719, 727, 733, 739,
			      743, 751, 757, 761, 769, 773, 787, 797, 809, 811,
			      821, 823, 827, 829, 839, 853, 857, 859, 863, 877,
			      881, 883, 887, 907, 911, 919, 929, 937, 941, 947,2147483647};
void cls(){//清屏 
	system("cls");
	return;
}
void con(){//按任意键继续 
    system("pause");
    cls();
}
void kaishi(){
	cout<<"很久很久以前\n";
	cout<<"地球上生活着人类和怪物..."<>name; 
	cls();
	return;
}
void lvup(bool a){
	while(exp_>=lvexp[lv+1]){
		exp_-=lvexp[lv+1];
		lv+=1;
		yuanatk+=3*lv;
		yuandef+=3*lv;
		maxHP+=20;
		HP=maxHP; 
		if(a){
			cout<<"你升级了!!升级了!!升级!!哦哦哦!!!"<=lvexp[xiaoguailv]){
		xiaoguaiexp-=lvexp[xiaoguailv];
		xiaoguailv+=1;
	}
	return;
}
void dalvup(){
	if(daguaiexp>=lvexp[daguailv]){
		daguaiexp-=lvexp[daguailv];
		daguailv+=1;
	}
	return;
}
void shop(){//商店功能 
	char a;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_GREEN );
	cout<<"老板:小兄弟,你来这里购买?太好了!"<>a;
	cls();
	switch(a){
		case '1':
			if(money>=40){
				money-=40;
				wuqiatk=50;
				atk=yuanatk+wuqiatk;
				cout<<"谢谢惠顾!"<=800){
				money-=800;
				wuqiatk=800;
				atk=yuanatk+wuqiatk;
				cout<<"谢谢惠顾!"<=15000){
				money-=15000;
				wuqiatk=60000;
				atk=yuanatk+wuqiatk;
				cout<<"谢谢惠顾!"<=80){
					money-=80;
					kuijiadef+=40 ;
					cout<<"谢谢惠顾!"<=2000){
					money-=2000;
					kuijiadef+=300; 
					cout<<"谢谢惠顾!"<=1200){
				if(bag==8){
					cout<<"包满啦"<=700){
				if(bag==8){
					cout<<"包满啦"<=400){
				if(bag==8){
					cout<<"包满啦"<=5000){
					money-=5000;
					kuijiadef+=250; 
					cout<<"谢谢惠顾!"<=123456){
				money-=123456;
				atk=2147483647;
				cout<<"谢谢惠顾!"<>a;
	switch(a){
		case 1:
			cout<<"你感觉充满了力量!"<0&&guaiHP>0){
		if(b){
			b-=1;
			if(!b){
				atk_-=4000;
			}
		}
		cout<<"你碰到了"<>a;
		cls();
		switch(a){
			case 1:
				srand(time(0));
				if(rand()%max(2,(xiaoguailv-lv+2))==0){
					cout<<"你攻击了,但小怪躲开了"<maxHP)HP=maxHP;
		}
		con();
	}
	if(HP<=0)die();
	if(run)return;
	if(guaiHP<=0){
		cout<<"你胜利了!"<0&&guaiHP>0){
		if(b){
			b-=1;
			if(!b){
				atk_-=4000;
			}
		}
		cout<<"你碰到了"<>a;
		cls();
		switch(a){
			case 1:
				srand(time(0));
				if(rand()%max(2,(daguailv-lv+2))==0){
					cout<<"你攻击了,但大怪躲开了"<maxHP)HP=maxHP;
		}
		con();
	}
	if(HP<=0)die();
	if(run)return;
	if(guaiHP<=0){
		cout<<"你胜利了!"<0&&bossHP>0){
		if(def_){
			def_=false;
			bossatk+=def;
		}
		if(b){
			b-=1;
			if(!b){
				atk_-=4000;
			}
		}
		cout<<"你的回合!!!" <>a;
		cls();
		switch(a){
			case 1:
				srand(time(0));
				if(rand()%max(2,(35-lv+2))==0){
					cout<<"你攻击了,但boss躲开了"<maxHP)HP=maxHP;
		}
		con();
	}
	if(HP<=0)die();
	if(run)return;
	if(bossHP<=0){
		cout<<"你胜利了...但你并不开心"<0)p-=1;
				if(ch=='a')if(q>0)q-=1;
				if(ch=='s')if(p<2)p+=1; 
				if(ch=='d')if(q<2)q+=1;
    		}
		}
		cls();
		cout<<"提示:按w往上,按s往下,按a往左,d往右"<0&&bossHP>0){
		if(def_){
			def_=false;
			bossatk+=def;
		}
		if(b){
			b-=1;
			if(!b){
				atk_-=4000;
			}
		}
		cout<<"boss托雷!!!"<>a;
		cls();
		switch(a){
			case 1:
				srand(time(0));
				if(rand()%max(2,(50-lv+2))==0){
					cout<<"你攻击了,但boss躲开了"<maxHP)HP=maxHP;
		}
		con();
	}
	if(HP<=0)die();
	if(run)return;
	if(bossHP<=0){
		cout<<"我...输了!"<>a;
	switch(a){
		case 1:
			cout<<"盖房子需要20s,获得1~10@";
			Sleep(20000);
			cls();
			srand(time(0));
			b=(rand()%10==0?10:rand()%10);
			cout<<"你获得了"<>a;
	if(a=='y'){
		cout<<"正在重置存档,存档后请重进游戏...";
		init(); 
		write_file();
		Sleep(5000);
		cout<<"成功!";
		con(); 
		return; 
	} 
	else{
		cls();
		return;
	}
}
void gonggao(){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_GREEN );
	cout<<"火龙征程V1.0.2"<>a;
		switch(a){
			case 1:
				cls();
				xiaoguai();
				break;
			case 2:
				cls();
				daguai();
				break;
			case 3:
				cls();
				shop();
				break;
			case 4:
				cls();
				dagong();
				break;
			case 5:
				cls();
				zhuangtai();
				break; 
			case 6:
				cls();
				write_file();
				break;
			case 7:
				cls();
				chongzhicundang();
				break;
			case 8:
				cls();
				gonggao(); 
				break;
			default:
				cout<<"退退退!别乱点!"<>name;
	fin>>zhangjie;
	fin.close();
	if(zhangjie==0){
		init();
		juqing();
	}
	else{
		ifstream fin("存档.txt");
		fin>>name;
		fin>>zhangjie;
		fin>>money;
		fin>>exp_;
		fin>>lv;
		fin>>HP;
		fin>>yuanatk;
		fin>>wuqiatk;
		fin>>yuandef;
		fin>>kuijiadef;
		fin>>liliang;
		fin>>wudi;
		fin>>xuebao;
		fin>>dun;
		fin>>kuijia;
		fin>>huifu;
		fin>>bag;
		fin>>xiaoguaiexp;
		fin>>daguaiexp;
		fin>>xiaoguailv;
		fin>>daguailv;
		fin>>shaguaishu;
		fin>>maxHP;
		fin.close();
		mianban();
	}
}
int main(){
	system("title 火龙征战");
	read_file(); 
	juqing();
} 

记得指出bug

再见!

你可能感兴趣的:(c++,蓝桥杯,算法)