异世界1 优化

#include<bits/stdc++.h>
#include<conio.h>
typedef long long ll;
using namespace std;
const int maxn = 1e6 + 7;
struct person {
	string name;
	ll maxhealth;
	ll health;
	ll fight;
	ll qian;
	ll shoulei;
	ll yzd;
};
struct guai {
	ll maxhealth;
	ll health;
	ll fight;
};
//小怪:{222,222,50}
//中等怪:{444,444,70}
//大怪:{666,666,90}
//Boss:{1000,1000,111}
person wo = {"", 130, 130, 30, 0, 0, 0};
void play(person g1, guai g, string name, int money) {
	system("cls");
	person me = g1;
	guai zomb = g;
	int z = 5;
	while (1) {
		if (me.health <= 0 && zomb.health <= 0) {
			cout << "游戏结束!!!" << endl;
			cout << "你和" << name << "同归于尽了!" << endl;
			exit(0);
		}
		if (me.health <= 0) {
			cout << "游戏结束!!!" << endl;
			cout << "你被 " << name << "杀死了!" << endl;
			exit(0);
		}
		if (zomb.health <= 0) {
			cout << "你胜利了!!!" << endl;
			cout << name << "死了!" << endl;
			cout << "你获得了" << money << "个金币!!!" << endl;
			wo.qian += money;
			return ;
		}
		cout << "你的血量为:" << me.health << "/" << me.maxhealth << endl;
		cout << name << "的血量为:" << zomb.health << "/" << zomb.maxhealth << endl;
		cout << "你的技能: 1.打拳(攻击) 2.圣剑斩(攻击,伤害+5) 3.硫酸拳(1.5倍攻击,虚弱5) 4.自我再生(回复80hp) 5.手雷(伤害为200) 6.超级无敌大炸弹(秒杀)" << endl;
		char j;
		j=getch();
		if (j == '1') {
			cout << "你 使用了  打拳  !!!" << endl;
			zomb.health -= me.fight + 10;
		} else if (j == '2') {
			cout << "你 使用了  圣剑斩  !!!" << endl;
			zomb.health -= me.fight;
			me.fight += 5;
		} else if (j == '3') {
			cout << "你 使用了  硫酸拳  !!!" << endl;
			zomb.health -= me.fight * 1.5;
			cout << name << " 虚弱了!!!" << endl;
			zomb.fight -= 4;
		} else if (j == '4') {
			if (z > 0) {
				cout << "你 使用了  自我再生  !!!" << endl;
				me.health += 80;
				z--;
			} else {
				cout << "  自我再生  技能  使用失败,自动使用  打拳  !!!" << endl;
				zomb.health -= me.fight + 10;
			}
		} else if (j == '5') {
			if (wo.shoulei > 0) {
				cout << "你 使用了  手雷  ,消耗一个  手雷  !!!" << endl;
				wo.shoulei--;
				zomb.health -= 200;
			} else {
				cout << "你的手雷数量不够!!!" << endl;
				continue;
			}
		} else if (j == '6') {
			if (wo.yzd > 0) {
				cout << "你 使用了  超级无敌大炸弹  ,消耗一个  超级无敌大炸弹  !!!" << endl;
				wo.yzd--;
				zomb.health -= zomb.health;
			} else {
				cout << "你的超级无敌大炸弹数量不够!!!" << endl;
				continue;
			}
		}else{
			cout << "没有该技能,将自动使用  打拳!!!" << endl;
			zomb.health-=me.fight + 10;
		}
		cout << name << " 使用了  打击  !!!" << endl;
		me.health -= zomb.fight;
		zomb.health += 5;
		if (me.health > me.maxhealth) {
			me.health = me.maxhealth;
		}
		if (zomb.health > zomb.maxhealth) {
			zomb.health = zomb.maxhealth;
		}
	}
}
void xunlian() {
	system("cls");
	cout << "你要训练什么方面: 1.防御(50元) 2.攻击(75元) 0.离开" << endl;
	char x;
	x=getch();
	if (x == '1') {
		if (wo.qian >= 50) {
			wo.qian -= 50;
			wo.maxhealth += 20;
			wo.health += 20;
			cout << "训练成功!!  你的血量上升20!!!" << endl;
		} else {
			cout << "训练失败!! 你的钱还不够!!!" << endl;
		}
	} else if(x=='2'){
		if (wo.qian >= 75) {
			wo.qian -= 75;
			wo.fight += 20;
			cout << "训练成功!!  你的攻击力上升20!!!" << endl;
		} else {
			cout << "训练失败!! 你的钱还不够!!!" << endl;
		}
	}else cout << "这玩意儿不能练,滚滚滚!\n";
}
void shop() {
	system("cls");
	cout << "你要买什么: 1.手雷(150元) 2.超级无敌大炸弹(300元) 3.穿梭者1号(50000元) 0.离开" << endl;
	char op;
	op=getch();
	if (op == '1') {
		if (wo.qian >= 150) {
			wo.qian -= 150;
			wo.shoulei++;
		} else {
			cout << "购买失败,你太穷了!!!" << endl;
		}
	} else if (op == '2') {
		if (wo.qian >= 300) {
			wo.qian -= 300;
			wo.yzd++;
		} else {
			cout << "购买失败,你太穷了!!!" << endl;
		}
	} else if (op == '3') {
		if (wo.qian >= 50000) {
			cout << "你买到了“穿梭者一号”,回到了自己的家,但真的就结束了吗……" << endl;
			exit(0);
		} else {
			cout << "购买失败,你太穷了!!!" << endl;
		}
	} else {
		cout << "没这玩意儿,滚滚滚!\n";
	}
}
int compute(int hp,int att){
	return (int)sqrt(hp*hp+att*att);
}
void ask(){
	system("cls");
	cout << "你的血量为:" << wo.health << "/" << wo.maxhealth << endl;
	cout << "你的攻击力为:" << wo.fight << endl;
	cout << "你有" << wo.qian << "个金币" << endl;
	cout << "你有" << wo.shoulei << "个手雷" << endl;
	cout << "你有" << wo.yzd << "个超级无敌大炸弹" << endl;
	cout << "要干啥: 1.训练 2.冒险 3.商店" << endl;
	char num;
	num=getch();
	if (num == '1') {
		xunlian();
	} else if (num == '2') {
		system("cls");
		cout << "要挑战啥: 1.僵尸 2.石人 3.坦克尸 4.钢铁巨人 5.#!!?#@#" << endl;
		cout << "僵尸:     Hp:222  Att:50" << endl;
		cout << "石人:     Hp:444  Att:70" << endl;
		cout << "坦克尸:   Hp:666  Att:90" << endl;
		cout << "钢铁巨人: Hp:1000 Att:111"<< endl;
		cout << "#!!?#@#:  Hp:??? Att:???\n";
		cout << "提示: 怪物每攻击你一次就会回复5Hp." << endl;
		char f;
		f=getch();
		//小怪:{222,222,50}
		//中等怪:{444,444,70}
		//大怪:{666,666,90}
		//Boss:{1000,1000,111}
		if (f == '1') {
			play(wo, {222, 222, 50}, "僵尸", 300);
		} else if (f == '2') {
			play(wo, {444, 444, 70}, "石人", 550);
		} else if (f == '3') {
			play(wo, {666, 666, 90}, "坦克尸", 800);
		} else if (f == '4') {
			play(wo, {1000, 1000, 200}, "钢铁巨人", 1000);
		} else if (f == '5'){
			int x=rand()%10000+1,y=rand()%10000+1;
			play(wo,{x,x,y},"#!!?#@#",compute(x,y));
		} else {
			cout << "没有该怪物,将自动离开。" << endl;
		}
	} else if (num == '3') {
		shop();
	} else {
		cout << "该地点不存在!!!" << endl;
	}
}
void First();
int main() {
	srand(time(0));
	First();//开场白
	cin >> wo.name;
	while (1) {
		ask();//询问操作
	}
	return 0;
}
void First(){
	cout << "--------------------欢迎来到  “异世界1”  测试版--------------------\n\n\n\n\n\n";
	cout << "你是一个不小心穿越到异世界的旅者,在这个世界有一个战斗岛,你可以在里面和怪物战斗,领取赏金;还有一个训练场,你可以训练你的抗击打力和攻击力;最后还有一个商店,那里会售卖强力的武器和你梦寐以求的穿越器“穿梭者1号”。\n";
	cout << "你做出了一个重大的决定:获得穿越器,离开这里!!!\n";
	cout << "你的名字是:" << endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值