Редактировать: поскольку параметр attack.condition будет иметь несколько значений, инструкция switch не будет работать!Есть ли альтернатива этому длинному списку «if argA == argB do ...»?
Так что у меня это перечисление , который будет расти:
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.
Что я могу купить с моими бонусами? – chris
Я не упоминал слово «точки»: p –
Не можете ли вы пройти через значения «enum»? Смотрите это: http://stackoverflow.com/questions/261963/c-iterate-through-an-enum –