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


C++ Country类代码示例

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


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

示例1: addConnection

//Add a new country to the list of adjacent countries
void Country::addConnection(Country &conn)
{
	connections.push_back(conn.getName());
	if (!conn.isAdjacent(name)) {
		conn.addConnection(*this);
	}
}
开发者ID:tv14,项目名称:COMP345-Risk,代码行数:8,代码来源:Country.cpp

示例2: convertCardsToReinforcements

/**
 * @brief Reinforcement phase decision making. Places all reinforcements on the
 * country with the fewest armies.
 */
std::string Strategy::reinforcePhase() {
	RiskMap* map = this->driver->getRiskMap();
	std::string playerName = this->driver->getCurrentPlayerName();

	int minArmies = 10000;
	Country* minArmiesCountry = nullptr;

	// add the reinforcements to the player
	int numCardsSelected = map->getPlayer(playerName)->getCards();
	int armiesEarned = convertCardsToReinforcements(numCardsSelected);
	if (armiesEarned > 0) {
		this->driver->addCardsTradeReinforcements(armiesEarned);
		this->driver->updatePlayerCards(-numCardsSelected);
	}

	// Reinforce the weakest country
	for (const std::string countryName : map->getCountriesOwnedByPlayer(playerName)) {
		Country* country = map->getCountry(countryName);
		int armies = country->getArmies();
		if (armies < minArmies) {
			minArmies = armies;
			minArmiesCountry = country;
		}
	}
	if (minArmiesCountry == nullptr) {
		return "";
	}
	return minArmiesCountry->getName();
}
开发者ID:Taimoorrana1,项目名称:Risk,代码行数:33,代码来源:strategy.cpp

示例3: throw

void HwFederateAmbassador::reflectAttributeValues (
        RTI::ObjectHandle                 theObject,     // supplied C1
  const RTI::AttributeHandleValuePairSet& theAttributes, // supplied C4
  const RTI::FedTime&                     theTime,       // supplied C1
  const char                             *theTag,        // supplied C4
        RTI::EventRetractionHandle        theHandle)     // supplied C1
throw (
  RTI::ObjectNotKnown,
  RTI::AttributeNotKnown,
  RTI::FederateOwnsAttributes,
  RTI::InvalidFederationTime,
  RTI::FederateInternalError)
{
   //-----------------------------------------------------------------
   // Find the Country instance this update is for.  If we can't find
   // it then I am getting data I didn't ask for.
   //-----------------------------------------------------------------
   Country *pCountry = Country::Find( theObject );

   if ( pCountry )
   {
      //-----------------------------------------------------------------
      // Set the new attribute values in this country instance.
      //-----------------------------------------------------------------
      pCountry->Update( theAttributes );
      pCountry->SetLastTime( theTime );
   }
   else
           throw RTI::ObjectNotKnown("received reflection for unknown OID");
}
开发者ID:huidesign,项目名称:Projects,代码行数:30,代码来源:HwFederateAmbassador.cpp

示例4: debug

/**
 * @brief Determines if the countries on the map are a connected graph.
 * @param limitTo Limits the search to the given continent (by string name)
 */
bool RiskMap::isConnectedGraph(const std::string& limitTo) {
	std::map<const Country*, bool> visited = std::map<const Country*, bool>();
	for (auto const &ent1 : this->countries) {
		const Country& country = ent1.second;

		if (limitTo.size() > 0 && this->getContinentOfCountry(country.getName())->getName().compare(limitTo) != 0) {
			continue;
		}

		visited.insert(std::pair<const Country*, bool>(&country, false));
	}

	Country* country = nullptr;
	if (limitTo.size() > 0) {
		country = this->getCountry(*this->getCountriesInContinent(limitTo).begin());
	}
	else {
		country = &this->countries.begin()->second;
	}
	this->isConnectedGraphHelper(visited, country, limitTo);

	for (auto const &ent1 : visited) {
		if (!ent1.second) {
			Country country = *ent1.first;
			debug("Country " + country.getName() + " is not connected.");
			return false;
		}
	}

	return true;
}
开发者ID:Taimoorrana1,项目名称:Risk,代码行数:35,代码来源:risk_map.cpp

示例5: main

int main() {
    string name;
    string capitalcity;
    int population;
    int area;
    Country qveyana;
    vector <Country> v;
    while(ans1 == 'y') {
    cout << "Enter new information" << endl;
    cin >> name;
    cin >> capitalcity;
    cin >> population;
    cin >> area;
    qveyana.setInfo(name,capitalcity,population,area);
    v.push_back(qveyana);
    cout << "Continue? (y/n)" << endl;
    cin >> ans1;
}
        cout << "Enter country name to get information:" << endl;
        cin >> countryname;
        for(int i=0;i<v.size();i++){
                if (v[i].getName()==countryname)
                    cout<<v[i].splittedArea()<<endl;
            }
    return 0;
}
开发者ID:getsadzeg,项目名称:cpp-codes,代码行数:26,代码来源:Countries.cpp

示例6: getContinentFromName

bool World::addCountry(const char* _name, const char* _continent)
{
	lastOperationSuccess = true;
	//We cannot allow 2 times the same name.
	if (getCountryFromName(_name) != NULL)
	{
		lastOperationSuccess = false;
		lastErrorMessage = "The country already exists.";
		return false;
	}

	Continent* continent = getContinentFromName(_continent);

	if (continent == NULL)
	{
		lastOperationSuccess = false;
		lastErrorMessage = "The continent does not exists.";
		return false;
	}

	//Create the object.
	Country* countryObject = new Country(_name, (int)countriesVector->size());
	countryObject->setContinent(continent);

	//Once we have the infos of one, we add it to our vector.
	countriesVector->push_back(countryObject);
	return true;
}
开发者ID:Netopya,项目名称:COMP-345-Project,代码行数:28,代码来源:World.cpp

示例7: while

void MainScreen::allocateArmiesByNumberOfPlayers(const std::string playerName){
	RiskMap* map = this->driver->getRiskMap();
	const int armiesByNumPlayers[] = {40, 35, 30, 25, 20};
	int totalArmies = armiesByNumPlayers[map->getPlayers().size()-2];

	// Create a vector of country pointers for countries the player owns
	std::vector<Country*> playerCountries;
	for (auto const &countryName : map->getCountriesOwnedByPlayer(playerName)) {
		playerCountries.push_back(map->getCountry(countryName));
	}

	// Randomize order of country pointer list
	auto engine = std::default_random_engine{};
	std::shuffle(std::begin(playerCountries), std::end(playerCountries), engine);

	auto playerCountriesIter = playerCountries.begin();
	while (totalArmies > 0) {
		Country* country = *playerCountriesIter;
		country->addArmies(1);
		totalArmies--;
		std::advance(playerCountriesIter, 1);
		if (playerCountriesIter == playerCountries.end()) {
			playerCountriesIter = playerCountries.begin();
		}
	}

	// Signal to update the info widgets.
	for (auto &ent1: map->getPlayers()){
		map->getPlayer(ent1.first)->notifyObservers();
	}
}
开发者ID:Taimoorrana1,项目名称:Risk,代码行数:31,代码来源:mainscreen.cpp

示例8: FindPlace

bool Countries::FindPlace(const char *country_val, const char *place_val,
						  DPoint2 &point)
{
	Country *country;

	int num = m_countries.GetSize();

	int i;
	for (i = 0; i < num; i++)
	{
		country = m_countries[i];

		if (country->m_full.CompareNoCase(country_val) != 0)
			continue;

		bool success = country->FindPlace(place_val, point, true);

		// try again with just the length of the initial sea
		if (!success)
			success = country->FindPlace(place_val, point, false);

		if (success)
			return true;
	}
	return false;
}
开发者ID:kalwalt,项目名称:ofxVTerrain,代码行数:26,代码来源:GEOnet.cpp

示例9: removeCountry

/**
 * @brief Removes a country from the map.
 */
void RiskMap::removeCountry(const Country& country){
	std::string continent = (this->getContinentOfCountry(country.getName()))->getName();
	countries.erase(country.getName());
	if (mapGraph.removeNode(country.getName())){
		continents.erase(continent);
	}
	this->notifyObservers();
}
开发者ID:Taimoorrana1,项目名称:Risk,代码行数:11,代码来源:risk_map.cpp

示例10: while

bool World::pathFindCountry(Country* country1, Country* country2, Player* player)
{
	cout << "DEbug country 1+++++++++++++++++++++++" << country1->getName() << endl;
	cout << "DEbug country 2+++++++++++++++++++++++" << country2->getName() << endl;

	if (country1->getName() == country2->getName() || isCountryAdjacent(country1, country2))
	{
		return true;
	}
	queue<Country*> countryQueue;
	vector<Country*> boardersToCountry1 = country1->getBoarders();
	countryQueue.push(country1);
	while (countryQueue.empty() == false)
	{
		Country* c = countryQueue.front();
		countryQueue.pop();
		if (c->getName() == country2->getName())
		{
			//need to put marked back to false for every country
			//here but map iterator is my enemy
			for (std::map<string, Country*>::iterator it = _territories.begin(); it != _territories.end(); ++it)
			{
				it->second->marked = false;
			}
				
			return true;
		}
		for (int i = 0; i < c->getBoarders().size(); i++)
		{
			vector<Country*> allBoardersToC = c->getBoarders();
			for (int k = 0; k < allBoardersToC.size(); k++)
			{
				for (int j = 0; j < player->getListCountriesOwned().size(); j++)
				{

					if (allBoardersToC.at(k)->getName() == player->getListCountriesOwned().at(j)->getName() && allBoardersToC.at(k)->marked == false)
					{
						countryQueue.push(allBoardersToC.at(k));
					}
				}
			}
		}
	}
	/*for (int i = 0; i < boardersToCountry1.size(); i++)
	{
	for (int j = 0; j < player->getListCountriesOwned().size(); j++)
	{

	if (boardersToCountry1.at(i)->getName() == player->getListCountriesOwned().at(j)->getName())
	{
	return pathFindCountry(boardersToCountry1.at(i), country2, player);
	}
	}
	}*/
}
开发者ID:thomasCM23,项目名称:RiskGame,代码行数:55,代码来源:World.cpp

示例11: mp

QStringList Country::getCountryNames() {
    if (sCountryNames.isEmpty()) {
        Country cc;
        QMetaProperty mp(cc.metaProperty("val"));
        QMetaEnum qmen = mp.enumerator();
        for (int i=0; i<qmen.keyCount(); ++i) {
            sCountryNames += qmen.valueToKey(i);
        }
    }
    return sCountryNames;
}
开发者ID:jabouzi,项目名称:qt,代码行数:11,代码来源:country.cpp

示例12: malloc

void Evaluation::computeConnectedComponents()
{
    // Do not use 42 here as it might change from outside this file
    // Rather obtain the number of countries from Global Settings
    int nb_countries = gs->get_global_settings()->get_countries().size();
    //bool markedCountries[42]; Must be allocated dinamically
    bool* markedCountries = (bool*) malloc (nb_countries * sizeof(bool));

    for(int i=0; i<nb_countries; i++)
    {
        markedCountries[i]=0;
    }

    stack<Country*> pile;
    list<Country*> countries = gs->countries_owned_by(gs->get_current_player());
    for (list<Country*>::iterator it = countries.begin(); it!=countries.end(); ++it)
    {
        markedCountries[(*it)->get_id()]=1;
        pile.push(*it);
    }



    while(!pile.empty()){
        Country* elem = pile.top();
        pile.pop(); // void
        if (markedCountries[elem->get_id()]==0){continue;}
        else{
            stack<Country*> parcours;
            Connected_component* connected_comp = new Connected_component(world_map, gs, probabilities);
            parcours.push(elem);
            while(!parcours.empty()){
                Country* father = parcours.top();
                parcours.pop(); // void
                if(markedCountries[father->get_id()]==0){continue;}
                else{
                    markedCountries[father->get_id()]=0;
                    connected_comp->add(father);

                    set<Country*> sons = (world_map->find(father))->second;

                    for(set<Country*>::iterator son = sons.begin(); son!=sons.end(); ++son)
                    {
                        if(gs->owner(*son) == gs->get_current_player()){
                            parcours.push(*son);
                        }
                    }
                }
            }
            connected_components.push_back(connected_comp);
        }
    }
}
开发者ID:Taimoorrana1,项目名称:risk-1,代码行数:53,代码来源:evaluation.cpp

示例13: undoAction

	void undoAction(AbstractAction::EnvType env)
	{
		int index = env->getCountryIndex();

		Country* country = (*env->getCountries())[index];



		country->setColor(Country::GREY);

		env->setCountryIndex(env->getCountryIndex() - 1);
	}
开发者ID:Loopush,项目名称:Loopop,代码行数:12,代码来源:ColorCountries.cpp

示例14: Country

void MapManager::populateCountryVector() {

	vector<string> adjacents;
	Country newCountry;
	for (int i = 0; i < getMapTerritories().size(); i++) {
		newCountry = Country(getMapTerritories().at(i)[0], getMapTerritories().at(i)[3]);
		adjacents = getAdjacents(i);
		newCountry.setConnections(adjacents);
		countries.push_back(newCountry);
	}


}
开发者ID:mouadbroos,项目名称:COMP345-Risk,代码行数:13,代码来源:MapManager.cpp

示例15: sectionTitle

	/**
	 * Add data from database into list view.
	 */
	void CountriesListScreen::addDataToListView()
	{
		// Clear data from map.
		mCountryMap.clear();

		// Create first section.
		NativeUI::ListViewSection* section = NULL;
		MAUtil::String sectionTitle("A");

		// For each country read create and add an ListViewItem widget.
		int countCountries = mDatabase.countCountries();
		for (int index = 0; index < countCountries; index++)
		{
			// If index is invalid skip this country.
			Country* country = mDatabase.getCountryByIndex(index);
			if (!country)
			{
				continue;
			}

			// If country's name is an empty string skip this country.
			MAUtil::String countryName = country->getName();
			if (countryName.length() == 0)
			{
				continue;
			}

			// Check if current country can go into current section.
			if (!section || countryName[0] != sectionTitle[0])
			{
				// Create new section.
				sectionTitle[0] = countryName[0];
				section = new NativeUI::ListViewSection(
					NativeUI::LIST_VIEW_SECTION_TYPE_ALPHABETICAL);
				section->setTitle(sectionTitle);
				section->setHeaderText(sectionTitle);
				mListView->addChild(section);
			}

			// Create and add list item for this country.
			NativeUI::ListViewItem* item = new NativeUI::ListViewItem();
			item->setText(countryName);
			item->setFontColor(COLOR_WHITE);
			item->setSelectionStyle(NativeUI::LIST_VIEW_ITEM_SELECTION_STYLE_GRAY);
			item->setIcon(country->getFlagID());
			section->addItem(item);

			mCountryMap.insert(item->getWidgetHandle(), country->getID());
		}
	}
开发者ID:Ginox,项目名称:MoSync,代码行数:53,代码来源:CountriesListScreen.cpp


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