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


C++ Floor::hasUpRiders方法代码示例

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


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

示例1: if

Building& Building::step(int numRiders) // moves elevators and riders each second. numRiders = riders to randomly add to floors
{
  int count = 0; // screen counter for pausing.


  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  //@@@@@@@@@@@@@@@@@@@@@@                 Riders                @@@@@@@@@@@@@@@@@@@@@@@@@@@
  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  for (int i=0; i < numRiders; i++) // add riders on random floors
  {
    int randomStartFloor = rand() % buildingFloors.size(); // random number from 0 to buildingFloors max
    int randomDestinationFloor = rand() % buildingFloors.size(); // random number from 0 to buildingFloors max

    if (randomStartFloor == 0) // Basement case - no down
    {
      randomDestinationFloor = rand() % (buildingFloors.size()-1) + 1; // random number from 1 to (buildingFloors max -1)
    }
    else if (randomStartFloor == buildingFloors.size()) // Top case - no up
    {
      randomDestinationFloor = rand() % (buildingFloors.size()-1); // random number from 0 to (buildingFloors max -1)
    }
    else
    {
      while (randomDestinationFloor == randomStartFloor) // make sure starting != destination floor
      {
        randomDestinationFloor = rand() % buildingFloors.size();
      }
    }
    buildingFloors[randomStartFloor]->addNewRider(Rider(*buildingFloors[randomDestinationFloor])); // add rider on rand floor w/ rand dest.
  } // end for (adding riders to random floors)


  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  //@@@@@@@@@@@@@@@@@@@@@@                Elevator               @@@@@@@@@@@@@@@@@@@@@@@@@@@
  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  for (int i = 0; i<buildingElevators.size(); i++) // checking all elevators one by one [3]
  {
    if (buildingElevators[i]->isDoorOpen() == false) // if doors are closed [3]
    {
      if (!buildingElevators[i]->isNearDestination()) // executed if elevator is not near destination [3]
      {
        if (buildingElevators[i]->isDirectionUp()) buildingElevators[i]->moveUp(); // move up [3]
        else if (buildingElevators[i]->isDirectionDown()) buildingElevators[i]->moveDown(); // move down [3]
      } // end 'if not near destination' loop

      else if (buildingElevators[i]->isNearDestination()) // if elevator is near to destination [4]
      {
        buildingElevators[i]->moveToDestinationFloor(); // [4]
        buildingElevators[i]->openDoor(); // [4]
        {
          buildingElevators[i]->removeRidersForDestinationFloor();// remove riders; ignore returned vector of removed riders [4]
        } // "{}" & cout are temp

        Floor* elevatorsCurrentFloor = const_cast<Floor*>(&(buildingElevators[i]->getDestination())); // [5]

        if (buildingElevators[i]->hasRiders() == false) // if elevator is empty [5]
        {
          if (elevatorsCurrentFloor->isPreferredDirectionUp() == true) // if floor direction = up [5]
          {
            buildingElevators[i]->setDirectionUp();
          }
          else // if floor direction != up [5]
          {
            buildingElevators[i]->setDirectionDown();
          }
        } // end if elevator = empty

        if (buildingElevators[i]->getAvailableSpace()!=0) // if space in elevator, board riders [6]
        {
          if (buildingElevators[i]->isDirectionUp() == true) // if the elevator is going up
          {
            if (elevatorsCurrentFloor->hasUpRiders() == true) // if there are up riders on the floor
            {
              buildingElevators[i]->addRiders(elevatorsCurrentFloor->removeUpRiders(buildingElevators[i]->getAvailableSpace())); // board up-riders [6]
            } // end if (has up riders)
          } // end if elevator direction == up
          else // for down elevators
          {
            if (elevatorsCurrentFloor->hasDownRiders() == true) // if there are down riders on the floor
            {
              buildingElevators[i]->addRiders(elevatorsCurrentFloor->removeDownRiders(buildingElevators[i]->getAvailableSpace()));// board down-riders [6]
            } // end if (has down riders)
          } // end else (for down riders)
        } // end if space in elevator

        buildingElevators[i]->setDestinationBasedOnRiders(); //reassess elevator's destination based on riders [8]
      } // end if 'near destination' loop
    } // end 'if elevator doors are closed' loop


    else // "isDoorOpen() == true" (it already let off riders, or is in its initial state) [7]
    {
      if (buildingElevators[i]->hasRiders() == true) // has riders [7]
      {
        buildingElevators[i]->closeDoor(); // close door [7]
      } // end if has riders
      else // if no riders
      {
//.........这里部分代码省略.........
开发者ID:yutuotuo,项目名称:OOP-in-CPP,代码行数:101,代码来源:Building.cpp


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