📄 match.cpp
字号:
// Match.cpp: implementation of the CMatch class.
//
//////////////////////////////////////////////////////////////////////
#include "Match.h"
#include "..\System\resfile.h"
#include "..\System\simplememory.h"
#include "..\System\keyinput.h"
#include "..\System\sound.h"
#include "def.h"
#include "CScene.h"
#include "CPlayer.h"
#include "CTenpin.h"
#include "CCameraControl.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMatch::CMatch(CEngine *pEngine)
{
m_pEngine = pEngine;
m_pInput = m_pEngine->GetInput();
m_bPause = false;
m_curPlayer = 0;
m_curPinMode[m_curPlayer] = m_InitPinMode;//(ALL_TENPINS_STAND);
for(int i =0; i< MAX_PLAYER_COUNT; ++i)
{
m_curRound[i] = 0; //m_roundNumber = 0;
m_BallIconID[i] = 0;
m_PlayerClothesID[i] =0;
}
m_iBonusPinState = 0;
m_bnPassed = 0;
m_iGrabId = 0;
//m_iMaxRoundNumber = MAX_ROUND_NUMBER;
}
CMatch::~CMatch()
{
}
void CMatch::Init()
{
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;
//for BONUS MODE //Milo 12-27
//end
}
/*
* Deciding which the next state in this gameplay lifecycle is
*/
bool CMatch::NextDelivery()
{
if (m_bIsFinish)
return m_bIsFinish;
if (m_curRound[m_curPlayer] < (m_RoundCount -1)) //MAX_ROUND_NUMBER)//m_iMaxRoundNumber) // 2)//
{ //go to Player Position
//(there 2 possibilities: a. new rounds ++m_roundNumber, b.the 2 ball in this round)
if (m_Scores[m_curPlayer].m_isStrike) {
++m_curRound[m_curPlayer];
m_Scores[m_curPlayer].m_isStrike = false;
m_Scores[m_curPlayer].m_isSecondBall = false;
}
else
{
if (m_Scores[m_curPlayer].m_isSecondBall)
{
++m_curRound[m_curPlayer];
}
m_Scores[m_curPlayer].m_isSecondBall = !m_Scores[m_curPlayer].m_isSecondBall;
}
}
else { //deal with last round in one match
if (m_Scores[m_curPlayer].m_isBonusShot == 0)
{
if (m_Scores[m_curPlayer].m_isStrike)
{
m_Scores[m_curPlayer].m_isStrike = false;
m_Scores[m_curPlayer].m_isSecondBall = false;
m_Scores[m_curPlayer].m_isBonusShot = 1;
}
else
{
if (m_Scores[m_curPlayer].m_isSecondBall)
{
{
int check = 0x0001;
Byte counter = 0;
for (int i = 0; i < 10; i++) {
if ( ( (m_curPinMode[m_curPlayer] & check) >> i == 1)) { //true for the stand tenpin
counter++;
}
check = check << 1;
}
if(counter == 0)
{
m_Scores[m_curPlayer].m_isBonusShot = 2;
m_Scores[m_curPlayer].m_isSecondBall = false;
}
else
{
++m_curRound[m_curPlayer];
}
}
}
m_Scores[m_curPlayer].m_isSecondBall = !m_Scores[m_curPlayer].m_isSecondBall;
}
}
else
{
if(m_Scores[m_curPlayer].m_isBonusShot == 1)
{
if (m_Scores[m_curPlayer].m_isStrike)
{
m_Scores[m_curPlayer].m_isBonusShot = 2;
}
else
{
if (m_Scores[m_curPlayer].m_isSecondBall == true)
{
++m_curRound[m_curPlayer];
m_Scores[m_curPlayer].m_isSecondBall = false;
m_Scores[m_curPlayer].m_isBonusShot = 0;
}
else
{
m_Scores[m_curPlayer].m_isSecondBall = true;//!m_Scores[m_curPlayer].m_isSecondBall;
}
}
}
else if(m_Scores[m_curPlayer].m_isBonusShot == 2)
{
++m_curRound[m_curPlayer];
m_Scores[m_curPlayer].m_isSecondBall = false;
m_Scores[m_curPlayer].m_isBonusShot = 0;
}
}
}
restart();
///need be changed to Game CLASS when score board is put
if ((m_pInput->KeyPressed(VKEY_SCROLL_LEFT) || m_pInput->KeyHold(VKEY_SCROLL_LEFT)) && m_Scores[m_curPlayer].m_offSet < m_curRound[m_curPlayer] - 5) {
m_Scores[m_curPlayer].m_offSet += 1;
m_Scores[m_curPlayer].m_isScoreBoardChanged = true;
}
if ((m_pInput->KeyPressed(VKEY_SCROLL_RIGHT) || m_pInput->KeyHold(VKEY_SCROLL_RIGHT)) && m_Scores[m_curPlayer].m_offSet > 0) {
m_Scores[m_curPlayer].m_offSet -= 1;
m_Scores[m_curPlayer].m_isScoreBoardChanged = true;
}
return m_bIsFinish;
}
void CMatch::restart()
{
if (m_curRound[m_PlayerCount-1] < m_RoundCount)
{
m_Scores[m_curPlayer].m_isScoreBoardChanged = false;
if (m_Scores[m_curPlayer].m_isSecondBall == false)
{
if(m_Scores[m_curPlayer].m_isBonusShot != 1 && m_Scores[m_curPlayer].m_isBonusShot != 2)
//&& m_curRound[m_curPlayer] < m_RoundCount)
{
++m_curPlayer;
if(m_curPlayer > m_PlayerCount-1)
{
m_curPlayer = 0;
}
}
m_curPinMode[m_curPlayer] = m_InitPinMode;//(ALL_TENPINS_STAND); // defined in CScene Milo 09-27
if(m_iMatchType == MATCH_TYPE_BONUS)
{
//m_Scores[m_curPlayer].m_isSecondBall = true;
}
}
if(m_Scores[m_curPlayer].m_isBonusShot == 2)
{
m_curPinMode[m_curPlayer] = (ALL_TENPINS_STAND);
}
}
else
{
m_bIsFinish = TRUE;
//}
}
}
void CMatch::CalculateAfterCollision()
{
int check = 0x0001;
Byte counter = 0;
for (int i = 0; i < 10; i++) {
if ( ( (m_curPinMode[m_curPlayer] & check) >> i == 1)) { //true for the stand tenpin
counter++;
}
check = check << 1;
}
if (counter == 0 && !m_Scores[m_curPlayer]. m_isSecondBall) {
m_Scores[m_curPlayer].m_isStrike = true;
}
else if (counter == 0)
{
m_bnPassed ++;
}
calculateScore(&m_Scores[m_curPlayer], (Byte) (TOTAL_TENPIN_NUMBER - counter)); //Milo 11-22
// for the money system
if(counter==0)
{
if(m_curPlayer==0)//human
{
//if(!m_Scores[m_curPlayer]. m_isSecondBall || ( && m_Scores[m_curPlayer].strikeCount>0))// strike
if( !m_Scores[m_curPlayer]. m_isSecondBall||
((GetPlayerScore(GetCurPlayer())->iScores == GetRoundCount() * 2+1
&& GetPlayerScore(GetCurPlayer())->strikeCount > 1)
|| (GetPlayerScore(GetCurPlayer())->iScores == GetRoundCount() * 2+1
&& (GetPlayerScore(GetCurPlayer())->scores[GetRoundCount() * 2-1] != 0)
&& (GetPlayerScore(GetCurPlayer())->scores[GetRoundCount() * 2-2] + GetPlayerScore(GetCurPlayer())->scores[GetRoundCount() * 2-1])== 10)))
{
((CGame*)m_pEngine->m_pGame)->updateStrike(((CGame*)m_pEngine->m_pGame)->m_money,matchUpdateStrike,true);
}
else//spare
{
((CGame*)m_pEngine->m_pGame)->updateStrike(((CGame*)m_pEngine->m_pGame)->m_money,matchUpdateSpare,true);
}
}
else
{
//if(!m_Scores[m_curPlayer]. m_isSecondBall||m_Scores[m_curPlayer].strikeCount>0)// strike
if( !m_Scores[m_curPlayer]. m_isSecondBall||
((GetPlayerScore(GetCurPlayer())->iScores == GetRoundCount() * 2+1
&& GetPlayerScore(GetCurPlayer())->strikeCount > 1)
|| (GetPlayerScore(GetCurPlayer())->iScores == GetRoundCount() * 2+1
&& (GetPlayerScore(GetCurPlayer())->scores[GetRoundCount() * 2-1] != 0)
&& (GetPlayerScore(GetCurPlayer())->scores[GetRoundCount() * 2-2] + GetPlayerScore(GetCurPlayer())->scores[GetRoundCount() * 2-1])== 10)))
{
((CGame*)m_pEngine->m_pGame)->updateStrike(((CGame*)m_pEngine->m_pGame)->m_money,matchUpdateStrike,false);
}
else//spare
{
((CGame*)m_pEngine->m_pGame)->updateStrike(((CGame*)m_pEngine->m_pGame)->m_money,matchUpdateSpare,false);
}
}
}
}
bool CMatch::calculateScore(ScoreInfo *scoreInfo, Byte numFallPin)
{
int iScores = scoreInfo->iScores;
bool addSpareScore = scoreInfo->addSpareScore;
int *totalScores = scoreInfo->totalScores;
byte *scores = scoreInfo->scores;
int strikeCount = scoreInfo->strikeCount;
bool addStrikeScore = scoreInfo->addStrikeScore;
bool setAllPinStand = false;
bool isTurkey = false;
//Record the score and start next delivery if game not over
if(iScores <= m_RoundCount * 2 - 2)
{
if((iScores % 2) == 0)
{
scores[iScores] = numFallPin;
//Add append score.
if(addSpareScore)
{
totalScores[iScores / 2 - 1] += scores[iScores];
addSpareScore = false;
}
if(numFallPin == 10)
{
if(++strikeCount == 3)
{
isTurkey = true;
if(iScores / 2 - 2 == 0)
totalScores[iScores / 2 - 2] = 30;
else
totalScores[iScores / 2 - 2] = totalScores[iScores / 2 - 3] + 30;
strikeCount--;
}
addStrikeScore = true;
totalScores[iScores / 2] = -1;
if(iScores == m_RoundCount * 2 - 2)
{
setAllPinStand = true;
iScores++;
}
else
iScores = iScores + 2;
}
else
{
if(strikeCount == 2)
{
if(iScores / 2 - 2 == 0)
totalScores[iScores / 2 - 2] = 20 + numFallPin;
else
totalScores[iScores / 2 - 2] = totalScores[iScores / 2 - 3] + 20 + numFallPin;
strikeCount--;
}
if(iScores == m_RoundCount * 2 - 2) totalScores[iScores / 2] = -1;
iScores++;
}
}
else
{
scores[iScores] = (byte)(numFallPin - scores[iScores - 1]);
//Add append score
if(addStrikeScore)
{
if(strikeCount == 1)
{
if(iScores / 2 - 1 == 0)
totalScores[iScores / 2 - 1] = 10 + numFallPin;
else
totalScores[iScores / 2 - 1] = totalScores[iScores / 2 - 2] + 10 + numFallPin;
}
strikeCount = 0;
addStrikeScore = false;
}
if(numFallPin == 10) addSpareScore = true;
if(iScores / 2 == 0)
totalScores[iScores / 2] = numFallPin;
else
totalScores[iScores / 2] = totalScores[iScores / 2 - 1] + numFallPin;
iScores++;
}
if (m_curPinMode[m_curPlayer] == ALL_TENPINS_FALL || ((iScores % 2) == 0))
setAllPinStand = true;
}
else if(iScores == m_RoundCount * 2 - 1)
{
if(scores[m_RoundCount * 2 - 2] == 10)
{
scores[iScores] = numFallPin;
if(numFallPin == 10)
{
if(++strikeCount == 3)
{
isTurkey = true;
totalScores[m_RoundCount - 2] = totalScores[m_RoundCount - 3] + 30;
strikeCount--;
}
addStrikeScore = true;
}
else
{
if(strikeCount == 2)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -