⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myfactory.h

📁 gamecode 很不错的小游戏源代码
💻 H
字号:
//****************************************************************
//作为所有可投资项目的抽象基类
//作者:曾铮
//时间:2004年5月
//说明:游戏中有若干工厂,通过kind类来标识。此类被MyBuilding类继承。
//      具体的成员变量及函数见下。
//*****************************************************************
#ifndef MyFactory_h_
#define MyFactory_h_

//#include "CZDemo.h"
extern void SignFunc(int &num);

#define AUTOFAC		24//汽车制造厂
#define FOODFAC		25//食品厂
#define RESTAURANT	26//酒店
#define MINERFAC	27//矿厂
#define SPINMILL	28//纺纱厂
#define SMELTFAC	36//冶炼厂

#define BEGOVT	9//定义房屋的ower为政府
class MyFactory
{
public:
	int x,y;//在网格中的索引。
	int kind;//表识是什么工厂
	int owner;//表识所属玩家
	long buildcost;//建设费用
	long weekcost;//周消耗
	long income;//额定收入
	int enviaff;//对环境的影响度
	int stability;//收入稳定性
	int aff_rate;//受影响率
	long real_income;//实际收入
	long affe_money;//外界等额外的影响的总值
private:
	void Setincome(int kind);//根据kind来设置income
	void Setstability(int kind);//根据kind来设置stablility
	void Setweekcost(int kind);//
	void Setenviaff(int kind);//
public:
	MyFactory();
	MyFactory(const int& px,const int& py,const int& playerID,const int& fackind);
	MyFactory& operator=(const MyFactory& temp);
	long Normal_Produce();//正常的生产收入(在额定值附近浮动)
	bool ChangeOwner(int playerID);//改变主人
//	long Var_Produce();//受影响而得到的收入
	long Profit();//当月的生产利润值(提总值给玩家)
	long WeekCost();//当月消耗
	virtual ~MyFactory();

};

MyFactory::MyFactory()
{
	this->aff_rate=5;//收入浮动值在5%左右。
	this->income=100;
	this->real_income=150;
	this->kind=FACTORY;
	this->affe_money=0;
	this->aff_rate=5;//收入浮动值在5%左右。
	this->weekcost=20;
}

MyFactory::MyFactory(const int& px,const int& py,const int& playerID,const int& fackind)
{
	this->x=px;
	this->y=py;
	this->owner=playerID;
	this->real_income=150;
	this->affe_money=0;
	this->kind=fackind;//表识为某种工厂
	this->aff_rate=5;//收入浮动值在5%左右。
	this->Setincome(fackind);
	this->Setstability(fackind);
	this->Setweekcost(fackind);
	this->Setenviaff(fackind);
}

void MyFactory::Setincome(int kind)
{
	switch (kind)
	{
	case BUILDFACTORY0://汽车厂
		this->income=125;
		break;
	case BUILDFACTORY1://食品厂
		this->income=30;
		break;
	case BUILDFACTORY2://酒店
		this->income=200;
		break;
	case BUILDFACTORY3://矿厂
		this->income=75;
		break;
	case BUILDFACTORY4://纺织厂
		this->income=40;
		break;
	case BUILDFACTORY5://冶炼厂
		this->income=60;
		break;
	default:
		this->income=50;
		break;
	}
	return;
}

void MyFactory::Setenviaff(int kind)
{
	switch (kind)
	{
	case BUILDFACTORY0://汽车厂
		this->enviaff=-15;
		break;
	case BUILDFACTORY1://食品厂
		this->enviaff=-9;
		break;
	case BUILDFACTORY2://酒店
		this->enviaff=10;//正的,其它都为负
		break;
	case BUILDFACTORY3://矿厂
		this->enviaff=-20;
		break;
	case BUILDFACTORY4://纺织厂
		this->enviaff=-5;
		break;
	case BUILDFACTORY5://冶炼厂
		this->enviaff=-15;
		break;
	default:
		this->enviaff=-10;
		break;
	}
	return;
}

void MyFactory::Setstability(int kind)
{
	switch (kind)
	{
	case BUILDFACTORY0://汽车厂
		this->stability=70;
		break;
	case BUILDFACTORY1://食品厂
		this->stability=90;
		break;
	case BUILDFACTORY2://酒店
		this->stability=30;
		break;
	case BUILDFACTORY3://矿厂
		this->stability=60;
		break;
	case BUILDFACTORY4://纺织厂
		this->stability=75;
		break;
	case BUILDFACTORY5://冶炼厂
		this->stability=60;
		break;
	default:
		this->stability=50;
		break;
	}
	return;
}

void MyFactory::Setweekcost(int kind)
{
	switch (kind)
	{
	case BUILDFACTORY0://汽车厂
		this->weekcost=50;
		break;
	case BUILDFACTORY1://食品厂
		this->weekcost=10;
		break;
	case BUILDFACTORY2://酒店
		this->weekcost=75;
		break;
	case BUILDFACTORY3://矿厂
		this->weekcost=30;
		break;
	case BUILDFACTORY4://纺织厂
		this->weekcost=10;
		break;
	case BUILDFACTORY5://冶炼厂
		this->weekcost=20;
		break;
	default:
		this->weekcost=20;
		break;
	}
	return;
}

MyFactory& MyFactory::operator=(const MyFactory& temp)
{
	this->x=temp.x;
	this->y=temp.y;
	this->owner=temp.owner;
	this->income=temp.income;
	this->kind=temp.kind;
	this->weekcost=temp.weekcost;
	this->real_income=temp.real_income;
	this->aff_rate=temp.aff_rate;
	this->affe_money=temp.affe_money;
	this->enviaff=temp.enviaff;
	return *this;
}

bool MyFactory::ChangeOwner(int playerID)
{
	if(playerID>=0)//有效玩家ID
	{
		this->owner=playerID;
		return true;
	}
	else
		return false;
}

long MyFactory::Normal_Produce()
{
	SignFunc(this->aff_rate);		//决定上涨还是下滑。
	float rate=((float)this->aff_rate)/100;//外界改变影响率
	return (long)((float)this->income*(1+rate));
}

long MyFactory::Profit()
{
	this->real_income=0l;
	this->real_income+=this->Normal_Produce();
	this->real_income+=this->affe_money;
	this->real_income-=this->WeekCost();//减每周消耗
	return this->real_income;
}

long MyFactory::WeekCost()
{
	return this->weekcost;
}

MyFactory::~MyFactory()
{

}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -