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


C++ CGameManager::GetPlayer方法代码示例

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


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

示例1: MessageProc

// This is the MessageSystem MessageProc. Message handling is done here
void CGameManager::MessageProc(IMessage* pMsg)
{
	CGameManager* pThis = CGameManager::GetInstance();
	// MESSAGE HANDLING
	switch (pMsg->GetMessageID())
	{
	case MSG_SPAWNUNIT:
		{
			CSpawnUnitMessage* pSMSG = dynamic_cast<CSpawnUnitMessage*>(pMsg);
			CUnit* pUnit = (CUnit*)CObjectManager::GetInstance()->CreateObject(pSMSG->GetUnitType(), pSMSG->GetPlayerID() );
			pUnit->SetPos(pSMSG->GetPos());

			if (CTileManager::GetInstance()->GetTile(pSMSG->GetPos().nPosX, pSMSG->GetPos().nPosY)->GetIfOccupied())
			{
				CUnit* pOccupyingUnit = CGameManager::GetInstance()->FindUnit(pSMSG->GetPos());
				if (pOccupyingUnit != pUnit)
				{
					Vec2D newpos = CAIManager::GetInstance()->NearestOpen(pOccupyingUnit->GetPos(), pSMSG->GetPos());
					pUnit->SetPos(pSMSG->GetPos());
					pUnit->AddWaypoint(CTileManager::GetInstance()->GetTile(newpos.nPosX, newpos.nPosY));
				}
			}
			if (CTileManager::GetInstance()->GetTile(pUnit->GetPos().nPosX, pUnit->GetPos().nPosY)->GetIfResourceTile()==true)
			{
				if (CTileManager::GetInstance()->GetTile(pUnit->GetPos().nPosX, pUnit->GetPos().nPosY)->GetIfCaptured())
				{
					if (CTileManager::GetInstance()->GetTile(pUnit->GetPos().nPosX, pUnit->GetPos().nPosY)->GetPlayerID() != pUnit->GetPlayerID())
					{
						CTileManager::GetInstance()->GetTile(pUnit->GetPos().nPosX, pUnit->GetPos().nPosY)->SetStatus(TS_CAPTURING,true);
				CTileManager::GetInstance()->GetTile(pUnit->GetPos().nPosX, pUnit->GetPos().nPosY)->SetPlayerID(pUnit->GetPlayerID());
					}
				}
				else
				{
				CTileManager::GetInstance()->GetTile(pUnit->GetPos().nPosX, pUnit->GetPos().nPosY)->SetStatus(TS_CAPTURING,true);
				CTileManager::GetInstance()->GetTile(pUnit->GetPos().nPosX, pUnit->GetPos().nPosY)->SetPlayerID(pUnit->GetPlayerID());
				}
			}
			pUnit->SetFacing(pSMSG->GetFacing());
			pUnit->SetPlayerID(pSMSG->GetPlayerID());

			CPlayer* pPlayer = CGameManager::GetInstance()->GetPlayer(pSMSG->GetPlayerID());
			switch (pSMSG->GetUnitType())
			{
			case UT_SWORDSMAN:
				pPlayer->GetStats()->nSwordsmanCreated++;
				break;
			case UT_ARCHER:
				pPlayer->GetStats()->nArcherCreated++;
				break;
			case UT_CAVALRY:
				pPlayer->GetStats()->nCalvaryCreated++;
				break;
			}

			if (pSMSG->GetLoaded())
			{
				pUnit->SetHP(pSMSG->GetHealth());
				pUnit->SetTilesMoved(pSMSG->GetTilesMoved());
				pUnit->SetHasAttacked(pSMSG->GetHasAttacked());
				if (pSMSG->GetSpellSize() != 0)
				{
					for (int i = 0; i < pSMSG->GetSpellSize(); ++i)
					{
						((CHero*)pUnit)->SwapSpell(CAbilityManager::GetInstance()->GetAbility(pSMSG->GetSpells(i)), i);
						((CHero*)pUnit)->SetCooldown(i, pSMSG->GetCooldown(i) );
					}

					for (unsigned int i = 0; i < pSMSG->GetBought().size(); ++i)
					{
						((CHero*)pUnit)->SpellBought(CAbilityManager::GetInstance()->GetAbility(pSMSG->GetBought()[i]));
					}
				}
				if (pSMSG->GetEffects().size() != 0)
				{
					for (unsigned int i = 0; i < pSMSG->GetEffects().size(); ++i)
					{
						pUnit->PushEffect(CAbilityManager::GetInstance()->GetAbility(pSMSG->GetEffects()[i]),1);
					}

				}
			}
		}
		break;
	case MSG_DESPAWNUNIT:
		{
			CDespawnUnitMessage* pSMSG = dynamic_cast<CDespawnUnitMessage*>(pMsg);
			if (CGameplayState::GetInstance()->GetSelectedUnit() == pSMSG->GetUnit())
			{
				CGameplayState::GetInstance()->ClearSelections();
			}
			CTile* tile = CTileManager::GetInstance()->GetTile(pSMSG->GetUnit()->GetPos().nPosX, pSMSG->GetUnit()->GetPos().nPosY);

			int nUnitID = pSMSG->GetUnit()->GetUniqueID();
			if (tile != nullptr)
			{
				tile->SetIfOccupied(false);
				if (pSMSG->GetUnit()->GetType() != UT_SKELETON)
					tile->SetIfDeadTile(true);
//.........这里部分代码省略.........
开发者ID:Jon-Stumpfel,项目名称:league-of-champion-craft,代码行数:101,代码来源:GameManager.cpp


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