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


C++ Cube::getInfection方法代码示例

本文整理汇总了C++中Cube::getInfection方法的典型用法代码示例。如果您正苦于以下问题:C++ Cube::getInfection方法的具体用法?C++ Cube::getInfection怎么用?C++ Cube::getInfection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cube的用法示例。


在下文中一共展示了Cube::getInfection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: updateInfectionState

int Map::updateInfectionState( void )
{
  int counter = 0;

  for( int y = 0; y < levels; y++ )
    for( int z = 0; z < height; z++ )
      for(  int x = 0; x < width; x++ )
      {
        int infection = getInfection(x, y, z);
        if(infection < MAX_INFECTION)
          continue;

        Cube *cube;

        for( int i = -1; i < 2; i++ )
          for( int j = -1; j < 2; j++ )
            for( int k = -1; k < 2; k++ )
            {
              if(!i &&!j && !k)
                continue;

              cube = getCube(x+k, y+i, z+j);
              if(cube && !cube->isTransparent())
              {
                int inf = cube->getInfection();
                counter += cube->incInfection() - inf;
              }
            }

        getCube(x,y,z)->setInfection(0);
        getCube(x,y,z)->setTransparent(true);
      }

  return counter;
}
开发者ID:Zaleskiy,项目名称:CubeSimulationLibrary,代码行数:35,代码来源:map.cpp

示例2: makePlan

unsigned char HealAgent::makePlan(Map *map, QList<CubeBasic *> enemy, int coord[])
{
  qDebug() << "Heal step!";

  Cube *cube;
  unsigned char plan = 0;
  for( int y = coord[1]-1; y < coord[1]+2; y++ )
    for( int z = coord[2]-1; z < coord[2]+2; z++ )
      for( int x = coord[0]-1; x < coord[0]+2; x++ )
      {
        cube = map->getCube(x,y,z);
        if(!cube)
          continue;

        if(x == coord[0] && y == coord[1] && z == coord[2])
          continue;

        if(x > coord[0])
          plan = plan | (1 << 4);
        else if(x < coord[0])
          plan = plan | (1 << 5);

        if(y > coord[1])
          plan = plan | (1 << 2);
        else if(y < coord[1])
          plan = plan | (1 << 3);

        if(z > coord[2])
          plan = plan | (1 << 6);
        else if(z < coord[2])
          plan = plan | (1 << 7);

        if(isEnemy(map, enemy, x,y,z))
        {
          plan = plan | 3;

          return plan;
        }

        if(cube->getInfection())
        {
          plan = plan | 1;

          return plan;
        }

        plan = 0;
      }


  int i, j, k;
  cube = NULL;
  while(!cube)
  {
    i = qrand() % 3 - 1;
    j = qrand() % 3 - 1;
    k = qrand() % 3 - 1;

    if(i > 1)
      i = 1;
    if(j > 1)
      j = 1;
    if(k > 1)
      k = 1;

    if(!i && !j && !k)
      continue;

    cube = map->getCube(coord[0] + i, coord[1] + j, coord[2] + k);
    qDebug() << "CUBE: " << cube << coord[0] + i << coord[1] + j << coord[2] + k;
    if(!cube)
      continue;

    if(!cube->isTransparent())
      cube = NULL;
  }

  plan = 0;
  if(k == -1)
    plan = plan | (1 << 7);
  if(k == 1)
    plan = plan | (1 << 6);

  if(i == -1)
    plan = plan | (1 << 5);
  if(i == 1)
    plan = plan | (1 << 4);

  if(j == -1)
    plan = plan | (1 << 3);
  if(j == 1)
    plan = plan | (1 << 2);

  setPlan(plan);

  return plan;
}
开发者ID:zmactep,项目名称:CubeSimulationLibrary,代码行数:97,代码来源:healagent.cpp


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