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


C++ MapInfo::Init方法代码示例

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


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

示例1: StartAttack

int CPlayer::StartAttack( CPlayer* pDefender )
{
	int			destroyCount	= 0;
	int			hitCount		= 0;
	int			turn				= 0;
	int			maxTurn		= MAP_SIZE * MAP_SIZE;
	
	Position		attackPosition = {0, };
	HitResult	result = MISS;
	MapInfo	mapInfo;
	char			string[255] = {0, };

	m_MyMap.InitMapInfo(MI_All);
	InitGuessShipState();

	while(turn < maxTurn)
	{
		mapInfo.Init();
		++turn;

		m_MyMap.InitMapInfo(MI_Probability);

#ifdef TEST_FLAG
		// 공격 결과 출력
		sprintf_s(string, " ");
		CUIManager::GetInstance()->BroadCast(string);
		m_MyMap.DisplayMap(MI_HitResult);
#endif
		// 확률 계산
		CalculateProbability();
		
		// 최대값 찾기
		attackPosition = GetBestPosition();
		result = pDefender->HitCheck(attackPosition);

#ifdef TEST_FLAG
		sprintf_s(string, "    Attack Position : ( %c , %c ) ", attackPosition.x, attackPosition.y);
		CUIManager::GetInstance()->BroadCast(string);
#endif

		switch (result)
		{
		case MISS:
#ifdef TEST_FLAG
			sprintf_s(string, "    Miss! - Turn : %d", turn);
			CUIManager::GetInstance()->BroadCast(string);
			sprintf_s(string, "       - Hit : %d, Destroy : %d", hitCount, destroyCount);
			CUIManager::GetInstance()->BroadCast(string);
#endif
			mapInfo.type = MI_HitResult;
			mapInfo.value.hitResult = MISS;
			m_MyMap.SetMapInfo(attackPosition, mapInfo);

			break;
		case HIT:
			++hitCount;
#ifdef TEST_FLAG
			sprintf_s(string, "    Hit ! - Turn : %d", turn);
			CUIManager::GetInstance()->BroadCast(string);
			sprintf_s(string, "       - Hit : %d, Destroy : %d", hitCount, destroyCount);
			CUIManager::GetInstance()->BroadCast(string);
#endif	
			mapInfo.type = MI_HitResult;
			mapInfo.value.hitResult = HIT;
			m_MyMap.SetMapInfo(attackPosition, mapInfo);

			break;
		case DESTROY_AIRCRAFT:
		case DESTROY_BATTLESHIP:
		case DESTROY_CRUISER:
		case DESTROY_DESTROYER:
		case DESTROY_SUBMARINE:

			mapInfo.type = MI_HitResult;
			mapInfo.value.hitResult = HIT;
			m_MyMap.SetMapInfo(attackPosition, mapInfo);

#ifdef TEST_FLAG
			sprintf_s(string, "    Destroy!!! - Turn : %d", turn);
			CUIManager::GetInstance()->BroadCast(string);
			sprintf_s(string, "      - Hit : %d, Destroy : %d", hitCount, destroyCount);
			CUIManager::GetInstance()->BroadCast(string);
#endif

			// 터진 배 추측
			GuessDestroyedShip(result, attackPosition);
			
			++hitCount;
			++destroyCount;
			if(destroyCount >= sizeof(m_Ships) / sizeof(m_Ships[0]))
			{
#ifdef TEST_FLAG
				m_MyMap.DisplayMap(MI_Probability, attackPosition.x, attackPosition.y);
				pDefender->m_MyMap.DisplayMap(MI_ShipType);
#endif
				sprintf_s(string, "      Victory !!! Turn : %d", turn);
				CUIManager::GetInstance()->BroadCast(string);
#ifdef TEST_FLAG
			
				CUIManager::GetInstance()->Sound(4);
//.........这里部分代码省略.........
开发者ID:zrma,项目名称:PLinCPP,代码行数:101,代码来源:Player.cpp


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