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


C++ shared_ptr::AddGold方法代码示例

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


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

示例1: UseAbility

void WarlordState::UseAbility(shared_ptr<Player> &player, shared_ptr<Game> &game)
{
	if (game->GetOpponent(player)->GetBuildings()->Size() >= 8) {
		player->GetClient()->writeline("Your opponent has built 8 or more buildings, you are not allowed to destroy his buildings!");
	}
	else if (game->GetOpponent(player)->HasCharacterCard("Bishop")) {
		player->GetClient()->writeline("Your opponent has the bishop card, you are not allowed to destroy his buildings!");
	}
	else {
		// Print opponent cards
		LookAtOpponent(player, game);

		player->GetClient()->writeline("Which building do you want to destroy?");

		int choice = -1;
		do {
			choice = HandleChoice(player, game, player->GetBuildings()->Size() - 1);
		} while (choice == -1);

		BuildingCard destroy = game->GetOpponent(player)->GetBuildings()->ShowCardByIndex(choice);
		if (destroy.GetName() == "Dungeon")
			player->GetClient()->writeline("A dungeon cannot be destroyed!");
		else {
			if (destroy.GetValue() == 1)
				game->GetOpponent(player)->DestroyByIndex(choice);
			else  {
				int cost = destroy.GetValue() - 1;
				if (player->GetGoldAmount() >= cost) {
					// Player has enough gold to destroy building
					player->RemoveGold(cost);
					game->AddGold(cost);
					BuildingCard card = game->GetOpponent(player)->GetBuildings()->GetCardByIndex(choice);
					
					player->GetClient()->writeline("Building destroyed!");
					
					if (game->GetOpponent(player)->GetGoldAmount() >= 1 && game->GetOpponent(player)->HasBuilding("Graveyard")) {
						game->GetOpponent(player)->RemoveGold(1);
						game->AddGold(1);
						game->GetOpponent(player)->AddBuildingCard(card);
						game->GetOpponent(player)->GetClient()->writeline("The warlord destoyed your " + card.GetName() + ", card returned to your hand");
					}
					else {
						game->GetOpponent(player)->GetClient()->writeline("The warlord destoyed your " + card.GetName() + "!");
						game->AddBuildingCard(card);
					}
				}
				else {
					// Not enough gold to destroy this building
					player->GetClient()->writeline("Not enough gold available to destroy this building!");
				}
			}
		}
	}
}
开发者ID:niekw91,项目名称:Machiavelli,代码行数:54,代码来源:WarlordState.cpp

示例2: Init

void WarlordState::Init(shared_ptr<Player> &player, shared_ptr<Game> &game)
{
	// Receive gold for player color buildings
	int playercolor = Game::Color::RED;
	int playercolorbuildings = 0;
	auto buildings = player->GetBuildings();

	for (auto i = 0, ilen = buildings->Size(); i < ilen; ++i) {
		if (buildings->ShowCardByIndex(i).GetColor() == playercolor)
			++playercolorbuildings;
	}
	if (playercolorbuildings > 0)
		player->AddGold(playercolorbuildings);
	else {
		player->GetClient()->writeline("You do not own any " + GetColor(playercolor) + " buildings and therefore receive no gold");
	}
	if (player->HasBuilding("School of Wizards")) {
		int gold = 1;
		player->AddGold(gold);
		player->GetClient()->writeline("You receive 1 gold coin for the School of Wizards, " + to_string(gold) + " gold received!");
	}
}
开发者ID:niekw91,项目名称:Machiavelli,代码行数:22,代码来源:WarlordState.cpp


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