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


C++ Fleet::getDestinationId方法代码示例

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


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

示例1: reset


//.........这里部分代码省略.........
                break;
            }

            Fleet* fleet = new Fleet(this);
            fleet->setOwner(this->getPlayer(atoi(tokens[1].c_str())));
            fleet->setNumShips(atoi(tokens[2].c_str()));
            fleet->setSourceId(atoi(tokens[3].c_str()));
            fleet->setDestinationId(atoi(tokens[4].c_str()));
            fleet->setTotalTripLength(atoi(tokens[5].c_str()));
            fleet->setTurnsRemaining(atoi(tokens[6].c_str()));

            fleets.push_back(fleet);
            fleetLines.push_back(i);

        } else {
            std::stringstream message;
            message << "Map file error [line " << i
                    << "]: a non-empty line that does not contain a planet or a fleet.";
            this->logError(message.str());
            failed = true;
            break;
        }
    }

    const int numPlanets = static_cast<int>(planets.size());

    //Resolve planet references inside fleets.
    int fleetIndex = 0;

    if (!failed) {
        for (FleetList::iterator it = fleets.begin(); it != fleets.end(); ++it) {
            Fleet* fleet = *it;

            //Attempt to resolve the source planet.
            const int sourceId = fleet->getSourceId();

            if (sourceId < 0 || sourceId >= numPlanets) {
                std::stringstream message;
                message << "Map file error [line " << fleetLines[fleetIndex]
                        << "]: fleet refers to an invalid planet with id=" << sourceId << ".";
                this->logError(message.str());
                failed = true;
                break;

            } else {
                fleet->setSource(planets[sourceId]);
            }

            //Attempt to resolve the destination planet.
            const int destinationId = fleet->getDestinationId();

            if (destinationId < 0 || destinationId >= numPlanets) {
                std::stringstream message;
                message << "Map file error [line " << fleetLines[fleetIndex]
                        << "]: fleet refers to an invalid planet with id=" << destinationId << ".";
                this->logError(message.str());
                failed = true;
                break;

            } else {
                fleet->setDestination(planets[destinationId]);
            }

            //This will force recalculation of the current position.
            fleet->setTurnsRemaining(fleet->getTurnsRemaining());

            ++fleetIndex;
        }
    }

    if (failed) {
        //Clean up.
        for (int i = 0; i < numPlanets; ++i) delete planets[i];
        for (FleetList::iterator it = fleets.begin(); it != fleets.end(); ++it) delete *it;

        return;
    }

    //Parsed the map successfully. Reset the game.
    //Stop any running processes.
    this->stop();
    this->stopPlayers();

    //If didn't fail, replace the old planets and fleets with the new.
    const int numOldPlanets = static_cast<int>(m_planets.size());
    for (int i = 0; i < numOldPlanets; ++i) delete m_planets[i];
    for (FleetList::iterator it = m_fleets.begin(); it != m_fleets.end(); ++it) delete (*it);

    m_planets = planets;
    m_fleets = fleets;
    m_newFleets.insert(m_newFleets.end(), fleets.begin(), fleets.end());

    //Reset all flags and counters.
    m_state = RESET;
    m_turn = 0;

    //Notify everyone of the resetn
    this->logMessage("================= Game reset. ==================");
    emit wasReset();
}
开发者ID:kerzum,项目名称:PlanetWarrior,代码行数:101,代码来源:game.cpp


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