编辑:由于attack.condition 偶尔会有多个值,switch 语句将不起作用!
所以我有这个将会增长的枚举:
enum Condition { Null = 0x0001,
SelfIsUnderground = 0x0002,
SelfIsGround = 0x0004,
SelfIsAir = 0x0008,
SelfIsWater = 0x0010,
OtherIsUnderground = 0x0020,
OtherIsGround = 0x0040,
OtherIsAir = 0x0080,
OtherIsWater = 0x0100,
Tile = 0x0200,
CONDITION_COUNTX = 0x03FF};
这个功能也将增长:
bool Attack::CanBeDone(Spirit* pSelf, Spirit* pTarget,Map* pMap)
{
if(this->condition!=Null)
{
if(this->condition & SelfIsUnderground)
if(pSelf->GetcurrentLayer()!=Underground)
return false;
if(this->condition & SelfIsGround)
if(pSelf->GetcurrentLayer()!=Ground)
return false;
if(this->condition & SelfIsAir)
if(pSelf->GetcurrentLayer()!=Air)
return false;
if(this->condition & SelfIsWater)
if(pSelf->GetcurrentLayer()!=Water)
return false;
if(this->condition & OtherIsUnderground)
if(pTarget->GetcurrentLayer()!=Underground)
return false;
if(this->condition & OtherIsGround)
if(pTarget->GetcurrentLayer()!=Ground)
return false;
...
除了一遍又一遍地写,有没有替代方法:
if(this->condition & arg)
if(pSelf->GetcurrentLayer()!=value)
return false;
?
奖励:如果我给 Condition::Null 值 0x0000、SelfIsUnderground 0x0001、SelfIsGround 0x0002 并再次使用 2 的幂,它会起作用吗?最终,Tile 的值将是 0x0100。