卡牌游戏源代码(原创)(控制台)

零零水 2016-02-14

游戏预览:




完成度90%,约3000行,过年这几天全用在这上面了

由于尚未学到QT等,因此只能在黑窗口下面制作了


未完成的部分:

①战斗代码未优化(800行,精简后应该能降到200行左右)

②关卡掉落预留位置了,但是没有加入(加入掉落很简单)

③可以通过程序来手动添加关卡,但未加入这个功能。

④大概这样吧。


完成的部分:

①支持卡牌查询,卡牌仓库查询,装备仓库查询。

②通关,选择地图,然后从地图选择关卡。支持我方5人和地方6人的战斗模式,有简单的战斗描述(但没有动画),每回合更新一次战斗实况(可以通过修改源代码来变更为每次行动,但感觉这种情况不是很完美),通关可以获得经验,金钱等奖励

③购买卡牌,装备(分金币和钻石,钻石可以购买的东西更多)

④抽奖

⑤卡牌和装备的整理

⑥存档、读档,建立新人物

⑦给卡牌装备新装备,卸除装备,更换装备,将仓库中的卡牌装备到出站中,将出战的卡牌放到仓库中。


游戏资源:

依靠txt格式。

card:卡牌资源,dltr:某地图,dltr1:地图的某关卡(包含剧情和怪物),dunpai(等):装备属性,maplist:地图列表(指向各地图,如dltr.txt),player:玩家存档格式说明,wd:玩家存档名

扩展性个人觉得还可以,只需要修改这些资源文件即可。

①可添加新地图,新关卡,新剧情,新怪物;

②可添加新装备,新卡牌

以下是资源文件:

http://download.csdn.net/detail/qq20004604/9431348





//卡牌
//卡牌.h
#pragma once
#include<string>
#include<iostream>

using std::string;
void check(char&ch);
struct combat	//结构,战斗用,因为不考虑技能,所以用结构挺简单的,如果考虑技能的话,有点麻烦,目前想法是,做一个技能类,内置多种技能,然后根据输入参数来返回一个伤害值
{
	string name = " ";	//名字
	int hp = 0;		//生命
	int atk = 0;	//攻击
	int def = 0;	//防御
	int lv = 0;
};

class Equip
{
	string name;	//装备名
	int id;			//装备id
	int quality;	//装备品质,1白2绿3蓝4紫5橙6史诗
	int lv;		//装备级别
	int atk;	//装备带来的攻击
	int def;	//装备带来的防御
	int hp;		//装备带来的生命值
	int side;	//装备位置
public:
	Equip() { name = "", id = lv = atk = def = hp = quality = side = 0; }
	void set(int i, int l);	//根据ID和级别初始化装备
	bool buyEq(int i);	//根据ID购买装备
	int getATK() { return atk*lv*lv; }	//返回攻击力
	int getDEF() { return def*lv*lv; }	//返回防御力
	int getHP() { return hp*lv*lv; }
	int getside() { return side; }
	int getLv() { return lv; }
	int getQu() { return quality; }
	string getNANME() { return name; }
	void setSide(int s) { side = s; }	//设置装备位置,移除卡牌的装备时使用
	bool show();	//显示装备属性
	int getLvLimit();	//装备级别限制
	void operator=(int i) { side = i + 1; }
	friend std::ostream& operator<<(std::ostream& os, const Equip& eq);
	friend std::istream& operator>>(std::istream& is, Equip& eq);
	bool isHere();	//装备是否存在
};


class Card	//卡牌类
{
	string name;	//卡牌名
	int id;
	int quality;	//品质,1白2绿3蓝4紫5橙6神话
	int lv;			//级别
	double base_atk;	//基础攻击系数
	double base_def;	//基础防御系数
	double base_hp;		//基础生命值系数
	long exp;		//经验值
	int atk;		//攻击力(实际的,不算入装备加成等)
	int def;		//防御力(实际的,不算入装备加成等)
	int hp;			//生命值(实际的,不算入装备加成等)
	void setATK() { atk = int(sqrt(lv*lv*lv)*sqrt(base_atk)*(quality*quality)); }	//=等级三次方再开方 乘以 基础攻击系数的开方 乘以 品质的平方
	void setDEF() { def = int(lv*sqrt(base_def)*quality*quality); }	//=等级 乘以 基础防御系数的开方 乘以 品质的平方
	void setHP() { hp = int(base_hp*quality*quality*sqrt(lv*lv*lv)); }		//=生命值系数*品质的平方*等级三次方的开方
	Equip eq[6];	//0头盔,1盔甲,2手套,3武器,4盾牌,5戒指
public:
	Card();
	Card(const Card& ca);		//复制构造函数
	void addCard(int i);	//新建一张卡牌,先声明,然后初始化,抽卡时使用
	bool buyCard(int i);	//新建一张卡牌,用于购买指定卡牌时使用
	bool show();	//显示卡牌所有属性
	bool isHere();	//卡牌存在返回true,否则false
	bool addEquip(Equip& eq);	//装备装备
	int getATK();	//得到最终攻击力,计算装备加成
	int getDEF();	//得到最终防御力,计算装备加成
	int getHP();	//得到最终生命值,计算装备加成
	int getLV() { return lv; }	//得到级别
	int getQU() { return quality; }	//得到品质
	const string& getName() { return name; }
	string getPinZhi();		//得到品质,中文版
	void setLV();	//级别更新
	void addEXP(int ex);	//经验更新
	int GiveEXP();	//打败后给予的经验值
	bool isEquipHere(int num);	//检查卡牌某件装备是否存在
	Equip& lookforEQ(int s);	//根据参数,返回某位置装备的引用,用于修改该位置装备
	void setSide();		//重置卡牌的各个装备的位置,移除装备时使用
	friend std::ostream& operator<<(std::ostream& os, const Card& ca);
	friend std::istream& operator>>(std::istream& is, Card& ca);
};



class Player	//玩家
{
	string name;	//玩家名
	Card card[5];	//主力卡牌五张
	Card caBank[40];	//后备卡牌40张,由于不会数据库,因此这里使用的是数组
	int gold;	//金币
	int diamond;	//钻石
	int lv;		//玩家战斗次数
	int stars;	//星星(拆解卡牌后获得)
	Equip eqBank[40];	//存放装备的仓库
	int MAP = 11;	//地图进度,个位数表示关卡,除以10表示地图
public:
	Player();	//默认构造函数
	int getGold()const { return gold; }
	int getDiamond()const { return diamond; }
	int getLv()const { return lv; }
	int getStars()const { return stars; }
	int getMAP()const { return MAP; }	//返回地图进度
	string& getName() { return name; }
	void addMAP(int m) { MAP = m; }	//将新的进度赋值给MAP(如果之后没地图了,赋值和上一个关卡维持一致即可)
	void addGold(int g) { gold += g; }	//增加金钱
	void addDiamond(int d) { diamond += d; }	//增加钻石
	void addLv() { lv += 1; }	//战斗次数+1
	void addStars(int s) { stars += s; }	//增加拆解碎片
	void save()const;	//存档
	void load(std::istream& is, const string&na);	//读档
	void operator=(const string& na);	//创建新人物时使用
	void show(int num = 0);		//显示详细信息函数,默认0为全部显示,1为显示装备中的卡牌,2为显示仓库中的卡牌,3为显示仓库中的装备
	void goodLuck();	//抽奖
	bool isCaBankFull();	//返回仓库中卡牌是否满了
	bool isEqBankFull();	//返回仓库中装备是否满了
	Card& lookfor();	//返回仓库中遇见的第一个空位置的卡牌,注意,需要用isCaBankFull()函数检测不满的时候才能使用
	Equip& lookforEquip();	//返回第一个没装备的位置
	void caBankLvHtoL();	//整理仓库中的卡牌,把级别高的放前面
	void caBankQuHtoL();	//整理仓库中的卡牌,把品质好的放前面
	void eqBankHtoL();		//整理仓库中的装备,首先按头盔、盔甲、手套、武器、盾牌、戒指顺序摆放,其次品质高的放前面,再次同一品质级别高的放前面
	void easyCardShow(int num);		//简单显示,参数1显示装备卡牌,参数2显示仓库中卡牌
	void CardMove(int f,int l,int num);		//交换卡牌,参数1和参数2为交换的2个卡牌的位置,参数3值为1时为装备卡牌,值为2时为将仓库卡牌和身上卡牌交换,值为3时,为将身上的卡牌卸除
	bool isCardEquipHere(int ca, int eq, int num);	//检查某件卡牌的某件装备是否存在,参数1是卡牌位置,参数2是装备位置,参数3值1为装备中卡牌,值2为仓库中卡牌
	bool isCardHere(int i,int num);		//检查某个卡牌是否存在,参数1为卡牌卡牌,参数2为装备中(值1)或仓库中(值2)
	int getHowMuchEquip();		//返回仓库中的装备总数
	bool CardEquipChange(int ca, int e, int num);	//更换某张卡牌的装备,参数1为卡牌位置,参数2为装备位置,参数3为装备中的卡牌(值1)或仓库中的(值2)
	bool CardEquipRemove(int ca, int e, int num);	//卸除某卡牌的装备,参数1为卡牌位置,参数2为装备位置,参数3为装备中的卡牌(值1)或仓库中的(值2)
	Card getCardforCombat(int i) { return card[i]; }	//返回装备中的卡牌,用于战斗函数适应
	void winner(int num);		//给装备中的卡牌加经验
};









//类方法
//卡牌.cpp
#include<iostream>
#include<sstream>
#include<fstream>
#include<ctime>
#include<windows.h> //用于使用延迟函数,具体为Sleep(毫秒),S为大写;
#include <cstdlib>
#include"卡牌.h"
void check(char&ch);
//Player类
Player::Player()
{
	name = "";
	gold = diamond = lv = stars = 0;
}
void Player::save()const	//存档时使用
{
	using namespace std;
	ofstream save;
	save.open(name);
	save << lv << endl << gold << endl << diamond << endl << stars << endl << MAP << endl;
	for (int i = 0;i < 5;i++)	//存装备中的卡牌
		save << card[i];
	for (int i = 0;i < 40;i++)	//存仓库中的卡牌
		save << caBank[i];
	for (int i = 0;i < 40;i++)	//存仓库中的装备
		save << eqBank[i];
	save.close();
}
void Player::load(std::istream& is,const string&na)	//读档
{
	using namespace std;
	name = na;
	is >> lv;
	is >> gold;
	is >> diamond;
	is >> stars;
	is >> MAP;
	for (int i = 0;i < 5;i++)//读取装备中的卡牌
		is >> card[i];			
	for (int i = 0;i < 40;i++)	//读取仓库的卡牌
		is >> caBank[i];
	for (int i = 0;i < 40;i++)	//读取仓库的装备
		is >> eqBank[i];
}
void Player::show(int num)	//显示详细信息函数,默认0为全部显示,1为显示装备中的卡牌,2为显示仓库中的卡牌,3为显示仓库中的装备
{
	using namespace std;
	//显示出战卡牌
	if (num == 0 || num == 1)
	{
		cout << "******装备中的卡牌******" << endl;
		if (num == 0)system("pause");
		for (int i = 0;i < 5;i++)
		{
			cout << "第 " << i + 1 << " 张卡牌:" << endl;
			if (!card[i].show())
				cout << "无" << endl;
			system("pause");
		}
		cout << endl;
	}

	//显示仓库中的卡牌
	if (num == 0 || num == 2)
	{
		cout << "******仓库中的卡牌******" << endl;
		if (num == 0)system("pause");
		for (int i = 0, j = 1;i < 40;i++)
		{
			if (caBank[i].isHere())
			{
				cout << "第 " << j << " 张卡牌:" << endl;
				j++;
				caBank[i].show();
				system("pause");
			}
			if (j == 1 && i == 39)
				cout << "无任何卡牌" << endl;
		}
	}
	//显示仓库中的装备
	if (num == 0 || num == 3)
	{
		cout << "******仓库中的装备******" << endl;
		system("pause");
		for (int i = 0, j = 1;i < 40;i++)
		{
			if (eqBank[i].isHere())
			{
				cout << "装备" << j << ":" << endl;
				j++;
				eqBank[i].show();
			}
			if (j == 1 && i == 39)
				cout << "仓库中没有任何装备" << endl;
		}
	}
	cout << endl;
	cout << "显示结束.....";
	system("pause");
}
void Player::operator=(const string& na)	//新建人物,na为新人物的姓名
{
	using namespace std;
	name = na;
	gold = diamond = stars = lv = 0;
	cout << "由于是新建人物,因此获得一次抽取卡牌的机会" << endl;
	card[0].addCard(3);		//3为品质蓝色
}
bool Player::isCaBankFull()		//返回仓库中卡牌是否满了
{
	for (int i = 0;i < 40;i++)
	{
		if (!caBank[i].isHere())	//如果当前位置没卡牌,返回false(说明没满)
			return false;
	}
	return true;	//否则满了
}
Card& Player::lookfor()//返回仓库中遇见的第一个空位置的卡牌
{
	for (int i = 0;i < 40;i++)
		if (!caBank[i].isHere())	//返回第一个遇到的位置为空的卡牌
			return caBank[i];
	//以下是错误检验代码
	Card temp;
	std::cout << "仓库为满,无法返回仓库中的卡牌。返回一个临时创造的卡牌作为替代" << std::endl;
	system("pause");
	return temp;
}
void Player::caBankLvHtoL()	//整理仓库中的卡牌,把级别的放前面(实质上是冒泡算法)
{
	for (int i = 0;i < 40;i++)
		for (int j = 0;j < 39;j++)
		{
			if (caBank[j].getLV() < caBank[j + 1].getLV())	//如果前面的卡牌级别比后面的低,交换位置
			{
				Card temp;
				temp = caBank[j + 1];
				caBank[j + 1] = caBank[j];
				caBank[j] = temp;
			}
		}
}
void Player::caBankQuHtoL()	//整理仓库中的卡牌,把级别的放前面(实质上是冒泡算法)
{
	for (int i = 0;i < 40;i++)
		for (int j = 0;j < 39;j++)
		{
			if (caBank[j].getQU() < caBank[j + 1].getQU())	//如果前面的卡牌的品质比后面的低,交换位置
			{
				Card temp;
				temp = caBank[j + 1];
				caBank[j + 1] = caBank[j];
				caBank[j] = temp;
			}
		}
}
void Player::goodLuck()
{
	using namespace std;
	char ch = 0;
	while (ch != 'q')
	{
		cout << "********欢迎进入抽奖系统********" << endl;
		cout << "1.金币抽奖" << endl;
		cout << "2.钻石抽奖" << endl;
		cout << "q.退出" << endl;
		cout << "->";
		check(ch);		//输入错误检测代码
		if (ch == 'q')
		{
			cout << "为您已退出抽奖..." << endl;
			Sleep(1000);
		}
		else if (ch == '1')	//金币抽奖
		{
			srand((unsigned)time(0));
			cout << endl;
			cout << "******进入金币抽奖系统******" << endl;
			cout << "注意:金币抽取不能抽取到传说以上级别的卡牌" << endl;
			cout << "1.抽取一次(需要5000金币)" << endl;
			cout << "2.抽取十次(需要50000金币)" << endl;
			cout << "q.退出" << endl;
			cout << "->";
			char chh;
			check(chh);		//输入错误检测代码
			if (chh == '1')
			{
				if (gold < 5000)
				{
					cout << "金钱不足,你只有" << gold << "金币" << endl;
					system("pause");
				}
				else
				{
					if (isCaBankFull())
					{
						cout << "你的仓库中卡牌满了,不能抽奖。" << endl;
						system("pause");
					}
					else
					{
						gold -= 5000;
						Card &temp = lookfor();	//引用指向仓库中空卡牌的位置
						int te = rand() % 1000;
						if (te < 50)te = 4;	//5%史诗
						else if (te < 200)te = 3;	//15%精良
						else if (te < 600)te = 2;	//40%绿色
						else te = 1;	//40%白色
						temp.addCard(te);
						save();	//存档
						system("pause");
					}
				}
			}
			else if (chh == '2')
			{
				if (gold < 50000)
				{
					cout << "金钱不足,你只有" << gold << "金币" << endl;
					system("pause");
				}
				else
				{
					int te;
					for (int i = 0;i < 10;i++)
					{
						if (isCaBankFull())
						{
							cout << "你的仓库中卡牌满了,不能继续抽奖,多余的金钱已退回。" << endl;
							system("pause");
							break;
						}
						else
						{
							gold -= 5000;
							Card &temp = lookfor();	//引用指向仓库中空卡牌的位置
							te = rand() % 1000;
							if (te < 50)te = 4;
							else if (te < 200)te = 3;
							else if (te < 600)te = 2;
							else te = 1;
							cout << "第" << i + 1 << "次抽奖:";
							temp.addCard(te);
							save();	//存档
							system("pause");
						}
					}
				}
			}
		}
		else if (ch == '2')	//钻石抽奖
		{
			srand((unsigned)time(0));
			cout << endl;
			cout << "******进入钻石抽奖系统******" << endl;
			cout << "钻石抽奖有极低概率抽到【神话】卡牌" << endl;
			cout << "1.抽取一次(需要500钻石)" << endl;
			cout << "2.抽取十次(需要5000钻石,附赠一次)" << endl;
			cout << "q.退出" << endl;
			cout << "注意:请留足够的背包空间,若背包空间不足十一个,将无法享受附赠的抽奖次数" << endl;
			cout << "->";
			char chh;
			check(chh);		//输入错误检测代码
			if (chh == '1')
			{
				if (diamond < 500)
				{
					cout << "钻石不足,你只有" << diamond << "钻石" << endl;
					system("pause");
				}
				else
				{
					if (isCaBankFull())
					{
						cout << "你的仓库中卡牌满了,不能抽奖。" << endl;
						system("pause");
					}
					else
					{
						diamond -= 500;
						Card &temp = lookfor();	//引用指向仓库中空卡牌的位置
						temp.addCard(0);
						save();	//存档
						system("pause");
					}
				}
			}
			else if (chh == '2')
			{
				if (gold < 5000)
				{
					cout << "钻石不足,你只有" << diamond << "钻石" << endl;
					system("pause");
				}
				else
				{
					for (int i = 0;i < 11;i++)
					{
						if (isCaBankFull())
						{
							cout << "你的仓库中卡牌满了,不能继续抽奖,多余的钻石已退回。" << endl;
							system("pause");
							break;
						}
						else
						{
							if (i < 10)diamond -= 500;
							Card &temp = lookfor();	//引用指向仓库中空卡牌的位置
							cout << "第" << i + 1 << "次抽奖:";
							temp.addCard(0);
							save();	//存档
							system("pause");
						}
					}
				}
			}

		}
		save();	//存档
	}
}
bool Player::isEqBankFull()		//返回仓库中装备是否满了
{
	for (int i = 0;i < 40;i++)
		if (!eqBank[i].isHere())	//如果当前位置没装备,说明没满
			return false;
	return true;
}
Equip& Player::lookforEquip()	//返回仓库中第一个没装备的位置
{
	for (int i = 0;i < 40;i++)
		if (!eqBank[i].isHere())
			return eqBank[i];
	Equip temp;
	std::cout << "仓库中装备是满的,因此发生错误,请向技术人员反馈该情况是怎么发生的" << std::endl;
	return temp;
}
void Player::eqBankHtoL()	//整理仓库中的装备,首先按头盔、盔甲、手套、武器、盾牌、戒指顺序摆放,其次品质高的放前面,再次同一品质级别高的放前面
{
	for (int i = 0;i < 39;i++)
		for (int j = 0;j < 39;j++)
		{
			if (eqBank[j].getLv() < eqBank[j + 1].getLv())	//如果前面比后面级别低,交换之
			{
				Equip temp;
				temp = eqBank[j + 1];
				eqBank[j + 1] = eqBank[j];
				eqBank[j] = temp;
			}
		}
	for (int i = 0;i < 39;i++)
		for (int j = 0;j < 39;j++)
		{
			if (eqBank[j].getQu() < eqBank[j + 1].getQu())	//前面质量差,交换之
			{
				Equip temp;
				temp = eqBank[j + 1];
				eqBank[j + 1] = eqBank[j];
				eqBank[j] = temp;
			}
		}
	for (int i = 0;i < 39;i++)
		for (int j = 0;j < 39;j++)
		{
			if (eqBank[j].getside() > eqBank[j + 1].getside()&&eqBank[j+1].getside()!=0)	//前面顺序标号更高,交换之
			{
				Equip temp;
				temp = eqBank[j + 1];
				eqBank[j + 1] = eqBank[j];
				eqBank[j] = temp;
			}
		}


}
void Player::easyCardShow(int num)	//参数1显示装备中的卡牌,参数2显示仓库中的卡牌
{
	using namespace std;
	if (num == 1)
	{
		for (int i = 0, j = 1;i < 5;i++, j++)
		{
			cout << "第" << j << "张卡牌:" << endl;
			if (!card[i].isHere())cout << "空" << endl;
			else
			{
				cout << "名字:" << card[i].getName() << ",品质:" << card[i].getPinZhi()
					<< ",等级:" << card[i].getLV() << ",生命" << card[i].getHP()
					<< ",攻击" << card[i].getATK() << ",防御" << card[i].getDEF() << endl;
			}
		}
	}
	else if (num == 2)
	{
		for (int i = 0, j = 1;i < 40;i++, j++)
		{
			cout << "第" << j << "张卡牌:";
			if (!caBank[i].isHere())cout << "空" << endl;
			else
			{
				cout << endl;
				cout << "名字:" << caBank[i].getName() << ",品质:" << caBank[i].getPinZhi()
					<< ",等级:" << caBank[i].getLV() << ",生命" << caBank[i].getHP()
					<< ",攻击" << caBank[i].getATK() << ",防御" << caBank[i].getDEF() << endl;
			}
		}
	}
}
void Player::CardMove(int f, int l, int num)//解除装备卡牌时,需要在使用该函数之前,先检测仓库是否为空
{
	using namespace std;
	Card temp;
	f--, l--;
	if (num == 1)	//交换装备卡牌
	{
		temp = card[f];
		card[f] = card[l];
		card[l] = temp;
	}
	else if (num == 2)	//交换装备和仓库卡牌,f为装备卡牌,l为仓库卡牌
	{
		temp = card[f];
		card[f] = caBank[l];
		caBank[l] = temp;
	}
	else if (num == 3)	//解除装备卡牌
	{
		if (!isCaBankFull())
		{
			Card& temp_2 = lookfor();	//temp_2指向空卡牌的位置
			temp = temp_2;
			temp_2 = card[f];
			card[f] = temp;
		}
		else
		{
			cout << "仓库满,无法交换" << endl;
		}
	}
	else
	{
		cout << "出现错误,请反馈,错误代码s-005" << endl;
	}
}
bool Player::CardEquipChange(int ca, int e, int num)//更换某张卡牌的装备,参数1为卡牌位置,参数2为装备位置,参数3为装备中的卡牌(值1)或仓库中的(值2)
{
	ca--;//因为数组,所以参数-1为实际位置序号
	int i, p = 0;
	for (i = 0;i < 40;i++)	//找打第e件装备(需要排除空位置)
	{
		if (eqBank[i].isHere())	//如果该位置有装备,计数器p+1
			p++;
		if (p == e)break;	//当计数器和参数e相等时,说明该装备为玩家要装备的那件,那件装备为eqBank[i]
	}

	if (num == 1)
		return card[ca].addEquip(eqBank[i]);
	else if (num == 2)
		return caBank[ca].addEquip(eqBank[i]);
	else
	{
		std::cout << "发生了不知名的错误,请反应给技术人员,错误代码s-008" << std::endl;
		return false;
	}

}
int Player::getHowMuchEquip()	//返回仓库中的装备总数
{
	int num = 0;
	for (int i = 0;i < 40;i++)
		if (eqBank[i].isHere())
			num++;
	return num;
}
bool Player::isCardHere(int i, int num)	//检查某个卡牌是否存在,参数1为卡牌卡牌,参数2为装备中(值1)或仓库中(值2)
{
	i--;
	if (num == 1)
		return card[i].isHere();
	else if (num == 2)
		return caBank[i].isHere();
	else
	{
		std::cout << "出现某种错误,请反馈给技术人员,错误代码s-007" << std::endl;
		return false;
	}
}
bool Player::isCardEquipHere(int ca, int eq, int num)	//检查某件卡牌的某件装备是否存在,参数1是卡牌位置,参数2是装备位置,参数3值1为装备中卡牌,值2为仓库中卡牌
{
	ca--;		//因为数组,所以参数-1为实际位置序号
	eq--;
	if (num == 1)
	{
		return card[ca].isEquipHere(eq);	//返回装备中ca位置的卡牌的eq位置的装备是否存在

	}
	else if (num == 2)
	{
		return caBank[ca].isEquipHere(eq);		//返回仓库中ca位置的卡牌的eq位置的装备是否存在
	}
	else
	{
		std::cout << "出现某种错误,请反应给技术人员,错误代码s-007" << std::endl;
		return false;
	}
}
bool Player::CardEquipRemove(int ca, int e, int num)//卸除某卡牌的装备,参数1为卡牌位置,参数2为装备位置,参数3为装备中的卡牌(值1)或仓库中的(值2)
{
	using namespace std;
	ca--;
	if (e != 7)			//这里先判断e不为7的情况
	{
		if (isEqBankFull())	//仓库满
		{
			cout << "装备仓库满了,";
			return false;
		}
		else if (!isCardEquipHere(ca+1, e, num))	//卸除位置无装备
		{
			cout << "该位置没有装备,";
			return false;
		}
		else
		{
			if (num == 1)	//装备中卡牌
			{
				Equip& temp_1 = card[ca].lookforEQ(e);	//指向该卡牌的装备
				Equip& temp_2 = lookforEquip();	//指向仓库中的空装备位置
				Equip temp;		//作为中介
				temp = temp_1;
				temp_1 = temp_2;
				temp_2 = temp;
				cout << "之前的装备已经被取下放在仓库里了。" << endl;
				return true;

			}
			else if (num == 2)	//仓库中卡牌
			{
				Equip& temp_1 = caBank[ca].lookforEQ(e);
				Equip& temp_2 = lookforEquip();
				Equip temp;		//作为中介
				temp = temp_1;
				temp_1 = temp_2;
				temp_2 = temp;
				cout << "之前的装备已经被取下放在仓库里了。" << endl;
				return true;
			}
			else
			{
				cout << "发生了位置错误,请反馈给技术人员,错误代码s-009" << endl;
				return false;
			}
		}
	}
	else if (e == 7)	//e为7时,卸除全部装备,
	{
		int i;
		for (i = 0;i < 6;i++)
		{
			if (isEqBankFull())	//仓库满,结束
			{
				cout << "卸除过程中装备仓库已满,";
				return false;
			}
			else if (!isCardEquipHere(ca+1, i+1, num))	//卸除位置无装备,则跳过
				continue;
			else
			{
				if (num == 1)	//装备中卡牌
				{
					Equip& temp_1 = card[ca].lookforEQ(i+1);	//指向该卡牌的装备
					Equip& temp_2 = lookforEquip();	//指向仓库中的空装备位置
					Equip temp;		//作为中介
					temp = temp_1;		//交换位置
					temp_1 = temp_2;
					temp_2 = temp;
					cout << "之前的装备已经被取下放在仓库里了。" << endl;
				}
				else if (num == 2)	//仓库中卡牌
				{
					Equip& temp_1 = caBank[ca].lookforEQ(i+1);
					Equip& temp_2 = lookforEquip();
					Equip temp;		//作为中介
					temp = temp_1;
					temp_1 = temp_2;
					temp_2 = temp;
					cout << "之前的装备已经被取下放在仓库里了。" << endl;
				}
				else
				{
					cout << "发生了位置错误,请反馈给技术人员,错误代码s-009" << endl;
					return false;
				}
			}
		}		//for结束
		if (num == 1)
			card[ca].setSide();
		else if (num == 2)
			caBank[ca].setSide();
		if (i == 6)return true;		//如果是6,说明全部都卸除了,返回true
		else 	return false;
	}
	else
	{
		cout << "发生了位置错误,请反馈给技术人员,错误代码s-010" << endl;
		return false;
	}
}
void Player::winner(int num)	//给装备中的卡牌加经验
{
	for (int i = 0;i < 5;i++)
	{
		if(card[i].isHere())
			card[i].addEXP(num);
	}
}

//Card类
Card::Card()
{
	name = "";
	id = quality = lv = exp = 0;
	base_atk = base_def = base_hp = 0;
	for (int i = 0;i < 6;i++)
		eq[i] = i;
}
Card::Card(const Card& ca)
{
	name = ca.name;
	id = ca.id;
	quality = ca.quality;
	lv = ca.lv;
	base_atk = ca.base_atk;
	base_def = ca.base_def;
	base_hp = ca.base_hp;
	exp = ca.exp;
	for (int i = 0;i < 6;i++)
		eq[i] = ca.eq[i];
	setATK();
	setDEF();
	setHP();
}
void Card::addCard(int i)	//新增一个卡牌,创新人物/抽奖时可以使用
{
	using namespace std;
	if (i == 0)
	{
		int ra;
		ra = rand() % 10000;
		cout << ra << endl;
		if (ra < 3000)quality = 1;	//白色30%
		else if (ra < 6000)quality = 2;	//绿色30%
		else if (ra < 8000)quality = 3;	//蓝色20%
		else if (ra < 9500)quality = 4;	//紫色15%
		else if (ra < 9980)quality = 5;	//橙色4.8%
		else quality = 6;	//神话0.2%
							//决定抽卡的品质
	}
	else quality = i;

	ifstream one;
	one.open("card.txt");
	if (!one.is_open())
	{
		cout << "card.txt文件(用于存储卡牌信息)损坏" << endl;
		system("pause");
	}
	string line;		//用于储存临时内容的string类
	while (getline(one, line))
	{
		if (line.size() < 3 || line[0] == '/')
			continue;
		int temp;
		if (line[0] == ',')	//读取到各个品质有多少个的行
		{
			stringstream oss;	//转换成流——不懂
			oss << line;
			char q;
			oss >> q;	//先读取掉第一个逗号
			for (int i = 0;i < quality;i++)
				oss >> temp;	//读取当前品质卡的数量
			id = (quality - 1) * 100 + rand() % temp + 1;	//决定卡的ID,注意,每个卡片数量不能低于1,必须要有卡
			continue;
		}
		stringstream osss;
		osss << line;
		osss >> temp;
		if (temp == id)	//如果读取的是ID
		{
			osss >> name >> quality >> base_hp >> base_atk >> base_def;	//读取五个属性
			break;	//结束
		}
	}

	cout << "抽取中";
	for (int i = 0;i < 5;i++)
	{
		cout << ".";
		Sleep(200);
	}
	cout << endl;
	exp = 0;
	setLV();
	setATK();
	setDEF();
	setHP();

	cout << "你抽取的新卡为:" << name << ",品质:";
	if (quality == 1)cout << "普通,";
	else if (quality == 2)cout << "优质,";
	else if (quality == 3)cout << "精良,";
	else if (quality == 4)cout << "史诗,";
	else if (quality == 5)cout << "传说,";
	else if (quality == 6)cout << "神话,";
	cout << "生命值:" << hp << ",攻击力:" << atk << ",防御力:" << def << endl;
	cout << "恭喜你!" << endl << endl;
	one.close();
}
bool Card::buyCard(int i)
{
	using namespace std;
	id = i;
	ifstream one;
	bool sign = false;	//用于检测是否成功购买到
	one.open("card.txt");
	if (!one.is_open())
	{
		cout << "card.txt文件(用于存储卡牌信息)损坏" << endl;
		system("pause");
	}
	string line;		//用于储存临时内容的string类
	while (getline(one, line))
	{
		if (line.size() < 3 || line[0] == '/' || line[0] == ',')
			continue;
		int temp;
		stringstream osss;
		osss << line;
		osss >> temp;
		if (temp == i)	//如果读取的是ID
		{
			osss >> name >> quality >> base_hp >> base_atk >> base_def;	//读取五个属性
			sign = true;	//如果成功读取,标识符为true
			break;	//结束
		}
	}
	cout << endl;
	exp = 0;
	setLV();
	setATK();
	setDEF();
	setHP();

	if (sign == true)
	{
		cout << "你已成功购买新的卡片:" << name << ",品质:";
		if (quality == 1)cout << "普通,";
		else if (quality == 2)cout << "优质,";
		else if (quality == 3)cout << "精良,";
		else if (quality == 4)cout << "史诗,";
		else if (quality == 5)cout << "传说,";
		else if (quality == 6)cout << "神话,";
		cout << "生命值:" << hp << ",攻击力:" << atk << ",防御力:" << def << endl;
		cout << "谢谢惠顾!" << endl << endl;
	}
	else
	{
		cout << "找不到您要购买的ID为:" << i << "的卡牌呢,对不起噢~如果有疑问,请反馈给技术人员。" << endl;
	}
	one.close();
	system("pause");
	return sign;
}
bool Card::show()
{
	using namespace std;
	if (quality == 0)
	{
		//cout << "————无卡牌————" << endl;
		return false;
	}
	setATK();
	setDEF();
	setHP();
	cout << "——————————————" << endl;
	cout << "卡牌名  :" << name << endl;
	cout << "卡牌品质:";
	if (quality == 1)cout << "普通" << endl;
	else if (quality == 2)cout << "优质" << endl;
	else if (quality == 3)cout << "精良" << endl;
	else if (quality == 4)cout << "史诗" << endl;
	else if (quality == 5)cout << "传奇" << endl;
	else if (quality == 6)cout << "神话" << endl;
	cout << "级    别:" << lv << endl;
	cout << "经验值  :" << exp << endl;
	cout << "升级需要:";
	if (exp < 2)cout << 8 - exp << endl;
	else cout << (lv+1)*(lv + 1)*(lv + 1)*(lv + 1) - exp << endl;
	cout << "生命值:  " << getHP() << endl;
	cout << "攻击力  :" << getATK() << endl;
	cout << "防御力  :" << getDEF() << endl;
	cout << "装    备:" << endl;
	for (int i = 0;i < 6;i++)
		eq[i].show();	//调用eq[i].show()函数
	cout << "——————————————" << endl;
	return true;
}
bool Card::isHere()	//卡牌存在返回true,否则false
{
	return (quality > 0);
}
int Card::GiveEXP() //打败后给予的经验值,非对怪使用
{
	if (lv < 20)return int(lv*lv*lv*quality*quality);
	else if (lv < 40)return int(lv*lv*lv*0.9*quality*quality);
	else if (lv < 60)return int(lv*lv*lv*0.8*quality*quality);
	else if (lv < 80)return int(lv*lv*lv*0.7*quality*quality);
	else if (lv < 100)return int(lv*lv*lv*0.6*quality*quality);
	else if (lv < 130)return int(lv*lv*lv*0.5*quality*quality);
	else return int(lv*lv*lv*0.45*quality*quality);	//if (lv <= 150)
}
void Card::addEXP(int ex)
{
	using namespace std;
	exp += ex;
	int LV = lv;
	setLV();
	if (LV < lv)
	{
		cout << "升级啦!新的级别为:" << lv << endl;
	}
}
void Card::setLV()
{
	if (exp == 0)lv = 1;
	else lv = int(sqrt(sqrt(exp)));	//经验满足等级的4次方后升级,等级的四次方开方后为等级(去掉小数部分)
}
int Card::getATK()
{
	return atk + eq[0].getATK() + eq[1].getATK() + eq[2].getATK() + eq[3].getATK() + eq[4].getATK() + eq[5].getATK();
}
int Card::getDEF()
{
	return def + eq[0].getDEF() + eq[1].getDEF() + eq[2].getDEF() + eq[3].getDEF() + eq[4].getDEF() + eq[5].getDEF();
}
int Card::getHP()
{
	return hp + eq[0].getHP() + eq[1].getHP() + eq[2].getHP() + eq[3].getHP() + eq[4].getHP() + eq[5].getHP();
}
bool Card::addEquip(Equip& eqq)	//装备上新装备
{
	using namespace std;
	int side = eqq.getside() - 1;		//side为装备的位置,eq[0]为头盔,但是头盔的side是1,所以需要-1
	cout << "更换前的装备:";
	eq[side].show();
	if (eq[side].isHere())	//如果当前位置有装备
	{
		if (eqq.getLvLimit() > lv)
		{
			cout << "你需要达到 " << eqq.getLvLimit() << " 级才能装备上这件装备" << endl;
			return false;
		}
		Equip temp = eqq;
		eqq = eq[side];
		eq[side] = temp;
		cout << "之前的装备已经被取下放在仓库里了。" << endl;
		cout << "更换后的装备:";
		eq[side].show();
		return true;
	}
	else 	//如果当前位置没有装备if (!eq[side].isLive())
	{
		if (eqq.getLvLimit() > lv)
		{
			cout << "你需要达到 " << eqq.getLvLimit() << " 级才能装备上这件装备" << endl;
			return false;
		}
		Equip temp;
		eq[side] = eqq;
		eqq = temp;
		cout << "新装备已经被装备上了。";
		cout << "更换后的装备:";
		eq[side].show();
		return true;
	}
}
std::ostream& operator<<(std::ostream& os, const Card& ca)	//存档时使用,存卡牌
{
	os << ca.id << " " << ca.exp << "     ";	//则储存id和经验
	if (ca.id>0)	//如果卡牌存在才存储装备
		for (int i = 0;i < 6;i++)		//并储存装备
			os << ca.eq[i] << " ";
	os << std::endl;
	return os;
}
std::istream& operator>>(std::istream& is, Card& ca)
{
	using namespace std;
	is >> ca.id;	//读取玩家存档文件中,卡牌行的第一个ID
	is >> ca.exp;
	if (ca.id > 0)	//如果卡牌存在才读取卡牌相关东西
	{
		ifstream two;
		two.open("card.txt");
		if (!two.is_open())
		{
			cout << "card.txt文件(用于存储卡牌信息)损坏" << endl;
			system("pause");
		}

		string line;		//用于储存临时内容的string类
		while (getline(two, line))
		{
			if (line.size() < 3 || line[0] == '/' || line[0] == ',')	//不读取注释行、空行、和品质行
				continue;
			int temp;
			stringstream osss;	//这个是个什么流,不太懂
			osss << line;	//把读取的那行转给流osss
			osss >> temp;	//先读取第一个ID
			if (temp == ca.id)	//如果读取的ID符合,则执行判断,不符合,则重来
			{
				osss >> ca.name >> ca.quality >> ca.base_hp >> ca.base_atk >> ca.base_def;	//读取名字、品质、生命、攻击、防御系数
				break;	//结束
			}
		}
		ca.setATK();	//设置攻击力
		ca.setDEF();	//设置防御力
		ca.setHP();	//设置生命值
		ca.setLV();	//设置等级
		two.close();	//关闭文件
		two.clear();
		for (int i = 0;i < 6;i++)
			is >> ca.eq[i];
	}
	return is;
}

string Card::getPinZhi()
{
	string PinZhi;
	if (quality == 1)PinZhi = "普通";
	else if (quality == 2)PinZhi = "优秀";
	else if (quality == 3)PinZhi = "精良";
	else if (quality == 4)PinZhi = "史诗";
	else if (quality == 5)PinZhi = "传说";
	else if (quality == 6)PinZhi = "神话";
	else PinZhi = "显示错误";
	return PinZhi;
}
bool Card::isEquipHere(int num)
{
	return eq[num].isHere();
}
Equip& Card::lookforEQ(int s)	//根据参数,返回某位置装备的引用,用于修改该位置装备
{
	s--;
	return eq[s];
}
void Card::setSide()		//设置卡牌的各个装备的位置
{
	for (int i = 0;i < 6;i++)
	{
		eq[i].setSide(i + 1);
	}
}

//Equip类
void Equip::set(int i, int l)	//读档时,根据装备id和等级,加载装备数据
{
	using namespace std;
	id = i;
	lv = l;
	ifstream three;
	if (i < 100)three.open("toukui.txt");
	else if (i < 200)three.open("kuijia.txt");
	else if (i < 300)three.open("shoutao.txt");
	else if (i < 400)three.open("wuqi.txt");
	else if (i < 500)three.open("dunpai.txt");
	else three.open("jiezhi.txt");
	if (!three.is_open())
	{
		cout << "读取文件失败,正在读取装备文件,ID:" << id << endl;
		system("pause");
	}
	string line;		//用于储存临时内容的string类
	while (getline(three, line))
	{
		if (line.size() < 3 || line[0] == '/')
			continue;
		int temp;

		stringstream osss;
		osss << line;
		osss >> temp;
		if (temp == i)	//如果读取的是ID
		{
			osss >> name >> quality >> atk >> def >> hp >> side;	//读取装备的6个属性
			break;	//结束
		}
	}
	three.close();
	three.clear();
}
int Equip::getLvLimit()	//装备的等级限制
{
	if (lv == 1)return 1;
	else if (lv < 10)return lv * 3;
	else if (lv < 15)return lv * 5;
	else if (lv < 20)return lv * 7;
	else return 150;
}
std::ostream& operator<<(std::ostream& os, const Equip& eq)	//存档时使用
{
	os << eq.id << " " << eq.lv << "  ";
	return os;
}
std::istream& operator>>(std::istream& is, Equip& eq)	//读档时读取装备
{
	is >> eq.id;
	is >> eq.lv;
	if (eq.id != 0)	//如果ID不为0,则说明有装备,于是读取
		eq.set(eq.id, eq.lv);	//将这个临时对象按值传递给eq
	return is;
}
bool Equip::show()	//装备显示,用于卡牌显示使用
{
	using namespace std;
	cout << "位置:";
	if (side == 1)cout << "头盔:";
	else if (side == 2)cout << "盔甲:";
	else if (side == 3)cout << "手套:";
	else if (side == 4)cout << "武器:";
	else if (side == 5)cout << "盾牌:";
	else if (side == 6)cout << "戒指:";
	if (quality == 0)
	{
		cout << "空" << endl;
		return false;
	}
	cout << name << ",品质:";
	if (quality == 1)cout << "普通,";
	else if (quality == 2)cout << "优质,";
	else if (quality == 3)cout << "精良,";
	else if (quality == 4)cout << "史诗,";
	else if (quality == 5)cout << "传说,";
	else if (quality == 6)cout << "神话,";

	cout << "级别:" << lv << ",";
	cout << "属性增益:";
	if (atk > 0)cout << "攻击:" << atk*lv*lv << ",";
	if (def > 0)cout << "防御:" << def*lv*lv << ",";
	if (hp > 0)cout << "生命:" << hp*lv*lv << ",";
	cout << endl;
	return true;
}
bool Equip::isHere()
{
	if (id > 0)return true;
	else return false;
}
bool Equip::buyEq(int i)	//购买装备时使用
{
	using namespace std;
	bool sign = false;
	id = i;
	lv = 1;
	ifstream three;
	if (i < 100)three.open("toukui.txt");
	else if (i < 200)three.open("kuijia.txt");
	else if (i < 300)three.open("shoutao.txt");
	else if (i < 400)three.open("wuqi.txt");
	else if (i < 500)three.open("dunpai.txt");
	else three.open("jiezhi.txt");
	string line;
	while (getline(three, line))
	{
		if (line.size() < 3 || line[0] == '/')
			continue;
		int temp;
		stringstream oss;
		oss << line;
		oss >> temp;
		if (temp == i)	//如果成功找到
		{
			oss >> name >> quality >> atk >> def >> hp >> side;
			sign = true;
			break;
		}
	}

	if (sign == true)
	{
		cout << "你已成功购买新的装备:";
		show();
		cout << "谢谢惠顾!" << endl << endl;
	}
	else
	{
		cout << "找不到您要购买的ID为:" << i << "的卡牌呢,对不起噢~如果有疑问,请反馈给技术人员。" << endl;
	}
	three.close();
	system("pause");
	return sign;
}
//——————————————————————————————






//游戏函数
//游戏.cpp
#include<iostream>
#include<fstream>
#include<string>
#include <cstdlib> //用于清屏,清屏命令是system("cls")
#include<windows.h> //用于使用延迟函数,具体为Sleep(毫秒),S为大写;
#include <ctime>//这个和下面两个,好像是和随机数有关的
#include <cstdlib>
#include<sstream>
#include<iomanip>
#include"卡牌.h"
void view(Player & pl);		//主界面
void openGame(Player & pl);		//进入游戏界面
bool GameLoad(Player& pl);	//读档
void NewGame(Player& pl);	//新建人物
void Shop(Player& pl);	//商店
void CardShop(Player& pl);	//商店之卡牌
void EquipShop(Player& pl);	//商店之装备
void moveCardAndEquip(Player& pl);	//装备中、背包的卡牌和装备的调整
void CardEquipChange(Player& pl);	//更改卡牌的装备
void MAPchoice(Player& pl);		//地图选择
bool combatVS(combat &p1, combat &p2, combat &p3, combat &p4, combat &p5, combat &e1, combat &e2, combat &e3, combat &e4, combat &e5, combat &e6);	//战斗函数
void ReadMap(Player&pl, string m);	//读取关卡
void combatShow(combat &p1, combat &p2, combat &p3, combat &p4, combat &p5, combat &e1, combat &e2, combat &e3, combat &e4, combat &e5, combat &e6, int i);	//战斗画面显示
int combatInOneTurn(combat &p1, combat &p2, combat &p3, combat &p4, combat &p5, combat &e1, combat &e2, combat &e3, combat &e4, combat &e5, combat &e6);	//每回合依次行动,并进行战斗通报,这是一回合的全部战斗

void openGame(Player & pl)
{
	using namespace std;
	while (1)
	{
		cout << "欢迎来到卡牌游戏~" << endl;
		cout << "1.读取存档" << endl;
		cout << "2.新建人物" << endl;
		cout << "->";
		int choice;
		cin >> choice;
		while (!cin || (choice != 1 && choice != 2))
		{
			cin.clear();
			cin.sync();
			cout << "输入错误,请重新输入:";
			cin >> choice;
		}
		if (choice == 1)
		{
			if (GameLoad(pl))break;		//读档
		}
		else
		{
			NewGame(pl);	//存档
			break;
		}
	}
}

bool GameLoad(Player& pl)
{
	using namespace std;
	ifstream temp;
	cout << "档案读取。输入你的角色名:";
	cin.sync();
	string name;
	getline(cin, name);
	cin.sync();
	temp.open(name);
	while (!temp.is_open())
	{
		cout << "读取失败!请输入正确的角色名(或者输入q返回初始界面):";
		getline(cin, name);
		cin.sync();
		if (name == "q")return false;
		temp.open(name);
	}
	//下来涉及到读取,和存档方式有关
	pl.load(temp,name);
	temp.close();
	return true;
}

void NewGame(Player& pl)
{
	using namespace std;
	cout << "请输入玩家姓名:";
	string name;
	cin >> name;
	pl = name;
}
void view(Player & pl)//初始显示画面
{
	using namespace std;
	char choice = 0;
	while (choice != 'q')
	{
		pl.save();
		cout << "——————卡牌游戏——————" << endl;
		cout << "亲爱的玩家 " << pl.getName() << " 你好!" << endl;
		cout << "您目前有" << pl.getGold() << "金币和" << pl.getDiamond() << "钻石" << endl;
		cout << "1.查看仓库" << endl;
		cout << "2.通关之路" << endl;
		cout << "3.抽奖" << endl;
		cout << "4.商店" << endl;
		cout << "5.仓库整理" << endl;
		cout << "6.调整卡牌和装备" << endl;
		cout << "q.存档并退出" << endl;
		cout << "————————————————" << endl;
		cout << "您的选择是->";
		cin >> choice;
		cin.sync();
		if (choice == 'q')
		{
			pl.save();
			break;
		}
		while (!cin || choice < '1' || choice > '6')
		{
			cin.clear();
			cin.sync();
			cout << "输入错误,请重新输入:";
			cin >> choice;
		}
		if (choice == '1')
		{
			pl.show();
		}
		else if (choice == '2')
		{
			MAPchoice(pl);
		}
		else if (choice == '3')
		{
			pl.goodLuck();
		}
		else if (choice == '4')
		{
			Shop(pl);
		}
		else if (choice == '5')
		{
			//整理卡牌
			cout << "将卡牌品质高的,级别高的放在前面。是否整理?" << endl;
			cout << "y.是\tq.退出" << endl;
			cout << "->";
			char chhh;
			cin >> chhh;
			while (!cin || (chhh != 'y'&&chhh != 'q'))
			{
				cin.clear();
				cin.sync();
				cout << "输入错误,请重新输入:";
				cin >> chhh;
			}
			if (chhh == 'y')
			{
				pl.caBankLvHtoL();
				pl.caBankQuHtoL();
				cout << "整理完成" << endl;
				system("pause");
			}
				//整理装备
			cout << "是否需要整理仓库中的装备?顺序为:首先按头盔、盔甲、手套、武器、盾牌、戒指顺序摆放,其次品质高的放前面,再次同一品质级别高的放前面" << endl;
			cout << "y.是\tq.退出" << endl;
			cout << "->";
			cin.sync();
			cin >> chhh;
			while (!cin || (chhh != 'y'&&chhh != 'q'))
			{
				cin.clear();
				cin.sync();
				cout << "输入错误,请重新输入:";
				cin >> chhh;
			}
			if (chhh == 'y')
			{
				pl.eqBankHtoL();
				cout << "整理完成" << endl;
				system("pause");
			}
			cin.sync();
		}
		else if (choice == '6')
		{
			moveCardAndEquip(pl);
		}

	}
	pl.save();
	
}
void check(char&ch)//输入错误检测函数——针对char类型,仅对1、2、q有效
{
	using std::cin;
	using std::cout;
	cin >> ch;
	while (ch != 'q'&& ch != '1' && ch != '2')	//如果输入不符合要求
	{
		cin.clear();
		cin.sync();
		cout << "输入错误,请重新输入:";
		cin >> ch;
	}
	cin.sync();
}

void Shop(Player& pl)	//商店
{
	using namespace std;
	char ch='0';
	while (ch != 'q')
	{
		cout << "********商店********" << endl;
		cout << "1.卡牌商店(需要碎片)" << endl;
		cout << "2.装备商店(需要金币)" << endl;
		cout << "q.退出" << endl;
		cout << "->";
		check(ch);
		if (ch == '1')
		{
			CardShop(pl);
		}
		else if (ch == '2')
		{
			EquipShop(pl);
		}
		else if (ch == 'q')
		{
			return;
		}
		else
		{
			cout << "无法找到您需要的选项" << endl;
		}
	}
}

void CardShop(Player& pl)		//卡牌商店(使用碎片)
{
	using namespace std;
	ifstream cashop;
	cashop.open("card.txt");
	if (!cashop.is_open())
	{
		cout << "card.txt文件(用于存储卡牌信息)损坏" << endl;
		system("pause");
	}
	char ch = '0';
	while (ch != 'q')
	{
		cashop.clear();	//清除cashop的状态
		cashop.seekg(0, ios::beg);		//把读指针移动到开头。seekg是读指针,ios::beg是文件开头
		cout << endl;
		cout << "******卡牌商店******" << endl;
		cout << "您现在有" << pl.getStars() << "个碎片" << endl;
		cout << "1.普通级" << endl;
		cout << "2.优质级" << endl;
		cout << "3.精良级" << endl;
		cout << "4.史诗级" << endl;
		cout << "5.传说级" << endl;
		cout << "q.退出" << endl;
		cout << "->";
		cin >> ch;
		cin.sync();
		while (!cin || (ch != '1'&&ch != '2'&&ch != '3'&&ch != '4'&&ch != '5'&&ch!='q'))
		{
			cin.clear();
			cin.sync();
			cout << "输入错误,请重新输入:";
			cin >> ch;
		}
		int min, max;
		if (ch == 'q')break;
		else if (ch == '1')min = 0;
		else if (ch == '2')min = 1;
		else if (ch == '3')min = 2;
		else if (ch == '4')min = 3;
		else if (ch == '5')min = 4;
		else {
			cout << "找不到你输入的对象,请重新输入。" << endl;
			system("pause");
			continue;
		}
		string line;		//用于储存临时内容的string类
		while (getline(cashop, line))
		{
			if (line.size() < 3 || line[0] == '/')
				continue;
			int temp;
			if (line[0] == ',')	//读取到各个品质有多少个的行
			{
				stringstream oss;	//转换成流——不懂
				oss << line;
				char q;
				oss >> q;	//先读取掉第一个逗号
				for (int i = -1;i < min;i++)
					oss >> temp;	//读取当前品质卡的数量
				max = min * 100 + temp;	//max为该品质卡牌的最大ID号
				min = min * 100 + 1;	//min为该品质卡牌的最小ID号
				continue;
			}
			stringstream osss;
			osss << line;
			osss >> temp;	//读取ID
			if (temp >= min && temp <= max)	//如果读取的是ID
			{
				int i = 1;
				string name;
				int quality;
				double base_hp, base_atk, base_def;
				int price;
				osss >> name >> quality >> base_hp >> base_atk >> base_def >> price >> price;	//读取五个属性,连续读取,第二个price是购买的价格
				cout << "***卡牌 " << i++ << " ***" << endl;
				cout << "ID:" << temp << ",名字:" << name << ",级别:1级,品质:";
				if (quality == 1)cout << "普通,";
				else if (quality == 2)cout << "优质,";
				else if (quality == 3)cout << "精良,";
				else if (quality == 4)cout << "史诗,";
				else if (quality == 5)cout << "传说,";
				else if (quality == 6)cout << "神话,";
				else cout << "显示错误,请反馈" << endl;		//错误提示
				cout << "攻击:" << int(sqrt(base_atk)*(quality*quality));
				cout << ",防御:" << int(sqrt(base_def)*quality*quality);
				cout << ",生命:" << int(base_hp*quality*quality);
				cout << ",价格:" << price << "碎片。" << endl;
			}
		}
		cout << "q.退出" << endl;
		cout << "请输入卡牌的ID号进行购买:" << endl;
		cout << "->";
		int chh;
		cin >> chh;
		while (chh<min || chh>max)
		{
			if (!cin)break;
			cout << "输入错误.请重新输入:";
			cin.sync();
			cin >> chh;
		}
		if (!cin)
		{
			cin.clear();
			cin.sync();
			cout << "已为您退出。" << endl;
			system("pause");
			break;
		}
			//下来是正确选择了购买道具后,查看碎片是否足够
		cashop.clear();	//清除cashop的状态
		cashop.seekg(0, ios::beg);		//把读指针移动到开头。seekg是读指针,ios::beg是文件开头

		int price;
		while (getline(cashop, line))
		{
			if (line.size() < 3 || line[0] == '/' || line[0] == ',')
				continue;
			int temp;
			stringstream osss;
			osss << line;
			osss >> temp;	//读取ID
			if (temp == chh)	//如果读取的ID和选择的ID相符
			{
				string name;
				int quality;
				double base_hp, base_atk, base_def;
				osss >> name >> quality >> base_hp >> base_atk >> base_def >> price >> price;	//此时读取了选择的卡牌的价格
				break;
			}
		}
		if (pl.getStars() < price)	//碎片不够
		{
			cout << "你只有" << pl.getStars() << "碎片,该卡片价格为" << price << "碎片" << endl;
			continue;
		}
		else		//碎片足够
		{
			if (pl.isCaBankFull())	//如果仓库是满的
			{
				cout << "你的仓库已满,不能购买" << endl;
				system("pause");
			}
			else
			{
				Card& temp = pl.lookfor();			//temp指向仓库中空卡牌的位置
				if (temp.buyCard(chh))				//如果成功购买
					pl.addStars(-price);			//扣除碎片
				else								//否则
					cout << "碎片已退回" << endl;
			}
		}
		pl.save();
	}
	pl.save();
}
void EquipShop(Player& pl)		//装备商店(使用金币)
{
	using namespace std;
	ifstream eqshop;
	char ch = 0;
	while (ch != 'q')
	{
		pl.save();
		cout << endl;
		cout << "******装备商店******" << endl;
		cout << "您现在有" << pl.getGold() << "个金币" << endl;
		cout << "1.头盔" << endl;
		cout << "2.盔甲" << endl;
		cout << "3.手套" << endl;
		cout << "4.武器" << endl;
		cout << "5.盾牌" << endl;
		cout << "6.戒指" << endl;
		cout << "q.退出" << endl;
		cout << "->";
		cin >> ch;
		cin.sync();
		while (!cin || (ch != 'q' && (ch<'1' || ch>'6')))
		{
			cin.clear();
			cin.sync();
			cout << "输入错误,请重新输入->";
			cin >> ch;
		}
		if (ch == 'q')	//输入的为q,则退出
			return;
		else if (ch == '1')
			eqshop.open("toukui.txt");
		else if (ch == '2')
			eqshop.open("kuijia.txt");
		else if (ch == '3')
			eqshop.open("shoutao.txt");
		else if (ch == '4')
			eqshop.open("wuqi.txt");
		else if (ch == '5')
			eqshop.open("dunpai.txt");
		else if (ch == '6')
			eqshop.open("jiezhi.txt");
		else
		{
			cout << "发生了奇怪的事情,竟然无法打开!请反馈给技术人员,错误代码s-001" << endl;
			continue;
		}
		if (!eqshop.is_open())	//假如发生了无法打开的情况
		{
			cout << "无法打开你要购买的装备列表,请反馈给技术人员,错误代码s-002" << endl;
			continue;
		}
		eqshop.clear();	//清除cashop的状态
		eqshop.seekg(0, ios::beg);		//把读指针移动到开头。seekg是读指针,ios::beg是文件开头
		string line;
		int min, max, i = 1;
		min = max = 0;
							//读取装备列表
		while (getline(eqshop, line))
		{
			if (line.size() < 3 || line[0] == '/')
				continue;
			int temp;
			stringstream osss;
			osss << line;
			osss >> temp;	//读取ID
			if (min == 0)min = temp;	//第一次的时候,min被赋值(于是min是最小的装备ID)
			max = temp;					//max是最大的装备ID
			string name;
			int quality;
			double atk, def, hp;
			int price;
			int side;
			osss >> name >> quality >> atk >> def >> hp >> side >> price;	//读取五个属性,连续读取,第二个price是购买的价格
			cout << "***装备 " << i++ << " ***" << endl;
			cout << "ID:" << temp << ",名字:" << name << ",级别:1级,品质:";
			if (quality == 1)cout << "普通,";
			else if (quality == 2)cout << "优质,";
			else if (quality == 3)cout << "精良,";
			else if (quality == 4)cout << "史诗,";
			else if (quality == 5)cout << "传说,";
			else if (quality == 6)cout << "神话,";
			else cout << "显示错误,请反馈,错误代码s-003" << endl;		//错误提示
			cout << "\n***属性加成***攻击:" << atk;
			cout << ",防御:" << def;
			cout << ",生命:" << hp;
			cout << ",价格:" << price << "金币。" << endl;
		}
		cout << "q.退出" << endl;
		cout << "请输入卡牌的ID号进行购买:" << endl;
		cout << "->";
		int chh;
		cin >> chh;
		while (chh<min || chh>max)
		{
			if (!cin)break;
			cout << "输入错误.请重新输入:";
			cin.sync();
			cin >> chh;
		}
		if (!cin)
		{
			cin.sync();
			cin.clear();
			cout << "已为您退出。" << endl;
			system("pause");
			eqshop.close();
			continue;
		}
		eqshop.clear();	//清除cashop的状态
		eqshop.seekg(0, ios::beg);		//把读指针移动到开头。seekg是读指针,ios::beg是文件开头
			//下来到处理购买装备的环节
		while (getline(eqshop, line))
		{
			if (line.size() < 3 || line[0] == '/')	//跳过空行和注释行
				continue;
			int temp;
			stringstream osss;
			osss << line;
			osss >> temp;	//读取ID

			if (temp == chh)	//如果查找到id符合的装备
			{
				string name;
				int quality;
				double atk, def, hp;
				int price;
				int side;
				osss >> name >> quality >> atk >> def >> hp >> side >> price;	//读取五个属性,连续读取,第二个price是购买的价格

				if (pl.getGold() < price)	//如果钱不够
				{
					cout << "你的金钱不足,你只有" << pl.getGold() << "金币,但购买这件装备需要" << price << "金币。" << endl;
					break;	//返回
				}
				else
				{
					if (pl.isEqBankFull())	//如果仓库满了
					{
						cout << "你的仓库满了,无法放下更多的装备" << endl;
						break;
					}
					else
					{
						Equip&tempeq = pl.lookforEquip();
						if (tempeq.buyEq(chh))
							pl.addGold(-price);
						else
							cout << "金币已退回" << endl;
						pl.save();
					}
				}
				break;	//结束读取文件
			}
		}
		eqshop.close();
	}
	pl.save();

}
void moveCardAndEquip(Player& pl)
{
	using namespace std;
	char ch = '0';
	while (ch != 'q')
	{
		cout << endl;
		cout << "********调整卡牌及装备********" << endl;
		cout << "1.调整装备卡牌" << endl;
		cout << "2.装备新卡牌" << endl;
		cout << "3.解除装备卡牌" << endl;
		cout << "4.更改卡牌的装备" << endl;
		cout << "q.退出" << endl;
		cout << "->";
		cin >> ch;
		while (!cin||(ch != 'q' && (ch<'0' || ch>'4')))	//输入检查
		{
			cin.sync();
			cin.clear();
			cout << "输入错误,请重新输入->";
			cin >> ch;
		}
		cin.sync();
		if (ch == 'q')break;
		else if (ch == '1')
		{
					//调整装备的卡牌
			cout << "*****你目前装备卡牌的次序如下*****" << endl;
			pl.easyCardShow(1);										//显示装备中的卡牌
			cout << "-----请输入你要交换的卡牌的序号-----" << endl;
			cout << "交换的卡牌①的序号(q.退出)->";
			int a, b, c = 0;
			cin >> a;
			while (!cin || a < 1 || a>5)
			{
				cin.sync();
				if (!cin)
				{
					cin.clear();
					cout << "已退出....";
					system("pause");
					c = 1;
					break;
				}
				cout << "输入错误,请重新输入卡牌①的序号(q.退出)->";
				cin >> a;
			}
			if (c == 1)continue;
			cin.sync();
			cout << "交换的卡牌②的序号(q.退出)->";
			cin >> b;
			while (!cin || b < 1 || b>5)
			{
				cin.sync();
				if (!cin)
				{
					cin.clear();
					cout << "已退出....";
					system("pause");
					c = 1;
					break;
				}
				cout << "输入错误,请重新输入卡牌②的序号(q.退出)->";
				cin >> b;
			}
			if (c == 1)continue;
			cin.sync();
			pl.CardMove(a, b, 1);	//交换装备卡牌顺序
			cout << "交换完成。。。。。" << endl;
			cout << "*****你目前装备卡牌如下*****" << endl;
			pl.easyCardShow(1);
			pl.save();
			system("pause");
		}
		else if (ch == '2')
		{
						//将仓库中的卡牌装备到卡牌之中
			cout << "*****仓库中的卡牌列表*****" << endl;
			pl.easyCardShow(2);							//显示仓库中的卡牌
			cout << "***请选取你要装备的卡牌***" << endl;
			cout << "输入该卡牌的位置序号(q.退出)->";
			int a, b, c = 0;
			cin >> a;
			while (!cin || a < 1 || a>40)
			{
				cin.sync();
				if (!cin)
				{
					cin.clear();
					cout << "已退出....";
					system("pause");
					c = 1;
					break;
				}
				cout << "输入错误,请重新输入卡牌①的序号(q.退出)->";
				cin >> a;
			}
			if (c == 1)continue;
			cin.sync();
			cout << "*****装备中的卡牌*****" << endl;
			pl.easyCardShow(1);							//显示装备中的卡牌
			cout << "***请输入你要装备位置的序号(例如1),若该位置已有卡牌,将被取下***" << endl;
			cout << "请输入(q.退出)->";
			cin >> b;
			while (!cin || b < 1 || b>5)
			{
				cin.sync();
				if (!cin)
				{
					cin.clear();
					cout << "已退出....";
					system("pause");
					c = 1;
					break;
				}
				cout << "输入错误,请重新输入(q.退出)->";
				cin >> b;
			}
			if (c == 1)continue;
			cin.sync();
			pl.CardMove(b, a, 2);	//交换装备卡牌顺序
			cout << "新卡牌装备完成。。。。。" << endl;
			cout << "*****你目前装备卡牌如下*****" << endl;
			pl.save();
			pl.easyCardShow(1);
		}
		else if (ch == '3')
		{
					//解除装备中的卡牌
			if (pl.isCaBankFull())
			{
				cout << "你的仓库满了,无法将装备中的卡牌放入仓库之中" << endl;
				system("pause");
				continue;
			}
			else
			{
				cout << "*****你目前装备卡牌如下*****" << endl;
				pl.easyCardShow(1);										//显示装备中的卡牌
				cout << "-----请输入你要解除装备的卡牌的序号-----" << endl;
				cout << "输入卡牌序号(q.退出)->";
				int a, c = 0;
				cin >> a;
				while (!cin || a < 1 || a>5)
				{
					cin.sync();
					if (!cin)
					{
						cin.clear();
						cout << "已退出....";
						system("pause");
						c = 1;
						break;
					}
					cout << "输入错误,请重新输入卡牌序号(q.退出)->";
					cin >> a;
				}
				if (c == 1)continue;
				cin.sync();
				pl.CardMove(a, 0, 3);	//参数3表示是解除装备中的卡牌
				cout << "该卡牌已经解除装备。。。。" << endl;
				cout << "*****你目前装备卡牌如下*****" << endl;
				pl.save();	//存档
				pl.easyCardShow(1);
			}
		}
		else if (ch == '4')
		{
					//给装备中的卡牌装备装备
			CardEquipChange(pl);
		}
		else
		{
				//错误检查
			cout << "发生了奇怪的问题,请联系技术人员反馈错误,错误代码s-004" << endl;
		}

	}
}

void CardEquipChange(Player& pl)		//更改卡牌的装备
{
	using namespace std;
	char ch = '0';
	while (ch != 'q')
	{
		cout << endl;
		cout << "******更改卡牌的装备******" << endl;
		cout << "1.更改装备中卡牌的装备" << endl;
		cout << "2.更改仓库中卡牌的装备" << endl;
		cout << "q.退出" << endl;
		cout << "->";
		check(ch);	//检查输入
		cin.sync();
		if (ch == 'q')break;
		else if (ch == '1')		//1.更改装备中卡牌的装备
		{
			pl.show(1);		//显示装备中的卡牌
			cout << "****请选择你要操作的卡牌****" << endl;
			cout << "请输入序号(q.退出)->";
			int a, b, c = 0;
			cin >> a;
			while (!cin || a < 1 || a>5 || !pl.isCardHere(a, 1))	//非法输入检查,会检查该位置卡牌是否存在
			{
				cin.sync();
				if (!cin)
				{
					cin.clear();
					cin.sync();
					cout << "已退出....";
					system("pause");
					c = 1;
					break;
				}
				if (!pl.isCardHere(a, 1))
					cout << "该位置没有卡牌,";
				cout << "输入错误,请重新输入卡牌的序号(q.退出)->";
				cin >> a;
			}
			if (c == 1)continue;
			cin.sync();

			char chh;
			cout << "****请选择你要进行的操作****" << endl;
			cout << "1.装备新装备 或 更换装备" << endl;
			cout << "2.卸除装备" << endl;
			cout << "q.退出" << endl;
			cout << "->";
			check(chh);
			if (chh == 'q')break;
			else if (chh == '1')
			{
				pl.show(3);		//显示仓库中的装备
				cout << "请输入你要装备的装备的序号(q.退出)->";
				cin >> b;
				while (!cin || b <= 0 || b > pl.getHowMuchEquip())	//如果输入错误或者序号超出已有的数量
				{
					cin.sync();
					if (!cin)
					{
						cin.clear();
						cout << "已退出....";
						system("pause");
						c = 1;
						break;
					}
					cin.clear();
					cout << "输入错误,请重新输入(q.退出)->";
					cin >> b;
				}
				if (c == 1)break;	//输入错误则退出
				else
				{
					if (!pl.CardEquipChange(a, b, 1))
						cout << "未能成功更换装备" << endl;
					pl.save();
					system("pause");
				}
			}
			else if (chh == '2')
			{
				cout << "请输入你要卸除的装备" << endl;
				cout << "1.头盔\n2.盔甲\n3.手套\n4.武器\n5.盾牌\n6.戒指\n7.全部装备\nq.退出" << endl;
				cout << "->";
				cin >> b;
				while (!cin || b <= 0 || b >7 )	//如果输入错误或者序号超出已有的数量
				{
					cin.sync();
					if (!cin)
					{
						cin.clear();
						cout << "已退出....";
						system("pause");
						c = 1;
						break;
					}
					cin.clear();
					cout << "输入错误,请重新输入(q.退出)->";
					cin >> b;
				}
				if (c == 1)break;	//输入错误则退出
				else
				{
					if (!pl.CardEquipRemove(a, b, 1))
					{
						cout << "卸除失败..." << endl;
					}
					else
					{
						cout << "卸除成功!" << endl;
						pl.save();
						pl.show(1);		//显示装备中的卡牌
					}
					pl.save();
					system("pause");
				}
			}
		}
		else if (ch == '2')	//2.更改仓库中卡牌的装备
		{
			pl.show(2);		//显示仓库中的卡牌

			cout << "****请选择你要操作的卡牌****" << endl;
			cout << "请输入序号(q.退出)->";
			int a, b, c = 0;
			cin >> a;
			while (!cin || a < 1 || a>40 || !pl.isCardHere(a, 2))	//非法输入检查,会检查该位置卡牌是否存在
			{
				cin.sync();
				if (!cin)
				{
					cin.clear();
					cin.sync();
					cout << "已退出....";
					system("pause");
					c = 1;
					break;
				}
				else if (!pl.isCardHere(a, 2))
					cout << "该位置没有卡牌,";
				cout << "输入错误,请重新输入卡牌的序号(q.退出)->";
				cin >> a;
			}
			if (c == 1)continue;
			cin.sync();

			char chh;
			cout << "****请选择你要进行的操作****" << endl;
			cout << "1.装备新装备 或 更换装备" << endl;
			cout << "2.卸除装备" << endl;
			cout << "q.退出" << endl;
			cout << "->";
			check(chh);
			if (chh == 'q')break;
			else if (chh == '1')
			{
				pl.show(3);		//显示仓库中的装备
				cout << "请输入你要装备的装备的序号(q.退出)->";
				cin >> b;
				while (!cin || b <= 0 || b > pl.getHowMuchEquip())	//如果输入错误或者序号超出已有的数量
				{
					cin.sync();
					if (!cin)
					{
						cin.clear();
						cout << "已退出....";
						system("pause");
						c = 1;
						break;
					}
					cin.clear();
					cout << "输入错误,请重新输入(q.退出)->";
					cin >> b;
				}
				if (c == 1)break;	//输入错误则退出
				else
				{
					if (!pl.CardEquipChange(a, b, 2))
						cout << "未能成功更换装备" << endl;
					pl.save();
					system("pause");
				}
			}
			else if (chh == '2')
			{
				cout << "请输入你要卸除的装备" << endl;
				cout << "1.头盔\n2.盔甲\n3.手套\n4.武器\n5.盾牌\n6.戒指\n7全部\nq.退出" << endl;
				cout << "->";
				cin >> b;
				while (!cin || b <= 0 || b >7)	//如果输入错误或者序号超出已有的数量
				{
					cin.sync();
					if (!cin)
					{
						cin.clear();
						cout << "已退出....";
						system("pause");
						c = 1;
						break;
					}
					cin.clear();
					cout << "输入错误,请重新输入(q.退出)->";
					cin >> b;
				}
				if (c == 1)break;	//输入错误则退出
				else
				{
					if (!pl.CardEquipRemove(a, b, 2))
					{
						cout << "卸除失败..." << endl;
					}
					else
					{
						cout << "卸除成功!" << endl;
						pl.save();
						pl.show(2);		//显示装备中的卡牌
					}
					pl.save();
					system("pause");
				}

			}

		}
	}

}

void MAPchoice(Player& pl)
{
	using namespace std;
	char chhh = '0';
	system("cls");
	while (chhh != 'q')
	{
		int ch = 0;
		int MAP = pl.getMAP() / 10;	//MAP是大关卡数
		int map = pl.getMAP() % 10;	//map是小关卡数
		ifstream MAPLIST;
		MAPLIST.open("maplist.txt");
		if (!MAPLIST.is_open())
		{
			cout << "无法打开maplist.txt文件,请反馈错误" << endl;
			return;
		}
		string line, filename;
		int max = 0;	//max为最多展示的地图数

						//大地图展示
		while (getline(MAPLIST, line))
		{
			if (line[0] == '/' || line.size() < 3)
				continue;
			stringstream oss;
			oss << line;
			int id;
			oss >> id;

			string name, JianJie;
			int lv;
			if (id <= MAP)
			{
				oss >> name >> lv >> JianJie >> filename;
				cout << "地图" << id << ":" << name << ",等级要求:" << lv << "\n描述:\n" << JianJie << endl << endl;
				max++;
			}
		}
		
		cout << "请输入你要选择进入的地图编号(q.退出)" << endl;
		cout << "->";
		cin >> ch;
		//地图选择
		
		while (!cin || ch<1 || ch>max)
		{
			cin.sync();
			if (!cin)
			{
				cout << "已退出..." << endl << endl;
				cin.clear();
				system("pause");
				return;
			}
			cout << "输入错误,请重新输入->";
			cin >> ch;
		}
		//读取选择的地图
		MAPLIST.clear();	//清除MAPLIST的状态
		MAPLIST.seekg(0, ios::beg);		//把读指针移动到开头。seekg是读指针,ios::beg是文件开头
		while (getline(MAPLIST, line))
		{
			if (line[0] == '/' || line.size() < 3)
				continue;
			stringstream oss;
			oss << line;
			int id;
			oss >> id;

			string name, JianJie;
			int lv;
			if (id == ch)	//读取文件名
			{
				oss >> name >> lv >> JianJie >> filename;
				system("cls");
				cout << "******" << name << "******" << endl;
			}
		}
		MAPLIST.clear();
		MAPLIST.close();	//关闭之

		ifstream Map;	//Map用于读取大小地图,读取地图列表
		Map.open(filename);
		if (!Map.is_open())
		{
			cout << "无法打开" << filename << "文件,请反馈错误" << endl;
			return;
		}

		//地图内的关卡展示
		max = 0;	//max为最多展示的关卡数
		while (getline(Map, line))
		{
			if (line[0] == '/' || line.size() < 3)
				continue;
			stringstream oss;
			oss << line;

			string name,JianJie;
			if (max < map)
			{
				oss >> filename >> name >> JianJie;
				cout << "****关卡" << max + 1 << ":" << name << "****\n简介:\n" << JianJie << endl << endl;
				max++;
			}
		}
		cout << "请输入你要选择进入的地图编号(q.退出)" << endl;
		cout << "->";
		//关卡选择
		int chh;
		cin >> chh;
		bool err = false;
		while (!cin || chh<1 || chh>max)
		{
			cin.sync();
			if (!cin)
			{
				cout << "已退出..." << endl << endl;
				cin.clear();
				system("pause");
				err = true;
				break;
			}
			cout << "输入错误,请重新输入->";
			cin >> chh;
		}

		//读取选择的关卡的文件名
		Map.clear();	//清除Map的状态
		Map.seekg(0, ios::beg);		//把读指针移动到开头。seekg是读指针,ios::beg是文件开头
		if (err == true)	//如果之前输入退出,那么这个时候,则返回选择大地图
			continue;
		max = 1;
		while (getline(Map, line))
		{
			if (line[0] == '/' || line.size() < 3)
				continue;
			stringstream oss;
			oss << line;

			string name, JianJie;
			if (max < chh)
				max++;
			else if (max == chh)
			{
				oss >> filename;	//读取到小地图的名字
				break;
			}
		}
		Map.clear();	//清除Map的状态
		Map.seekg(0, ios::beg);		//把读指针移动到开头。seekg是读指针,ios::beg是文件开头
		Map.close();			//打开关卡
		ReadMap(pl, filename);
	}
	



}

//战斗函数需要的参数有:玩家类(用于生成玩家装备的卡牌),ifstream对象(用于传递打开的文件)

void ReadMap(Player&pl, string m)	//读取关卡
{
	using namespace std;
	ifstream map;
	map.open(m);
	if (!map.is_open())
	{
		cout << "无法打开" << m << "文件,请反馈错误" << endl;
		return;
	}
	//现在是读取关卡地图的函数
	combat player[5];	//结构,战斗用,for玩家
	combat enemy[6];	//结构,战斗用,怪物的
	for (int i = 0;i < 5;i++)		//读取玩家的
	{
		if (pl.getCardforCombat(i).getHP()>0)
		{
			player[i].name = pl.getCardforCombat(i).getName();
			player[i].atk = pl.getCardforCombat(i).getATK();
			player[i].def = pl.getCardforCombat(i).getDEF();
			player[i].hp = pl.getCardforCombat(i).getHP();
			player[i].lv = pl.getCardforCombat(i).getLV();
		}
	}
	int gold, stars, exp, diamond;
	gold = stars = exp = diamond = 0;	//奖励皆为0
	int num = 0;
	int id[3];	//奖励卡牌ID共3种
	double GaiLv[3];	//其奖励几率共三种
	char q;			//读取标识符
	string word;	//读取剧情
	int en = 0;		//怪物开关,0为剧情状态,1为读取怪物状态,2为读取完怪物进入战斗
	string line;

	while (getline(map, line))
	{
		if (line[0] == '/' || (line.size() < 2 && line[0] != '*'))	//只读取有效行
			continue;
		stringstream oss;
		oss << line;
		if (line[0] == 'g')
			oss >> q >> gold;
		else if (line[0] == 's')
			oss >> q >> stars;
		else if (line[0] == 'e')
			oss >> q >> exp;
		else if (line[0] == 'd')
		{
			oss >> q >> diamond;
			cout << "关卡奖励:" << gold << "金币," << stars << "碎片," << exp << "经验," << diamond << "钻石。" << endl;
		}

		else if (line[0] == ',')		//读取可能掉落的三种卡牌
		{
			oss >> q;
			oss >> id[num];
			oss >> GaiLv[num];
			num++;
		}
		else if (line[0] == '$')		//$打头是剧情
		{
			oss >> q;
			oss >> word;
			cout << "-->>" << word << endl;
			Sleep(2000);
		}
		else if (line[0] == '*')		//进入或者结束怪物行
		{
			if (en == 0)	//如果未进入,则进入
			{
				en = 1;
				continue;
			}
			else if (en == 1)	//如果进入中(又遇见说明读取完了),则进入战斗准备
			{
				bool win;
				//战斗函数
				win = combatVS(player[0], player[1], player[2], player[3], player[4], enemy[0], enemy[1], enemy[2], enemy[3], enemy[4], enemy[5]);
				if (win == false)
				{
					system("pause");
					cout << "返回上层目录" << endl;
					return;
				}
				else	//结束战斗,需要分胜负两种情况,如果输了要跳出,如果赢了,那么还要清0当前的出战怪物(或者在战斗函数中清零)
				{
					en = 0;
					cout << endl << endl << endl;
					for (int j = 0;j < 6;j++)
					{
						enemy[j].name = " ";
						enemy[j].hp = enemy[j].atk = enemy[j].def = enemy[j].lv = 0;
					}
					continue;
				}

			}
		}
		else if (line[0] == '-')	//-表示结束行
		{
			int m;
			oss >> q;
			oss >> m;
			pl.addMAP(m);		//如果成功抵达结束行,说明通关了,设置地图进度
			pl.addDiamond(diamond);	//加钻石
			pl.addGold(gold);	//加金钱
			pl.addStars(stars);	//加碎片
			pl.winner(exp);		//加经验
			pl.addLv();		//战斗次数+1
			pl.save();		//存档
			cout << "你获胜了,获得了";
			if (diamond > 0)cout << diamond << "钻石,";
			if (gold > 0)cout << gold << "金币,";
			if (stars > 0)cout << stars << "碎片,";
			if (exp > 0)cout << exp << "经验,";
			cout << "恭喜你!" << endl;
			system("pause");
			system("cls");
			break;
		}


		if (en == 1)	//进入怪物行,开始读取
		{
			oss >> num;		//首先读取位置
			num--;
			oss >> enemy[num].name >> enemy[num].hp >> enemy[num].atk >> enemy[num].def >> enemy[num].lv;	//其次读取名字,生命,攻击,防御
		}

	}



}

bool combatVS(combat &p1, combat &p2, combat &p3, combat &p4, combat &p5, combat &e1, combat &e2, combat &e3, combat &e4, combat &e5, combat &e6)	//每回合依次行动,并进行战斗通报
{
	system("cls");	//清屏
	int i = 1;
	using namespace std;
	bool end = false;
	int win;
	while (end == false)
	{
		combatShow(p1, p2, p3, p4, p5, e1, e2, e3, e4, e5, e6, i);	//显示回合开始情况
		Sleep(1000);
		win = combatInOneTurn(p1, p2, p3, p4, p5, e1, e2, e3, e4, e5, e6);//赢了1,输了2,无结局0
		i++;		//回合数加1
		if (win > 0)//大于0,说明打完了
		{
			if (win == 1)return true;
			else if(win ==2)return false;
		}
		else if (i == 30)	//如果打满30回合
		{
			cout << "你打的时间太久了,战斗失败。。。" << endl;
			return false;
		}
	}
	cout << "combatVS函数发生了预料之外的情况,请反馈给技术人员" << endl;
	return false;	//
}

int combatInOneTurn(combat &p1, combat &p2, combat &p3, combat &p4, combat &p5, combat &e1, combat &e2, combat &e3, combat &e4, combat &e5, combat &e6)
//每回合依次行动,并进行战斗通报,这是一回合的全部战斗
{
	using namespace std;
	//每个轮流来判断,顺序为:p1,p2,p3,e1,e2,e3,p4,p5,e4,e5,e6;
	//p1轮
	int i = 1;

	//我方一号行动
	if (p1.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << p1.name << " 对 ";
		if (e1.hp > 0)
		{
			int dps = (100 + p1.lv - e1.lv) / 100 * p1.atk*(1 - e1.def / (2000 + e1.def));
			cout << e1.name << " 造成了 " << dps << " 点伤害。";
			e1.hp -= dps;
			if (e1.hp <= 0)
			{
				cout << e1.name << "已死亡!" << endl;
				e1.name = "已死亡";
				e1.hp = 0;
			}
		}
		else if (e2.hp > 0)
		{
			int dps = (100 + p1.lv - e2.lv) / 100 * p1.atk*(1 - e2.def / (2000 + e2.def));
			cout << e2.name << " 造成了 " << dps << " 点伤害。";
			e2.hp -= dps;
			if (e2.hp <= 0)
			{
				cout << e2.name << "已死亡!" << endl;
				e2.name = "已死亡";
				e2.hp = 0;
			}
		}
		else if (e3.hp > 0)
		{
			int dps = (100 + p1.lv - e3.lv) / 100 * p1.atk*(1 - e3.def / (2000 + e3.def));
			cout << e3.name << " 造成了 " << dps << " 点伤害。";
			e3.hp -= dps;
			if (e3.hp <= 0)
			{
				cout << e3.name << "已死亡!" << endl;
				e3.name = "已死亡";
				e3.hp = 0;
			}
		}
		else if (e4.hp > 0)
		{
			int dps = (100 + p1.lv - e4.lv) / 100 * p1.atk*(1 - e4.def / (2000 + e4.def));
			cout << e4.name << " 造成了 " << dps << " 点伤害。";
			e4.hp -= dps;
			if (e4.hp <= 0)
			{
				cout << e4.name << "已死亡!" << endl;
				e4.name = "已死亡";
				e4.hp = 0;
			}
		}
		else if (e5.hp > 0)
		{
			int dps = (100 + p1.lv - e5.lv) / 100 * p1.atk*(1 - e5.def / (2000 + e5.def));
			cout << e5.name << " 造成了 " << dps << " 点伤害。";
			e5.hp -= dps;
			if (e5.hp <= 0)
			{
				cout << e5.name << "已死亡!" << endl;
				e5.name = "已死亡";
				e5.hp = 0;
			}
		}
		else if (e6.hp > 0)
		{
			int dps = (100 + p1.lv - e6.lv) / 100 * p1.atk*(1 - e6.def / (2000 + e6.def));
			cout << e6.name << " 造成了 " << dps << " 点伤害。";
			e6.hp -= dps;
			if (e6.hp <= 0)
			{
				cout << e6.name << "已死亡!" << endl;
				e6.name = "已死亡";
				e6.hp = 0;
			}
		}
		Sleep(1000);
	}

	//我方二号行动
	if (p2.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << p2.name << " 对 ";
		if (e1.hp > 0)
		{
			int dps = (100 + p2.lv - e1.lv) / 100 * p2.atk*(1 - e1.def / (2000 + e1.def));
			cout << e1.name << " 造成了 " << dps << " 点伤害。";
			e1.hp -= dps;
			if (e1.hp <= 0)
			{
				cout << e1.name << "已死亡!" << endl;
				e1.name = "已死亡";
				e1.hp = 0;
			}
		}
		else if (e2.hp > 0)
		{
			int dps = (100 + p2.lv - e2.lv) / 100 * p2.atk*(1 - e2.def / (2000 + e2.def));
			cout << e2.name << " 造成了 " << dps << " 点伤害。";
			e2.hp -= dps;
			if (e2.hp <= 0)
			{
				cout << e2.name << "已死亡!" << endl;
				e2.name = "已死亡";
				e2.hp = 0;
			}

		}
		else if (e3.hp > 0)
		{
			int dps = (100 + p2.lv - e3.lv) / 100 * p2.atk*(1 - e3.def / (2000 + e3.def));
			cout << e3.name << " 造成了 " << dps << " 点伤害。";
			e3.hp -= dps;
			if (e3.hp <= 0)
			{
				cout << e3.name << "已死亡!" << endl;
				e3.name = "已死亡";
				e3.hp = 0;
			}
		}
		else if (e4.hp > 0)
		{
			int dps = (100 + p2.lv - e4.lv) / 100 * p2.atk*(1 - e4.def / (2000 + e4.def));
			cout << e4.name << " 造成了 " << dps << " 点伤害。";
			e4.hp -= dps;
			if (e4.hp <= 0)
			{
				cout << e4.name << "已死亡!" << endl;
				e4.name = "已死亡";
				e4.hp = 0;
			}
		}
		else if (e5.hp > 0)
		{
			int dps = (100 + p2.lv - e5.lv) / 100 * p2.atk*(1 - e5.def / (2000 + e5.def));
			cout << e5.name << " 造成了 " << dps << " 点伤害。";
			e5.hp -= dps;
			if (e5.hp <= 0) {
				cout << e5.name << "已死亡!" << endl;
				e5.name = "已死亡";
				e5.hp = 0;
			}
		}
		else if (e6.hp > 0)
		{
			int dps = (100 + p2.lv - e6.lv) / 100 * p2.atk*(1 - e6.def / (2000 + e6.def));
			cout << e6.name << " 造成了 " << dps << " 点伤害。";
			e6.hp -= dps;
			if (e6.hp <= 0) {
				cout << e6.name << "已死亡!" << endl;
				e6.name = "已死亡";
				e6.hp = 0;
			}
		}
		Sleep(1000);
	}

	//我方三号人员行动
	if (p3.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << p3.name << " 对 ";
		if (e1.hp > 0)
		{
			int dps = (100 + p3.lv - e1.lv) / 100 * p3.atk*(1 - e1.def / (2000 + e1.def));
			cout << e1.name << " 造成了 " << dps << " 点伤害。";
			e1.hp -= dps;
			if (e1.hp <= 0) {
				cout << e1.name << "已死亡!" << endl;
				e1.name = "已死亡";
				e1.hp = 0;
			}
		}
		else if (e2.hp > 0)
		{
			int dps = (100 + p3.lv - e2.lv) / 100 * p3.atk*(1 - e2.def / (2000 + e2.def));
			cout << e2.name << " 造成了 " << dps << " 点伤害。";
			e2.hp -= dps;
			if (e2.hp <= 0){cout << e2.name << "已死亡!" << endl;
			e2.name = "已死亡";
			e2.hp = 0;}
		}
		else if (e3.hp > 0)
		{
			int dps = (100 + p3.lv - e3.lv) / 100 * p3.atk*(1 - e3.def / (2000 + e3.def));
			cout << e3.name << " 造成了 " << dps << " 点伤害。";
			e3.hp -= dps;
			if (e3.hp <= 0){cout << e3.name << "已死亡!" << endl;
			e3.name = "已死亡";
			e3.hp = 0;}
		}
		else if (e4.hp > 0)
		{
			int dps = (100 + p3.lv - e4.lv) / 100 * p3.atk*(1 - e4.def / (2000 + e4.def));
			cout << e4.name << " 造成了 " << dps << " 点伤害。";
			e4.hp -= dps;
			if (e4.hp <= 0){cout << e4.name << "已死亡!" << endl;
			e4.name = "已死亡";
			e4.hp = 0;}
		}
		else if (e5.hp > 0)
		{
			int dps = (100 + p3.lv - e5.lv) / 100 * p3.atk*(1 - e5.def / (2000 + e5.def));
			cout << e5.name << " 造成了 " << dps << " 点伤害。";
			e5.hp -= dps;
			if (e5.hp <= 0){cout << e5.name << "已死亡!" << endl;
			e5.name = "已死亡";
			e5.hp = 0;}
		}
		else if (e6.hp > 0)
		{
			int dps = (100 + p3.lv - e6.lv) / 100 * p3.atk*(1 - e6.def / (2000 + e6.def));
			cout << e6.name << " 造成了 " << dps << " 点伤害。";
			e6.hp -= dps;
			if (e6.hp <= 0){cout << e6.name << "已死亡!" << endl;
			e6.name = "已死亡";
			e6.hp = 0;}
		}
		Sleep(1000);
	}



	//敌方一号
	if (e1.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << e1.name << " 对 ";
		if (p1.hp > 0)
		{
			int dps = (100 + e1.lv - p1.lv) / 100 * e1.atk*(1 - p1.def / (2000 + p1.def));
			cout << p1.name << " 造成了 " << dps << " 点伤害。";
			p1.hp -= dps;
			if (p1.hp <= 0){cout << p1.name << "已死亡!" << endl;
			p1.name = "已死亡";
			p1.hp = 0;}
		}
		else if (p2.hp > 0)
		{
			int dps = (100 + e1.lv - p2.lv) / 100 * e1.atk*(1 - p2.def / (2000 + p2.def));
			cout << p2.name << " 造成了 " << dps << " 点伤害。";
			p2.hp -= dps;
			if (p2.hp <= 0){cout << p2.name << "已死亡!" << endl;
			p2.name = "已死亡";
			p2.hp = 0;}
		}
		else if (p3.hp > 0)
		{
			int dps = (100 + e1.lv - p3.lv) / 100 * e1.atk*(1 - p3.def / (2000 + p3.def));
			cout << p3.name << " 造成了 " << dps << " 点伤害。";
			p3.hp -= dps;
			if (p3.hp <= 0){cout << p3.name << "已死亡!" << endl;
			p3.name = "已死亡";
			p3.hp = 0;}
		}
		else if (p4.hp > 0)
		{
			int dps = (100 + e1.lv - p4.lv) / 100 * e1.atk*(1 - p4.def / (2000 + p4.def));
			cout << p4.name << " 造成了 " << dps << " 点伤害。";
			p4.hp -= dps;
			if (p4.hp <= 0){cout << p4.name << "已死亡!" << endl;
			p4.name = "已死亡";
			p4.hp = 0;}
		}
		else if (p5.hp > 0)
		{
			int dps = (100 + e1.lv - p5.lv) / 100 * e1.atk*(1 - p5.def / (2000 + p5.def));
			cout << p5.name << " 造成了 " << dps << " 点伤害。";
			p5.hp -= dps;
			if (p5.hp <= 0){cout << p5.name << "已死亡!" << endl;
			p5.name = "已死亡";
			p5.hp = 0;}
		}
		Sleep(1000);
	}

	//敌方二号
	if (e2.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << e2.name << " 对 ";
		if (p1.hp > 0)
		{
			int dps = (100 + e2.lv - p1.lv) / 100 * e2.atk*(1 - p1.def / (2000 + p1.def));
			cout << p1.name << " 造成了 " << dps << " 点伤害。";
			p1.hp -= dps;
			if (p1.hp <= 0){cout << p1.name << "已死亡!" << endl;
			p1.name = "已死亡";
			p1.hp = 0;}
		}
		else if (p2.hp > 0)
		{
			int dps = (100 + e2.lv - p2.lv) / 100 * e2.atk*(1 - p2.def / (2000 + p2.def));
			cout << p2.name << " 造成了 " << dps << " 点伤害。";
			p2.hp -= dps;
			if (p2.hp <= 0){cout << p2.name << "已死亡!" << endl;
			p2.name = "已死亡";
			p2.hp = 0;}
		}
		else if (p3.hp > 0)
		{
			int dps = (100 + e2.lv - p3.lv) / 100 * e2.atk*(1 - p3.def / (2000 + p3.def));
			cout << p3.name << " 造成了 " << dps << " 点伤害。";
			p3.hp -= dps;
			if (p3.hp <= 0){cout << p3.name << "已死亡!" << endl;
			p3.name = "已死亡";
			p3.hp = 0;}
		}
		else if (p4.hp > 0)
		{
			int dps = (100 + e2.lv - p4.lv) / 100 * e2.atk*(1 - p4.def / (2000 + p4.def));
			cout << p4.name << " 造成了 " << dps << " 点伤害。";
			p4.hp -= dps;
			if (p4.hp <= 0){cout << p4.name << "已死亡!" << endl;
			p4.name = "已死亡";
			p4.hp = 0;}
		}
		else if (p5.hp > 0)
		{
			int dps = (100 + e2.lv - p5.lv) / 100 * e2.atk*(1 - p5.def / (2000 + p5.def));
			cout << p5.name << " 造成了 " << dps << " 点伤害。";
			p5.hp -= dps;
			if (p5.hp <= 0){cout << p5.name << "已死亡!" << endl;
			p5.name = "已死亡";
			p5.hp = 0;}
		}
		Sleep(1000);
	}

	//敌方三号
	if (e3.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << e3.name << " 对 ";
		if (p1.hp > 0)
		{
			int dps = (100 + e3.lv - p1.lv) / 100 * e3.atk*(1 - p1.def / (2000 + p1.def));
			cout << p1.name << " 造成了 " << dps << " 点伤害。";
			p1.hp -= dps;
			if (p1.hp <= 0){cout << p1.name << "已死亡!" << endl;
			p1.name = "已死亡";
			p1.hp = 0;}
		}
		else if (p2.hp > 0)
		{
			int dps = (100 + e3.lv - p2.lv) / 100 * e3.atk*(1 - p2.def / (2000 + p2.def));
			cout << p2.name << " 造成了 " << dps << " 点伤害。";
			p2.hp -= dps;
			if (p2.hp <= 0){cout << p2.name << "已死亡!" << endl;
			p2.name = "已死亡";
			p2.hp = 0;}
		}
		else if (p3.hp > 0)
		{
			int dps = (100 + e3.lv - p3.lv) / 100 * e3.atk*(1 - p3.def / (2000 + p3.def));
			cout << p3.name << " 造成了 " << dps << " 点伤害。";
			p3.hp -= dps;
			if (p3.hp <= 0){cout << p3.name << "已死亡!" << endl;
			p3.name = "已死亡";
			p3.hp = 0;}
		}
		else if (p4.hp > 0)
		{
			int dps = (100 + e3.lv - p4.lv) / 100 * e3.atk*(1 - p4.def / (2000 + p4.def));
			cout << p4.name << " 造成了 " << dps << " 点伤害。";
			p4.hp -= dps;
			if (p4.hp <= 0){cout << p4.name << "已死亡!" << endl;
			p4.name = "已死亡";
			p4.hp = 0;}
		}
		else if (p5.hp > 0)
		{
			int dps = (100 + e3.lv - p5.lv) / 100 * e3.atk*(1 - p5.def / (2000 + p5.def));
			cout << p5.name << " 造成了 " << dps << " 点伤害。";
			p5.hp -= dps;
			if (p5.hp <= 0){cout << p5.name << "已死亡!" << endl;
			p5.name = "已死亡";
			p5.hp = 0;}
		}
		Sleep(1000);
	}


	//我方四号
	if (p4.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << p4.name << " 对 ";
		if (e1.hp > 0)
		{
			int dps = (100 + p4.lv - e1.lv) / 100 * p4.atk*(1 - e1.def / (2000 + e1.def));
			cout << e1.name << " 造成了 " << dps << " 点伤害。";
			e1.hp -= dps;
			if (e1.hp <= 0){cout << e1.name << "已死亡!" << endl;
			e1.name = "已死亡";
			e1.hp = 0;}
		}
		else if (e2.hp > 0)
		{
			int dps = (100 + p4.lv - e2.lv) / 100 * p4.atk*(1 - e2.def / (2000 + e2.def));
			cout << e2.name << " 造成了 " << dps << " 点伤害。";
			e2.hp -= dps;
			if (e2.hp <= 0){cout << e2.name << "已死亡!" << endl;
			e2.name = "已死亡";
			e2.hp = 0;}
		}
		else if (e3.hp > 0)
		{
			int dps = (100 + p4.lv - e3.lv) / 100 * p4.atk*(1 - e3.def / (2000 + e3.def));
			cout << e3.name << " 造成了 " << dps << " 点伤害。";
			e3.hp -= dps;
			if (e3.hp <= 0){cout << e3.name << "已死亡!" << endl;
			e3.name = "已死亡";
			e3.hp = 0;}
		}
		else if (e4.hp > 0)
		{
			int dps = (100 + p4.lv - e4.lv) / 100 * p4.atk*(1 - e4.def / (2000 + e4.def));
			cout << e4.name << " 造成了 " << dps << " 点伤害。";
			e4.hp -= dps;
			if (e4.hp <= 0){cout << e4.name << "已死亡!" << endl;
			e4.name = "已死亡";
			e4.hp = 0;}
		}
		else if (e5.hp > 0)
		{
			int dps = (100 + p4.lv - e5.lv) / 100 * p4.atk*(1 - e5.def / (2000 + e5.def));
			cout << e5.name << " 造成了 " << dps << " 点伤害。";
			e5.hp -= dps;
			if (e5.hp <= 0){cout << e5.name << "已死亡!" << endl;
			e5.name = "已死亡";
			e5.hp = 0;}
		}
		else if (e6.hp > 0)
		{
			int dps = (100 + p4.lv - e6.lv) / 100 * p4.atk*(1 - e6.def / (2000 + e6.def));
			cout << e6.name << " 造成了 " << dps << " 点伤害。";
			e6.hp -= dps;
			if (e6.hp <= 0){cout << e6.name << "已死亡!" << endl;
			e6.name = "已死亡";
			e6.hp = 0;}
		}
		Sleep(1000);
	}

	//我方五号
	if (p5.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << p5.name << " 对 ";
		if (e1.hp > 0)
		{
			int dps = (100 + p5.lv - e1.lv) / 100 * p5.atk*(1 - e1.def / (2000 + e1.def));
			cout << e1.name << " 造成了 " << dps << " 点伤害。";
			e1.hp -= dps;
			if (e1.hp <= 0){cout << e1.name << "已死亡!" << endl;
			e1.name = "已死亡";
			e1.hp = 0;}
		}
		else if (e2.hp > 0)
		{
			int dps = (100 + p5.lv - e2.lv) / 100 * p5.atk*(1 - e2.def / (2000 + e2.def));
			cout << e2.name << " 造成了 " << dps << " 点伤害。";
			e2.hp -= dps;
			if (e2.hp <= 0){cout << e2.name << "已死亡!" << endl;
			e2.name = "已死亡";
			e2.hp = 0;}
		}
		else if (e3.hp > 0)
		{
			int dps = (100 + p5.lv - e3.lv) / 100 * p5.atk*(1 - e3.def / (2000 + e3.def));
			cout << e3.name << " 造成了 " << dps << " 点伤害。";
			e3.hp -= dps;
			if (e3.hp <= 0){cout << e3.name << "已死亡!" << endl;
			e3.name = "已死亡";
			e3.hp = 0;}
		}
		else if (e4.hp > 0)
		{
			int dps = (100 + p5.lv - e4.lv) / 100 * p5.atk*(1 - e4.def / (2000 + e4.def));
			cout << e4.name << " 造成了 " << dps << " 点伤害。";
			e4.hp -= dps;
			if (e4.hp <= 0){cout << e4.name << "已死亡!" << endl;
			e4.name = "已死亡";
			e4.hp = 0;}
		}
		else if (e5.hp > 0)
		{
			int dps = (100 + p5.lv - e5.lv) / 100 * p5.atk*(1 - e5.def / (2000 + e5.def));
			cout << e5.name << " 造成了 " << dps << " 点伤害。";
			e5.hp -= dps;
			if (e5.hp <= 0){cout << e5.name << "已死亡!" << endl;
			e5.name = "已死亡";
			e5.hp = 0;}
		}
		else if (e6.hp > 0)
		{
			int dps = (100 + p5.lv - e6.lv) / 100 * p5.atk*(1 - e6.def / (2000 + e6.def));
			cout << e6.name << " 造成了 " << dps << " 点伤害。";
			e6.hp -= dps;
			if (e6.hp <= 0){cout << e6.name << "已死亡!" << endl;
			e6.name = "已死亡";
			e6.hp = 0;}
		}
		Sleep(1000);
	}

	//敌方四号
	if (e4.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << e4.name << " 对 ";
		if (p1.hp > 0)
		{
			int dps = (100 + e4.lv - p1.lv) / 100 * e4.atk*(1 - p1.def / (2000 + p1.def));
			cout << p1.name << " 造成了 " << dps << " 点伤害。";
			p1.hp -= dps;
			if (p1.hp <= 0){cout << p1.name << "已死亡!" << endl;
			p1.name = "已死亡";
			p1.hp = 0;}
		}
		else if (p2.hp > 0)
		{
			int dps = (100 + e4.lv - p2.lv) / 100 * e4.atk*(1 - p2.def / (2000 + p2.def));
			cout << p2.name << " 造成了 " << dps << " 点伤害。";
			p2.hp -= dps;
			if (p2.hp <= 0){cout << p2.name << "已死亡!" << endl;
			p2.name = "已死亡";
			p2.hp = 0;}
		}
		else if (p3.hp > 0)
		{
			int dps = (100 + e4.lv - p3.lv) / 100 * e4.atk*(1 - p3.def / (2000 + p3.def));
			cout << p3.name << " 造成了 " << dps << " 点伤害。";
			p3.hp -= dps;
			if (p3.hp <= 0){cout << p3.name << "已死亡!" << endl;
			p3.name = "已死亡";
			p3.hp = 0;}
		}
		else if (p4.hp > 0)
		{
			int dps = (100 + e4.lv - p4.lv) / 100 * e4.atk*(1 - p4.def / (2000 + p4.def));
			cout << p4.name << " 造成了 " << dps << " 点伤害。";
			p4.hp -= dps;
			if (p4.hp <= 0){cout << p4.name << "已死亡!" << endl;
			p4.name = "已死亡";
			p4.hp = 0;}
		}
		else if (p5.hp > 0)
		{
			int dps = (100 + e4.lv - p5.lv) / 100 * e4.atk*(1 - p5.def / (2000 + p5.def));
			cout << p5.name << " 造成了 " << dps << " 点伤害。";
			p5.hp -= dps;
			if (p5.hp <= 0){cout << p5.name << "已死亡!" << endl;
			p5.name = "已死亡";
			p5.hp = 0;}
		}
		Sleep(1000);
	}

	//敌方五号
	if (e5.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << e5.name << " 对 ";
		if (p1.hp > 0)
		{
			int dps = (100 + e5.lv - p1.lv) / 100 * e5.atk*(1 - p1.def / (2000 + p1.def));
			cout << p1.name << " 造成了 " << dps << " 点伤害。";
			p1.hp -= dps;
			if (p1.hp <= 0)
			{
				cout << p1.name << "已死亡!" << endl;
				p1.name = "已死亡";
				p1.hp = 0;
			}
		}
		else if (p2.hp > 0)
		{
			int dps = (100 + e5.lv - p2.lv) / 100 * e5.atk*(1 - p2.def / (2000 + p2.def));
			cout << p2.name << " 造成了 " << dps << " 点伤害。";
			p2.hp -= dps;
			if (p2.hp <= 0)
			{
				cout << p2.name << "已死亡!" << endl;
				p2.name = "已死亡";
				p2.hp = 0;
			}
		}
		else if (p3.hp > 0)
		{
			int dps = (100 + e5.lv - p3.lv) / 100 * e5.atk*(1 - p3.def / (2000 + p3.def));
			cout << p3.name << " 造成了 " << dps << " 点伤害。";
			p3.hp -= dps;
			if (p3.hp <= 0)
			{
				cout << p3.name << "已死亡!" << endl;
				p3.name = "已死亡";
				p3.hp = 0;
			}
		}
		else if (p4.hp > 0)
		{
			int dps = (100 + e5.lv - p4.lv) / 100 * e5.atk*(1 - p4.def / (2000 + p4.def));
			cout << p4.name << " 造成了 " << dps << " 点伤害。";
			p4.hp -= dps;
			if (p4.hp <= 0)
			{
				cout << p4.name << "已死亡!" << endl;
				p4.name = "已死亡";
				p4.hp = 0;
			}
		}
		else if (p5.hp > 0)
		{
			int dps = (100 + e5.lv - p5.lv) / 100 * e5.atk*(1 - p5.def / (2000 + p5.def));
			cout << p5.name << " 造成了 " << dps << " 点伤害。";
			p5.hp -= dps;
			if (p5.hp <= 0) {
				cout << p5.name << "已死亡!" << endl;
				p5.name = "已死亡";
				p5.hp = 0;
			}
		}
		Sleep(1000);
	}

	//敌方六号
	if (e6.hp > 0)
	{
		cout << "行动轮" << i++ << ":";
		cout << e6.name << " 对 ";
		if (p1.hp > 0)
		{
			int dps = (100 + e6.lv - p1.lv) / 100 * e6.atk*(1 - p1.def / (2000 + p1.def));
			cout << p1.name << " 造成了 " << dps << " 点伤害。";
			p1.hp -= dps;
			if (p1.hp <= 0)
			{
				cout << p1.name << "已死亡!" << endl;
				p1.name = "已死亡";
				p1.hp = 0;
			}
		}
		else if (p2.hp > 0)
		{
			int dps = (100 + e6.lv - p2.lv) / 100 * e6.atk*(1 - p2.def / (2000 + p2.def));
			cout << p2.name << " 造成了 " << dps << " 点伤害。";
			p2.hp -= dps;
			if (p2.hp <= 0)
			{
				cout << p2.name << "已死亡!" << endl;
				p2.name = "已死亡";
				p2.hp = 0;
			}
		}
		else if (p3.hp > 0)
		{
			int dps = (100 + e6.lv - p3.lv) / 100 * e6.atk*(1 - p3.def / (2000 + p3.def));
			cout << p3.name << " 造成了 " << dps << " 点伤害。";
			p3.hp -= dps;
			if (p3.hp <= 0)
			{
				cout << p3.name << "已死亡!" << endl;
				p3.name = "已死亡";
				p3.hp = 0;
			}
		}
		else if (p4.hp > 0)
		{
			int dps = (100 + e6.lv - p4.lv) / 100 * e6.atk*(1 - p4.def / (2000 + p4.def));
			cout << p4.name << " 造成了 " << dps << " 点伤害。";
			p4.hp -= dps;
			if (p4.hp <= 0) {
				cout << p4.name << "已死亡!" << endl;
				p4.name = "已死亡";
				p4.hp = 0;
			}
		}
		else if (p5.hp > 0)
		{
			int dps = (100 + e6.lv - p5.lv) / 100 * e6.atk*(1 - p5.def / (2000 + p5.def));
			cout << p5.name << " 造成了 " << dps << " 点伤害。";
			p5.hp -= dps;
			if (p5.hp <= 0) {
				cout << p5.name << "已死亡!" << endl;
				p5.name = "已死亡";
				p5.hp = 0;
			}
		}
		Sleep(1000);
	}

	if (e1.hp <= 0 && e2.hp <= 0 && e3.hp <= 0 && e4.hp <= 0 && e5.hp <= 0 && e6.hp <= 0)
	{
		cout << "对方所有敌人都阵亡了!恭喜你赢得了胜利!" << endl;
		system("pause");
		return 1;	//我们赢了返回1
	}
	else if (p1.hp <= 0 && p2.hp <= 0 && p3.hp <= 0 && p4.hp <= 0 && p5.hp <= 0)
	{
		cout << "我方所有人阵亡了!你失败了。。。。" << endl;
		system("pause");
		return 2;		//我们输了返回2
	}
	else return 0;
}

void combatShow(combat &p1, combat &p2, combat &p3, combat &p4, combat &p5, combat &e1, combat &e2, combat &e3, combat &e4, combat &e5, combat &e6, int i)
{
	using namespace std;
	system("cls");	//清屏
	cout << "****第 " << i << " 回合*************************************************" << endl;
	cout << left;	//向左对齐,空格填充
	cout << "敌人:" << endl;
	cout << setw(5) << " " << "生命:" << setw(18) << e4.hp << "生命:" << setw(18) << e5.hp << "生命:" << e6.hp << endl;
	cout << setw(5) << " " << "名字:" << setw(18) << e4.name << "名字:" << setw(18) << e5.name << "名字:" << e6.name << endl;
	cout << endl;
	cout << setw(5) << " " << "生命:" << setw(18) << e1.hp << "生命:" << setw(18) << e2.hp << "生命:" << e3.hp << endl;
	cout << setw(5) << " " << "名字:" << setw(18) << e1.name << "名字:" << setw(18) << e2.name << "名字:" << e3.name << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	cout << endl;
	cout << "玩家:" << endl;
	cout << setw(5) << " " << "名字:" << setw(18) << p1.name << "名字:" << setw(18) << p2.name << "名字:" << p3.name << endl;
	cout << setw(5) << " " << "生命:" << setw(18) << p1.hp << "生命:" << setw(18) << p2.hp << "生命:" << p3.hp << endl;
	cout << endl;
	cout << setw(15) << " " << "名字:" << setw(20) << p4.name << "名字:" << setw(20) << p5.name << endl;
	cout << setw(15) << " " << "生命:" << setw(20) << p4.hp << "生命:" << setw(20) << p5.hp << endl;
}



//主函数,main函数所在
//源.cpp
#include<iostream>
#include<fstream>
#include<string>
#include <cstdlib> //用于清屏,清屏命令是system("cls")
#include<windows.h> //用于使用延迟函数,具体为Sleep(毫秒),S为大写;
#include <ctime>//这个和下面两个,好像是和随机数有关的
#include <cstdlib>
#include"卡牌.h"

void view(Player & pl);
void openGame(Player & pl);
void GameLoad(Player& pl);
void NewGame(Player& pl);

//应考虑做存档备份(可以考虑用战斗次数增加的作为备份的条件)

//下来应该是换装备,更换上场卡牌


int main()
{
	using namespace std;
	srand(unsigned int(time(0)));//通过系统时间初始化随机数种子
	Player pl;
	openGame(pl);
	view(pl);
	system("pause");
	return 0;
}


登录 后评论
下一篇
云攻略小攻
1446人浏览
2019-10-11
相关推荐
一些值得学习的Unity教程
758人浏览
2016-01-29 10:03:20
iOS7应用开发3、Objective-C
401人浏览
2013-11-10 16:05:15
0
0
1
2683