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

Posted qq20004604

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了卡牌游戏源代码(原创)(控制台)相关的知识,希望对你有一定的参考价值。

游戏预览:




完成度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 << "无法打开你要购买的装备列表,请反馈给技

以上是关于卡牌游戏源代码(原创)(控制台)的主要内容,如果未能解决你的问题,请参考以下文章

cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第一步---開始界面&amp;关卡选择

原创Steam极度好评推荐,超耐玩卡牌游戏《Ratropolis》

CSDN实训 - 通过Java修改游戏存档

Unity + Mirror实现原创卡牌游戏局域网联机

Unity3D_(游戏)卡牌03_选关界面

C1认证:任务一01-修改游戏存档和金币