編集: 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 になります。