📄 mymaps.h
字号:
if(kind!=BUIGROUND)
{
return false;
}
int slb=this->pbuilding.listlength();
if(slb!=0)
{
int si=0;
MyBuilding tempb;
while(si++!=slb)
{
this->pbuilding.getelem(si,tempb);
if(tempb.x==x && tempb.y==y && tempb.IsLeveled()==false)
return true;//返回可以升级。
}
return false;//不能升级
}
return false;
}
bool MyMaps::Levelup(int x,int y,int playerid)
{
int slb=this->pbuilding.listlength();
int tempx,tempy;
if(slb!=0)
{
int si=0;
MyBuilding tempb;
while(si++!=slb)
{
this->pbuilding.getelem(si,tempb);
if(tempb.x==x && tempb.y==y && tempb.IsLeveled()==false)
{//找到房子
MyBuilding tempb2;
this->pbuilding.getelem(si,tempb2);
tempb2.Levelup();//改变所属
this->pbuilding.delelem(si);//删除后再加入新建筑在原地方
this->pbuilding.insert(tempb2,si);
int colour;
switch (playerid)//根据不同的角色来建不同颜色的房子
{
case 0:
colour=14;
break;
case 1:
colour=15;
break;
case 2:
colour=16;
break;
case 3:
colour=17;
break;
default:
colour=14;
break;
}
if(this->IsLeveled(this->building[x-1][y],tempb.owner))//路的左边有空。
tempx=x-1,tempy=y;
else if(this->IsLeveled(this->building[x+1][y],tempb.owner) )//路的右边有空。
tempx=x+1,tempy=y;
else if(this->IsLeveled(this->building[x][y-1],tempb.owner))//路的上边有空。
tempx=x,tempy=y-1;
else if(this->IsLeveled(this->building[x][y+1],tempb.owner ))//路的下边有空。
tempx=x,tempy=y+1;
else
return false;
this->building[tempx][tempy]=colour;//修筑。
break;//强行退出循环,只升级一个房子
}
}
return false;//不正常返回
}
return false;
}
bool MyMaps::Build(const int& x,const int& y,const int& playerID,const int& kind)
{
int tempx,tempy;
if(kind==BUIGROUND)
{
if(this->IsSpace(this->building[x-1][y]))//路的左边有空。
tempx=x-1,tempy=y;
else if(this->IsSpace(this->building[x+1][y]) )//路的右边有空。
tempx=x+1,tempy=y;
else if(this->IsSpace(this->building[x][y-1]))//路的上边有空。
tempx=x,tempy=y-1;
else if(this->IsSpace(this->building[x][y+1]) )//路的下边有空。
tempx=x,tempy=y+1;
else
return false;
int colour;
switch (playerID)//根据不同的角色来建不同颜色的房子
{
case 0:
colour=10;
break;
case 1:
colour=11;
break;
case 2:
colour=12;
break;
case 3:
colour=13;
break;
default:
colour=10;
break;
}
this->building[tempx][tempy]=colour;//修筑。
this->AddBuilding(x,y,playerID); //加入建筑链。
return true;
}
else if(kind==BUILDFACTORY0 || kind==BUILDFACTORY1 || \
kind==BUILDFACTORY2 || kind==BUILDFACTORY3 || kind==BUILDFACTORY4 || \
kind==BUILDFACTORY5)
{
// if(10<=building[x-1][y] && building[x-1][y] <=15)//在左
if( this->IsSpacefa(this->building[x-1][y]) )//在左
{
tempx=x-3,tempy=y-1;
this->building[tempx+1][tempy]=100;//提供占位符,供作图时使用。下同
this->building[tempx+2][tempy]=100;
this->building[tempx][tempy+1]=100;
this->building[tempx+1][tempy+1]=100;
this->building[tempx+2][tempy+1]=100;
this->building[tempx][tempy+2]=100;
this->building[tempx+1][tempy+2]=100;
this->building[tempx+2][tempy+2]=100;
}
// else if(10<=building[x+1][y] && building[x+1][y] <=15)//在右
else if(this->IsSpacefa(this->building[x+1][y]) )//在右
{
tempx=x+1,tempy=y-1;
this->building[tempx+1][tempy]=100;//提供占位符,供作图时使用。下同
this->building[tempx+2][tempy]=100;
this->building[tempx][tempy+1]=100;
this->building[tempx+1][tempy+1]=100;
this->building[tempx+2][tempy+1]=100;
this->building[tempx][tempy+2]=100;
this->building[tempx+1][tempy+2]=100;
this->building[tempx+2][tempy+2]=100;
}
// else if(10<=building[x][y-1] && building[x][y-1] <=15)//在上
else if(IsSpacefa(this->building[x][y-1]) )//在上
{
tempx=x-1,tempy=y-3;
this->building[tempx+1][tempy]=100;//提供占位符,供作图时使用。下同
this->building[tempx+2][tempy]=100;
this->building[tempx][tempy+1]=100;
this->building[tempx+1][tempy+1]=100;
this->building[tempx+2][tempy+1]=100;
this->building[tempx][tempy+2]=100;
this->building[tempx+1][tempy+2]=100;
this->building[tempx+2][tempy+2]=100;
}
// else if(10<=building[x][y+1] && building[x][y+1] <=15)//在下
else if(this->IsSpacefa(this->building[x][y+1]) )//在下
{
tempx=x-1,tempy=y+1;
this->building[tempx+1][tempy]=100;//提供占位符,供作图时使用。下同
this->building[tempx+2][tempy]=100;
this->building[tempx][tempy+1]=100;
this->building[tempx+1][tempy+1]=100;
this->building[tempx+2][tempy+1]=100;
this->building[tempx][tempy+2]=100;
this->building[tempx+1][tempy+2]=100;
this->building[tempx+2][tempy+2]=100;
}
else
return false;
this->building[tempx][tempy]=kind;//修筑。在修筑建筑地方的左上角设置标识值。
this->AddFactory(x,y,playerID,this->building[tempx][tempy]); //加入建筑链。
return true;
}
return false;
}
void MyMaps::AddBuilding(const int& x,const int& y,const int& playerID)
{
MyBuilding build(x,y,playerID); //构造一个建筑结点。
this->pbuilding.insert(build,indexb); //加入建筑链。
indexb++;
return;
}
void MyMaps::AddFactory(const int& x,const int& y,const int& playerID,const int& fackind)
{
MyFactory factory(x,y,playerID,fackind);
this->pfactory.insert(factory,indexf);
indexf++;
return;
}
int MyMaps::SearchOwnerB(const int& px,const int& py)
{
int slb=this->pbuilding.listlength();
if(slb==0)
return -1;
else if(slb!=0)
{
int si=0;
MyBuilding tempb;
while(si++!=slb)
{
this->pbuilding.getelem(si,tempb);
if(tempb.x==px && tempb.y==py)
return tempb.owner;//找到一个building主人。
}
return -1;//不正常返回
}
return -1;//不正常返回
}
int MyMaps::SearchOwnerB(const int& px,const int& py,int& index,int& kind)
{
int slb=pbuilding.listlength();
if(slb==0 )
return -1;
else
{
int si=0;
MyBuilding tempb;
while(si++!=slb)
{
this->pbuilding.getelem(si,tempb);
if(tempb.x==px && tempb.y==py)
{
index=si;
return tempb.owner;//找到一个building主人。
}
}
return -1;//不正常返回
}
return -1;//不正常返回
}
int MyMaps::SearchOwnerF(const int& px,const int& py)
{
int slf=this->pfactory.listlength();
if(slf==0)
return -1;
else if(slf!=0)
{
int si=0;
MyFactory tempf;
while(si++!=slf)
{
this->pfactory.getelem(si,tempf);
if(tempf.x==px && tempf.y==py)
return tempf.owner;//找到一个factory主人。
}
return -1;
}
return -1;//不正常返回
}
int MyMaps::SearchOwnerF(const int& px,const int& py,int& index,int& kind)
{
int slf=pfactory.listlength();
if(slf==0)
return -1;
else if(slf!=0)
{
int si=0;
MyFactory tempf;
while(si++!=slf)
{
this->pfactory.getelem(si,tempf);
if(tempf.x==px && tempf.y==py)
{
index=si;
kind=tempf.kind;
return tempf.owner;//找到一个factory主人。
}
}
return -1;
}
return -1;//不正常返回
}
bool MyMaps::ChangeOwnerB(int x,int y,int old_id,int new_id)
{
int index=0;//记录建筑链中的位置
int kind=0;//建筑类型
if(this->SearchOwnerB(x,y)==-1)
return false;//有问题
if(old_id==this->SearchOwnerB(x,y,index,kind))
{
if(kind==0)
{
MyBuilding tempb;
this->pbuilding.getelem(index,tempb);
if(tempb.owner!=old_id)
return false;//有问题
MyBuilding newb(tempb.x,tempb.y,new_id);//必须要这样!!
this->pbuilding.delelem(index);//删除后再加入新建筑在原地方
this->pbuilding.insert(newb,index);
int old_colour=10;
if(tempb.IsLeveled()==false)
{
switch (old_id)
{
case 0:
old_colour=10;
break;
case 1:
old_colour=11;
break;
case 2:
old_colour=12;
break;
case 3:
old_colour=13;
default:
old_colour=10;
break;
}
}
else if(tempb.IsLeveled()==true)
{
switch (old_id)
{
case 0:
old_colour=14;
break;
case 1:
old_colour=15;
break;
case 2:
old_colour=16;
break;
case 3:
old_colour=17;
break;
default:
old_colour=14;
break;
}
}
int colour=10;
switch (new_id)//根据不同的角色来建不同颜色的房子
{
case 0:
colour=10;
break;
case 1:
colour=11;
break;
case 2:
colour=12;
break;
case 3:
colour=13;
break;
default:
colour=old_colour;
}
int tempx=tempb.x;
int tempy=tempb.y;
if(this->building[x-1][y]>=10 && this->building[x-1][y]<=17)//路的左边有空。
tempx=x-1,tempy=y;
else if(this->building[x+1][y]>=10 && this->building[x+1][y]<=17)//路的右边有空。
tempx=x+1,tempy=y;
else if(this->building[x][y-1]>=10 && this->building[x][y-1]<=17)//路的上边有空。
tempx=x,tempy=y-1;
else if(this->building[x][y+1]>=10 && this->building[x][y+1]<=17)//路的下边有空。
tempx=x,tempy=y+1;
else
return false;
this->building[tempx][tempy]=colour;
return true;
}
}
return false;
}
bool MyMaps::ChangeOwnerF(int x,int y,int old_id,int new_id)
{
int index=0;//记录建筑链中的位置
int kind=0;//建筑类型
if(old_id==this->SearchOwnerF(x,y,index,kind))
{
if(kind==BUILDFACTORY0 || kind==BUILDFACTORY1 || \
kind==BUILDFACTORY2 || kind==BUILDFACTORY3 || kind==BUILDFACTORY4 || \
kind==BUILDFACTORY5)
{
MyFactory tempf;
this->pfactory.getelem(index,tempf);
//改变所属
MyFactory newf(tempf.x,tempf.y,new_id,tempf.kind);
this->pfactory.delelem(index);//删除后再加入新建筑在原地方
this->pfactory.insert(newf,index);
return true;
}
}
return false;
}
bool MyMaps::SearchKind(int index,int pkind)
{
MyBuilding tempb;
this->pbuilding.getelem(index,tempb);
if(tempb.kind==pkind)
return true;//确定是这个类型。
return false;
}
int MyMaps::GetLenofFac()
{
// return this->pfactory.listlength();
return this->indexf;
}
int MyMaps::GetLenofHou()
{
// return this->pbuilding.listlength();
return this->indexb;
}
MyBuilding MyMaps::GetBuilding(int playerid)
{
int si=0;
MyBuilding tempb(0,0,-1);//owener=-1为错误
while(si++!=this->pbuilding.listlength())
{
this->pbuilding.getelem(si,tempb);
if(tempb.owner==playerid)
{
return tempb;//返回该建筑
}
}
return tempb;//返回一个错误建筑
}
MyFactory MyMaps::GetFactory(int playerid)
{
int si=0;
MyFactory tempf(0,0,-1,-1);//owern、kind=-1为错误
while(si++!=this->pfactory.listlength())
{
this->pfactory.getelem(si,tempf);
if(tempf.owner==playerid)
{
return tempf;//返回一个工厂
}
}
return tempf;//返回一个错误工厂
}
void MyMaps::GetProfitofB(int playerid,long& tempmoney)
{
MyBuilding tempb;
int sl=this->pbuilding.listlength();//Search Length->sl
if(sl==0)
return;
int si=0;//Search Index->si
while(si++!=sl)
{
this->pbuilding.getelem(si,tempb);
if(tempb.owner==playerid)
{
tempmoney+=tempb.Profit();//主人取得利润
}
}
}
void MyMaps::GetProfitofF(int playerid,long& tempmoney)
{
tempmoney=0;
MyFactory tempf;
int sl=this->pfactory.listlength();//Search Length->sl
if(sl==0)
return;
int si=0;//Search Index->si
while(si++!=sl)
{
this->pfactory.getelem(si,tempf);
if(tempf.owner==playerid)
{
tempmoney+=tempf.Profit();//主人取得利润
tempf.affe_money=0;//结一个月帐以后,受影响值=0
this->pfactory.delelem(si);
this->pfactory.insert(tempf,si);
}
}
}
MyMaps::~MyMaps()
{
for(int i=0;i<64;i++)
{
delete[] path[i];
delete[] building[i];
delete[] block[i];
}
delete[] path;
delete[] building;
delete[] block;
pbuilding.clearlist();
pfactory.clearlist();
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -