⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 match.cpp

📁 一个3D的保龄球的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					totalScores[m_RoundCount - 2] = totalScores[m_RoundCount - 3] + 20 + numFallPin; //+ numFallPin ADDED BY MILO 01-26
					strikeCount--;
				}
				iScores++;
			}
		}
		else
		{
			scores[iScores] =(byte)(numFallPin - scores[iScores - 1]);
			
			//Add append score
			if(addStrikeScore)
			{
				if(strikeCount == 1)
				{
					totalScores[m_RoundCount - 2] = totalScores[m_RoundCount - 3] + 10 + numFallPin;
				}
				strikeCount = 0;
				addStrikeScore = false;
			}
			
			if(numFallPin != 10)
			{
				totalScores[m_RoundCount - 1] = totalScores[m_RoundCount - 2] + numFallPin;
				iScores+=2;
				totalScores[m_RoundCount] = totalScores[m_RoundCount - 1];
				setAllPinStand = true;
			}
		}
		
		if(numFallPin == 10)
		{
			iScores++;
			setAllPinStand = true;
		}
		
    }
    else if(iScores == m_RoundCount * 2)
    {
		if(scores[iScores - 2] == 10 && scores[iScores - 1] != 10)
		{
			scores[iScores] =(byte)(numFallPin - scores[iScores - 1]);
		}
		else
			scores[iScores] = numFallPin;

		//for last turkey Milo 02-16
		if(numFallPin == 10 && ++strikeCount == 3)
		{				
			isTurkey = true;				
			strikeCount--;
		}		
		totalScores[m_RoundCount - 1] = totalScores[m_RoundCount - 2] + scores[iScores - 2] + scores[iScores - 1] + scores[iScores];
		
		//strikeCount = 0;
		strikeCount--; // Milo 04-06
		addStrikeScore = false;
		iScores++;
		setAllPinStand = true;
		totalScores[m_RoundCount] = totalScores[m_RoundCount - 1];
    }
    else if(iScores == m_RoundCount * 2 + 1)
    {
		strikeCount = 0;
		setAllPinStand = true;
		totalScores[m_RoundCount] = totalScores[m_RoundCount - 1];
    }
	
    //Record the current score information.
    scoreInfo->iScores = iScores;
    scoreInfo->addSpareScore = addSpareScore;
    scoreInfo->strikeCount = strikeCount;
    scoreInfo->addStrikeScore = addStrikeScore;
	scoreInfo->m_isTurkey = isTurkey;
	scoreInfo->preciseScore = getCurrentTotalScore(scoreInfo);
    return setAllPinStand;
}

// ************************************************************
// ************************************************************
/* Initialize the Scoreinfo struct.
* scoreInfo
* The score information.
*/
void CMatch::iniScoreInfo(ScoreInfo &scoreInfo)
{
	int i=0;
	scoreInfo.iScores = 0;
	scoreInfo.addSpareScore = false;
	scoreInfo.addStrikeScore = false;
	scoreInfo.strikeCount = 0;
	scoreInfo.totalScores[10] = -1;
	scoreInfo.trunPageNum = 0;
	for (i = 0; i < 10; i++)
	  scoreInfo.totalScores[i] = 0;
	for (i = 0; i < 21; i++)
	  scoreInfo.scores[i] = 0;

	scoreInfo.m_isSecondBall = false;
	scoreInfo.m_isStrike = false;
	scoreInfo.m_isTurkey = false;
	scoreInfo.m_isBonusShot = 0;
	scoreInfo.m_offSet = 0;
	scoreInfo.m_isScoreBoardChanged = false;
	scoreInfo.preciseScore = 0;
	scoreInfo.extraCount = 0;
	scoreInfo.extraScore = 0;
}

void CMatch::SetMatchType(int type)
{
	m_iMatchType=type;
}


void CMatch::InitMatch(byte roundCount, byte playerCount)
{
	int i;
	m_RoundCount=roundCount;
	m_PlayerCount=playerCount;
	for(i=0;i<m_PlayerCount;i++)
		m_PlayersAI[i]=0;
	m_bIsFinish = FALSE;
	m_bIsDrawFinish = false;
	m_curPlayer = 0;
	m_curPinMode[m_curPlayer] = m_InitPinMode;//(ALL_TENPINS_STAND);
	for(i =0; i< MAX_PLAYER_COUNT; ++i)
	{
		m_curRound[i] = 0; //m_roundNumber = 0;
	}
	m_bnPassed = 0;
}

void CMatch::LoadMatchRes(CDataManager *pMgr,int step)
{
	int i=step;
	if(step<m_PlayerCount)
	{
		m_player[i].SetClothesId(pMgr->LoadPlayerRes(m_Players[i],m_PlayerClothesID[i]));
		pMgr->LoadBallRes(m_PlayerBall[i]);
	}
	else
	switch(step-m_PlayerCount)
	{
	case 0:
		m_iGrabId = pMgr->LoadBgRes(m_LaneId);
		pMgr->GetRender3D()->GetG3d()->LoadTexture(pMgr->m_pStringItem[ID_TV_TEXTURE_FILENAME], 0);
		pMgr->LoadModel(MODEL_TV);				//Milo 02-24
		break;

	case 1:
//		pMgr->LoadModel(MODEL_ARROW);
		pMgr->LoadModel(MODEL_TENPIN);
		break;

	case 2:
		pMgr->LoadModel(MODEL_GRBBING);
		break;

	case 3:
		pMgr->LoadModel(MODEL_SETTING_PINS);
		break;

	case 4:
		pMgr->LoadModel(MODEL_2D_TENPIN);
		break;

	case 5:
//		pMgr->LoadModel(MODEL_AUD1);
//		pMgr->LoadModel(MODEL_AUD2);
//		pMgr->LoadModel(MODEL_AUD3);
//		pMgr->LoadModel(MODEL_FREEZE_AUD);
		pMgr->LoadModel(MODEL_COIN);
		break;

	case 6:
		pMgr->LoadCoinTexture();
		break;

	default:
		break;
	}
	

}



void CMatch::SwitchToFinish(int cheatMode)
{	
	int score = 0;
	int num = 0;
	
	//for(i=m_curRound[m_curPlayer]; i<m_RoundCount;++i)
	while(m_bIsFinish != TRUE)
	{		
		num = 0;
		if(	m_Scores[m_curPlayer].m_isSecondBall == false)
		{
			score = setImmediateComResult(num);
			SetCurDevliveryResult(score);
		}

		CalculateAfterCollision();
		NextDelivery();
	}
}

int CMatch::setImmediateComResult(int& count)
{
	int random;
	int ret = 0;
	int m = 0x0001;
	//int count = 0;

	for (int i = 0; i < 10; ++i) 
	{	
		random = getRandomNumber(10) & 0x7fffffff;
		if(random > 3)
		{
			++count;
			ret += (m << i);
			m = 0x0001;
		}
	}	
	return ret;
}

int CMatch::getCurrentTotalScore(ScoreInfo *scoreInfo)
{
  int score = 0;
    if(scoreInfo->iScores >= 2)
    {
      if(scoreInfo->iScores == m_RoundCount * 2)
        score = scoreInfo->totalScores[scoreInfo->iScores/2 - 2] + scoreInfo->scores[scoreInfo->iScores - 1] + scoreInfo->scores[scoreInfo->iScores - 2];
      else
        score = scoreInfo->totalScores[scoreInfo->iScores/2 - 1];
      if((scoreInfo->iScores < m_RoundCount * 2) && (scoreInfo->totalScores[scoreInfo->iScores/ 2 - 1] == -1 || scoreInfo->addSpareScore))
      {
        score = 10;
        if(scoreInfo->iScores >= 4)
        {
          if(scoreInfo->totalScores[scoreInfo->iScores / 2 - 2] == -1)
          {
            score += 20;
            if(scoreInfo->iScores >= 6)
              score += scoreInfo->totalScores[scoreInfo->iScores / 2 - 3];
          }
          else
            score += scoreInfo->totalScores[scoreInfo->iScores / 2 - 2];
        }
        if(scoreInfo->iScores % 2 != 0)
          score += scoreInfo->scores[scoreInfo->iScores - 1];
      }
      if(scoreInfo->iScores%2 != 0 && (scoreInfo->iScores != m_RoundCount * 2 + 1)) score += scoreInfo->scores[scoreInfo->iScores - 1]; //yjf 2004-12-27 for score error
    }
    else
    {
      if(scoreInfo->iScores == 1) score = scoreInfo->scores[0];
    }
    return score;
}





//// << ====================================================================================
//// 2005.1.12 YI WEN HU
// set all players' score into 0, and do not change other variables of match
void CMatch::ResetScoreRecord()
{
	int i=0;
	for(i =0; i< MAX_PLAYER_COUNT; ++i)
	{
		m_curRound[i] = 0; //m_roundNumber = 0;
	}
	m_curPlayer = 0;
	m_curPinMode[m_curPlayer] = m_InitPinMode;//(ALL_TENPINS_STAND);
	//11-30 Milo
	for(i=0; i< MAX_PLAYER_COUNT; ++i)
	{
		iniScoreInfo(m_Scores[i]);
	}
	m_MatchResult=-1;
	m_bIsFinish=false;

}


// skip a level
// jump into next delivery, called in bonus mode
void CMatch::SkipDelivery()
{
		m_iBonusPinState = m_InitPinMode;
		CalculateAfterCollision();
		NextDelivery();
}

//// >> ====================================================================================



bool CMatch::ExtraNext()
{
	bool ret = true;

	++m_curPlayer;
	if(m_curPlayer > m_PlayerCount-1)
	{
		m_curPlayer = 0;
		ret = false;
		m_bIsDrawFinish = true;
	}	
	else
	{
		m_curPinMode[m_curPlayer] = (ALL_TENPINS_STAND); 
	}
	//m_bIsFinish = !ret;
	return ret;
}

void CMatch::SetExtraResult(int pinMode)
{
	int check = 0x0001;
	Byte counter = 0;	
	m_Scores[m_curPlayer].extraScore = 0;
	
	for (int i = 0; i < 10; i++) {
        if ( ( (pinMode & check) >> i == 1)) { //true for the stand tenpin
			counter++;
        }
        check = check << 1;
	}	
	m_Scores[m_curPlayer].extraScore = (TOTAL_TENPIN_NUMBER - counter);  //Milo 11-22
	m_Scores[m_curPlayer].extraCount += m_Scores[m_curPlayer].extraScore;
}



void CMatch::JumpToNextRound()
{
	int score = 0;
	int num = 0;
	int round1 = m_curRound[m_curPlayer];
	int round2 = m_curRound[m_curPlayer];
 	
	
	while (round1 == round2)
	{
		if(	m_Scores[m_curPlayer].m_isSecondBall == false)
		{
				score = setImmediateComResult(num);		
			SetCurDevliveryResult(score);
		}
		CalculateAfterCollision();
		NextDelivery();		
		round2 = m_curRound[m_curPlayer];//MAX_PLAYER_COUNT-1];
	}
}

void CMatch::skipHumanRound()
{
	if(m_Scores[m_curPlayer].m_isSecondBall == false||(!m_Scores[m_curPlayer].m_isStrike))// not finish the game
	{
		SetCurDevliveryResult(ALL_TENPINS_STAND);				
		CalculateAfterCollision();
		NextDelivery();		
	}
	SetCurDevliveryResult(ALL_TENPINS_STAND);				
	CalculateAfterCollision();
	NextDelivery();
}




void CMatch::finishOnlineGame()
{	
	
	while(m_bIsFinish != TRUE)
	{		
		if(	m_Scores[m_curPlayer].m_isSecondBall == false)
		{
			SetCurDevliveryResult(ALL_TENPINS_STAND);
		}

		CalculateAfterCollision();
		NextDelivery();
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -