24年8月31号写了个游戏(211行,连这都这么多,累死了),代码如下:
#include<iostream>
#include<windows.h>
#include<string>
using namespace std;
int gongji[10]={50,61,72,83,94,105,116,127,138,149},glevel=0;
int fangyu[10]={55,60,65,70,75,80,85,90,95,100},flevel=0;
int fashang[10]={168,172,176,180,184,188,192,196,200,204},falevel=0;
int tntdun[10]={1,2,3,4,5,6,7,8,9,10},tlevel=0;
int chuizizhongliang[10]={10,20,30,40,50,60,70,80,90,100},clevel=0,money=100,xieliang=10000,guaixieliang;
string username="user";
/*更新点:
1.角色改名
2.复活
3.去加载
4.逃跑 
*/
int menu(){
	cout<<"1、升级攻击"<<endl;
	cout<<"2、升级防御"<<endl;
	cout<<"3、升级法伤"<<endl;
	cout<<"4、升级TNT吨数"<<endl;
	cout<<"5、升级锤子重量"<<endl;
	cout<<"6、打小怪"<<endl;
	cout<<"7、打大怪"<<endl; 
	cout<<"8、查看属性"<<endl;
	cout<<"9、加血"<<endl; 
	cout<<"10、改名"<<endl;
	int tt;
	cin>>tt;
	return tt;
}
void upgongji(){
	cout<<"1、升级攻击"<<endl;
	cout<<"2、退出"<<endl;
	int tt;
	cin>>tt;
	if(glevel==9){
		cout<<"已满级"<<endl;
	}else if(money<gongji[glevel]){
		cout<<"你的钱不够"<<endl;
	}else if(tt!=2){
		cout<<"升级完毕"<<endl;
		money-=gongji[glevel];
		glevel++;
		cout<<"已升级到"<<glevel+1<<"级"<<endl;
	}
}
void upfangyu(){
	cout<<"1、升级防御"<<endl;
	cout<<"2、退出"<<endl;
	int tt;
	cin>>tt;
	if(flevel==9){
		cout<<"已满级"<<endl;
	}else if(money<fangyu[flevel]){
		cout<<"你的钱不够"<<endl; 
	}else if(tt!=2){
		cout<<"升级完毕"<<endl;
		money-=fangyu[flevel];
		flevel++;
		cout<<"已升级到"<<flevel+1<<"级"<<endl;
	}
}
void upfashang(){
	cout<<"1、升级法伤"<<endl;
	cout<<"2、退出"<<endl;
	int tt;
	cin>>tt;
	if(tt==9){
		cout<<"已满级"<<endl;
	}else if(money<fangyu[flevel]){
		cout<<"你的钱不够"<<endl; 
	}else if(tt!=2){
		cout<<"升级完毕"<<endl;
		money-=fashang[falevel];
		flevel++;
		cout<<"已升级到"<<falevel+1<<"级"<<endl;
	}
}
void uptntdun(){
	cout<<"1、升级TNT吨数"<<endl;
	cout<<"2、退出"<<endl;
	int tt;
	cin>>tt;
	if(tlevel==9){
		cout<<"已满级"<<endl;
	}else if(money<tntdun[tlevel]){
		cout<<"你的钱不够"<<endl; 
	}else if(tt!=2){
		cout<<"升级完毕"<<endl;
		money-=tntdun[tlevel];
		tlevel++;
		cout<<"已升级到"<<tlevel+1<<"级"<<endl;
	}
}
void upchuizizhongliang(){
	cout<<"1、升级锤子重量"<<endl;
	cout<<"2、退出"<<endl;
	int tt;
	cin>>tt;
	if(clevel==9){
		cout<<"已满级"<<endl;
	}else if(money<chuizizhongliang[clevel]){
		cout<<"你的钱不够"<<endl; 
	}else if(tt!=2){
		cout<<"升级完毕"<<endl;
		money-=chuizizhongliang[clevel];
		clevel++;
		cout<<"已升级到"<<clevel+1<<"级"<<endl;
	}
}
int pk(){
	while(xieliang!=0){
		cout<<"1、攻击"<<endl<<"2、防御"<<endl<<"3、法术"<<endl<<"4、TNT"<<endl<<"5、锤"<<endl<<"6、复活"<<endl<<"7、逃跑";
		int tt;
		cin>>tt;
		system("cls");
		if(tt==1){
			guaixieliang-=gongji[glevel];
			xieliang-=100;
		}else if(tt==2){
			xieliang-=100-fangyu[flevel]; 
		}else if(tt==3){
			guaixieliang-=fashang[falevel];
	        xieliang-=100;
		}else if(tt==4){
			guaixieliang-=100*tntdun[tlevel];
			xieliang-=tntdun[tlevel];
		}else if(tt==5){
			guaixieliang-=10*chuizizhongliang[clevel];
			xieliang-=100;
		}else if(tt==6){
			xieliang+=10;
		}else if(tt==7){
			return 2;
		}
		cout<<"你还有"<<xieliang<<"滴血,怪物还有"<<guaixieliang<<"滴血"<<endl;
		if(guaixieliang<=0){
			cout<<"你赢了!"<<endl;
			return 0;
		} 
	} 
	cout<<"你死了!"<<endl;
	return 1; 
}
void buxie(){
	if(money>=100){
		cout<<"已加满"<<endl;
		money-=100;
		xieliang=10000;
	}else{
		cout<<"你的钱不够"<<endl;
	}
}
void gaiming(){
	string newusername;
	cin>>newusername;
	system("cls");
	if(newusername.size()>10){
		cout<<"名字过长,最长10个字符"<<endl;
	}else if(newusername.size()<4){
		cout<<"名字过短,最短4个字符"<<endl;
	}else if(newusername.find("{}")!=-1||newusername.find("[]")!=-1||newusername.find("()")!=-1||newusername.find("include")!=-1||newusername.find("<>")!=-1){
		cout<<"名字包含特殊字符{}[]()include<>"<<endl;
	}else{
		username=newusername;
	}
}
int main(){
	while(xieliang!=0){
		int tt=menu();
		system("cls");
		if(tt==1){
			upgongji();
		}else if(tt==2){
			upfangyu();
		}else if(tt==3){
			upfashang();
		}else if(tt==4){
			uptntdun();
		}else if(tt==5){
			upchuizizhongliang();
		}else if(tt==6){
			guaixieliang=10000;
			if(pk()==1){
				return 0;
			}else{
				money+=100;
			}
		}else if(tt==7){
			guaixieliang=100000;
			if(pk()==1){
				return 0;
			}else{
				money+=1000;
			}
		}else if(tt==8){
			cout<<"攻击"<<gongji[glevel]<<endl;
			cout<<"防御"<<fangyu[flevel]<<endl;
			cout<<"法伤"<<fashang[falevel]<<endl;
			cout<<"TNT吨数"<<tntdun[tlevel]<<endl;
			cout<<"锤子重量"<<chuizizhongliang[clevel]<<endl;
			cout<<"血量"<<xieliang<<endl;
			cout<<"钱"<<money<<endl; 
		}else if(tt==9){
			buxie();
		}else if(tt==10){
			gaiming();
		}
	}

}

各位可以弄来玩玩,1.2版本,敬请期待1.3!

本站作者已申明原创,禁止转载!

文章内容属作者个人观点,不代表本站立场,如有侵权立删。

   口袋儿题库-青少儿编程自测题库