当前位置: 首页>>代码示例>>C++>>正文


C++ Organism::whoIsThis方法代码示例

本文整理汇总了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
开发者ID:w0270525,项目名称:CplusplusGameOfLife,代码行数:32,代码来源:World.cpp

示例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
开发者ID:w0270525,项目名称:CplusplusGameOfLife,代码行数:22,代码来源:World.cpp

示例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
开发者ID:w0270525,项目名称:CplusplusGameOfLife,代码行数:22,代码来源:World.cpp

示例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
开发者ID:w0270525,项目名称:CplusplusGameOfLife,代码行数:23,代码来源:World.cpp

示例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
开发者ID:w0270525,项目名称:CplusplusGameOfLife,代码行数:23,代码来源:World.cpp

示例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();
//.........这里部分代码省略.........
开发者ID:w0270525,项目名称:CplusplusGameOfLife,代码行数:101,代码来源:World.cpp


注:本文中的Organism::whoIsThis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。