mybuilding.h

来自「gamecode 很不错的小游戏源代码」· C头文件 代码 · 共 124 行

H
124 行
字号
//************************************************************
//建房类
//作者:曾铮
//时间:2004年6月
//说明: 作为游戏中民用房的类。
//************************************************************
#ifndef MyBuilding_h_
#define MyBuilding_h_

#include "MyFactory.h"

class MyBuilding:public MyFactory
{
public:
	int x,y;//在网格中的索引。
	int owner;//所属玩家。
	int income;//产生的收入。
	int kind;//房屋类型
	int leveled;//升级版
	long levelupc;//升级消耗

public:
	MyBuilding();
	MyBuilding(const int&x,const int&y ,const int& playerID);//在某个地方有属于某个玩家的房子。
	long Profit();//产生的利润。
	MyBuilding& operator=(const MyBuilding& temp);//用于在建筑链中使用。
	long GetPrice();//取得费用
	bool Levelup(long money);//升级
	bool Levelup();//升级
	bool IsLeveled();//判断是否已升级
	bool ChangeOwner(int playerid);//改变主人
	virtual ~MyBuilding();
};

MyBuilding::MyBuilding()
{
	this->buildcost=20;
	this->leveled=0;
	this->levelupc=50l;
	this->kind=BUILDING;//一般房屋
	this->income=2;
}

long MyBuilding::GetPrice()
{
	return this->buildcost;
}

bool MyBuilding::Levelup(long money)
{
	if(money>this->levelupc)
	{
		this->leveled=1;
		this->buildcost=50l;
		this->income=10;
		return true;
	}
	else
		return false;
}
bool MyBuilding::ChangeOwner(int playerID)
{
	if(playerID>=0)//有效玩家ID
	{
		this->owner=playerID;
		return true;
	}
	else
		return false;
}
bool MyBuilding::Levelup()
{
	
	this->leveled=1;
	this->buildcost=50l;
	this->income=5;
	return true;
	
}

bool MyBuilding::IsLeveled()
{
	if(this->leveled==0)
		return false;
	else
		return true;
}

MyBuilding::MyBuilding(const int& px,const int& py,const int& playerID)
{
	this->leveled=0;
	this->buildcost=20;
	this->x=px;
	this->y=py;
	this->owner=playerID;
	this->income=2;
	this->kind=BUILDING;//表识为一般房屋
}

MyBuilding& MyBuilding::operator=(const MyBuilding& temp)
{
	this->x=temp.x;
	this->y=temp.y;
	this->owner=temp.owner;
	this->income=temp.income;
	this->kind=temp.kind;
	this->leveled=temp.leveled;
	return *this;
}

long MyBuilding::Profit() 
{
	return this->income;//收稳定,无变化
}

MyBuilding::~MyBuilding()
{

}




#endif

⌨️ 快捷键说明

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