本文整理汇总了C++中Organism::whoIsThis方法的典型用法代码示例。如果您正苦于以下问题:C++ Organism::whoIsThis方法的具体用法?C++ Organism::whoIsThis怎么用?C++ Organism::whoIsThis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Organism
的用法示例。
在下文中一共展示了Organism::whoIsThis方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: moveAnts
void World::moveAnts()
{
for (int row = 0; row < GRID_HEIGHT; row++)
{
for (int column = 0; column < GRID_WIDTH; column++)
{
Organism *org = &this->getLandscapePosition(row, column);
if (org != NULL)
{
if (org->whoIsThis() == "ant" && org->getMoved() != true)
{
vector<int> newMove = this->getLandscapePosition(row, column).move(this->findAvailSpots(false, row, column));
if (newMove[0] != -1 && newMove[1] != -1)
{
this->setOrganism(&this->getLandscapePosition(row, column), newMove[0], newMove[1]);
this->setOrganism(NULL, row, column);
}
Organism *x = &this->getLandscapePosition(newMove[0], newMove[1]);
if (x != NULL)
{
x->hasMoved();
}
}
} //end null check
} //end for
} //end for
} //end moveAnts
示例2: countLions
//returns the number of lions
int World::countLions()
{
int lions = 0;
for (int row = 0; row < GRID_HEIGHT; row++)
{
for (int column = 0; column < GRID_WIDTH; column++)
{
Organism *org = &this->getLandscapePosition(row, column);
if (org != NULL)
{
if (org->whoIsThis() == "lion")
{
lions++;
}
}
}
}
return lions;
} //end countLions
示例3: countAnts
//returns the number of ants.
int World::countAnts()
{
int ants = 0;
for (int row = 0; row < this->getGridHeight(); row++)
{
for (int column = 0; column < this->getGridWidth(); column++)
{
Organism *org = &this->getLandscapePosition(row, column);
if (org != NULL)
{
if (org->whoIsThis() == "ant")
{
ants++;
}
}
}
}
return ants;
}//end countAnts
示例4: breedAnts
void World::breedAnts()
{
for (int row = 0; row < GRID_HEIGHT; row++)
{
for (int column = 0; column < GRID_WIDTH; column++)
{
Organism *org = &this->getLandscapePosition(row, column);
if (org != NULL)
{
if (org->whoIsThis() == "ant")
{
int lives = org->getTurn();
if (lives >= 3)
{
org->breed();
}
}
}
}
}
} //end breedAnts
示例5: famine
void World::famine()
{
for (int row = 0; row < GRID_HEIGHT; row++)
{
for (int column = 0; column < GRID_WIDTH; column++)
{
Organism *org = &this->getLandscapePosition(row, column);
if (org != NULL)
{
if (org->whoIsThis() == "lion")
{
int lives = org->getLifeCounter();
if (lives > 3)
{
this->setOrganism(NULL, row, column);
}
}
}
}
}
} //end famine
示例6: breedAllAnimals
void World::breedAllAnimals()
{
for (int row = 0; row < GRID_HEIGHT; row++)
{
for (int column = 0; column < GRID_WIDTH; column++)
{
Organism *org = &this->getLandscapePosition(row, column);
if (org != NULL)
{
if (org->getBreedCounter()>0)
{
if (org->whoIsThis() == "ant")
{
//Look For Breeding Ground
if (&this->getLandscapePosition(row + 1, column) == NULL && (row + 1) > 0 && (row + 1) < GRID_HEIGHT)
{
this->setOrganism(new Ant, row + 1, column);
org->resetBreedCounter();
org->resetTurn();
}
else if (&this->getLandscapePosition(row, column + 1) == NULL && (column + 1) > 0 && (column + 1) < GRID_HEIGHT)
{
this->setOrganism(new Ant, row, column + 1);
org->resetBreedCounter();
org->resetTurn();
}
else if (&this->getLandscapePosition(row - 1, column) == NULL && (row - 1) > 0 && (row - 1) < GRID_HEIGHT)
{
this->setOrganism(new Ant, row - 1, column);
org->resetBreedCounter();
org->resetTurn();
}
else if (&this->getLandscapePosition(row, column - 1) == NULL && (column - 1) > 0 && (column - 1) < GRID_HEIGHT)
{
this->setOrganism(new Ant, row, column - 1);
org->resetBreedCounter();
org->resetTurn();
}
else//ant can't breed, resets counters anyway.
{
org->resetBreedCounter();
org->resetTurn();
}
} //end ant
else if (org->whoIsThis() == "lion")
{
//Look For Breeding Ground
if (&this->getLandscapePosition(row + 1, column) == NULL && (row + 1) > 0 && (row + 1) < GRID_HEIGHT)
{
this->setOrganism(new Lion, row + 1, column);
org->resetBreedCounter();
org->resetTurn();
}
else if (&this->getLandscapePosition(row, column + 1) == NULL && (column + 1) > 0 && (column + 1) < GRID_HEIGHT)
{
this->setOrganism(new Lion, row, column + 1);
org->resetBreedCounter();
org->resetTurn();
}
else if (&this->getLandscapePosition(row - 1, column) == NULL && (row - 1) > 0 && (row - 1) < GRID_HEIGHT)
{
this->setOrganism(new Lion, row - 1, column);
org->resetBreedCounter();
org->resetTurn();
}
else if (&this->getLandscapePosition(row, column - 1) == NULL && (column - 1) > 0 && (column - 1) < GRID_HEIGHT)
{
this->setOrganism(new Lion, row, column - 1);
org->resetBreedCounter();
org->resetTurn();
//Diagonal directions
}
else if (&this->getLandscapePosition(row + 1, column + 1) == NULL
&& (column + 1) > 0 && (column + 1) < GRID_HEIGHT
&& (row + 1) > 0 && (row + 1) < GRID_HEIGHT)
{
this->setOrganism(new Lion, row + 1, column + 1);
org->resetBreedCounter();
org->resetTurn();
//.........这里部分代码省略.........