zippyuk
asked on
Highscore system.
Hi,
I have created a game but am having trouble solving a scoring problem.
Here's my code:
if(!GameOver){bQuit=TRUE;}
else{bQuit=FALSE;}
CRegistry myreg(HKEY_LOCAL_MACHINE);
CString MyKey = TEXT("Software\\TwosUp");
CString m_Hightemp1,m_Hightemp2,m_ Hightemp3, m_Hightemp 4,m_Highte mp5;
myreg.LoadKey(MyKey, TEXT("Highscore1"), m_Hightemp1);
myreg.LoadKey(MyKey, TEXT("Highscore2"), m_Hightemp2);
myreg.LoadKey(MyKey, TEXT("Highscore3"), m_Hightemp3);
myreg.LoadKey(MyKey, TEXT("Highscore4"), m_Hightemp4);
myreg.LoadKey(MyKey, TEXT("Highscore5"), m_Hightemp5);
int m_Highscore1 = atoi(m_Hightemp1);
int m_Highscore2 = atoi(m_Hightemp2);
int m_Highscore3 = atoi(m_Hightemp3);
int m_Highscore4 = atoi(m_Hightemp4);
int m_Highscore5 = atoi(m_Hightemp5);
int Stop = 0;
int WhichCase=0;
if(m_Highscore5<m_iScore && m_Highscore4>=m_iScore)
{
m_Highscore5 = m_iScore;WhichCase=5;Stop = 1;
}
if(Stop==0)
if(m_Highscore4<m_iScore && m_Highscore5>=m_iScore)
{
m_Highscore4 = m_iScore;WhichCase=4;Stop = 1;
}
if(Stop==0)
if(m_Highscore3<m_iScore && m_Highscore4>=m_iScore)
{
m_Highscore3 = m_iScore;WhichCase=3;Stop = 1;
}
if(Stop==0)
if(m_Highscore2<m_iScore && m_Highscore3>=m_iScore)
{
m_Highscore2 = m_iScore;WhichCase=2;Stop = 1;
}
if(Stop==0)
if(m_Highscore1<m_iScore)
{
m_Highscore1 = m_iScore;WhichCase=1;Stop = 1;
}
CString TempString = "";
switch(WhichCase){
case 1: TempString.Format("%d",m_i Score);
myreg.SaveKey(MyKey, TEXT("Highscore1"), TempString);break;
case 2: TempString.Format("%d",m_i Score);
myreg.SaveKey(MyKey, TEXT("Highscore2"), TempString);break;
case 3: TempString.Format("%d",m_i Score);
myreg.SaveKey(MyKey, TEXT("Highscore3"), TempString);break;
case 4: TempString.Format("%d",m_i Score);
myreg.SaveKey(MyKey, TEXT("Highscore4"), TempString);break;
case 5: TempString.Format("%d",m_i Score);
myreg.SaveKey(MyKey, TEXT("Highscore5"), TempString);break;
}
OnOK();
It's the conditional stuff which I can't get right, can anyone help me on this? All I want to do is if current score (m_iScore) is higher than highscore1 set high score1 or if current score is higher than highscore2 but lower than highscore1 set high score2, etc.
There are five slot's for these scores, any help would be appriciated.
I have created a game but am having trouble solving a scoring problem.
Here's my code:
if(!GameOver){bQuit=TRUE;}
else{bQuit=FALSE;}
CRegistry myreg(HKEY_LOCAL_MACHINE);
CString MyKey = TEXT("Software\\TwosUp");
CString m_Hightemp1,m_Hightemp2,m_
myreg.LoadKey(MyKey, TEXT("Highscore1"), m_Hightemp1);
myreg.LoadKey(MyKey, TEXT("Highscore2"), m_Hightemp2);
myreg.LoadKey(MyKey, TEXT("Highscore3"), m_Hightemp3);
myreg.LoadKey(MyKey, TEXT("Highscore4"), m_Hightemp4);
myreg.LoadKey(MyKey, TEXT("Highscore5"), m_Hightemp5);
int m_Highscore1 = atoi(m_Hightemp1);
int m_Highscore2 = atoi(m_Hightemp2);
int m_Highscore3 = atoi(m_Hightemp3);
int m_Highscore4 = atoi(m_Hightemp4);
int m_Highscore5 = atoi(m_Hightemp5);
int Stop = 0;
int WhichCase=0;
if(m_Highscore5<m_iScore && m_Highscore4>=m_iScore)
{
m_Highscore5 = m_iScore;WhichCase=5;Stop = 1;
}
if(Stop==0)
if(m_Highscore4<m_iScore && m_Highscore5>=m_iScore)
{
m_Highscore4 = m_iScore;WhichCase=4;Stop = 1;
}
if(Stop==0)
if(m_Highscore3<m_iScore && m_Highscore4>=m_iScore)
{
m_Highscore3 = m_iScore;WhichCase=3;Stop = 1;
}
if(Stop==0)
if(m_Highscore2<m_iScore && m_Highscore3>=m_iScore)
{
m_Highscore2 = m_iScore;WhichCase=2;Stop = 1;
}
if(Stop==0)
if(m_Highscore1<m_iScore)
{
m_Highscore1 = m_iScore;WhichCase=1;Stop = 1;
}
CString TempString = "";
switch(WhichCase){
case 1: TempString.Format("%d",m_i
myreg.SaveKey(MyKey, TEXT("Highscore1"), TempString);break;
case 2: TempString.Format("%d",m_i
myreg.SaveKey(MyKey, TEXT("Highscore2"), TempString);break;
case 3: TempString.Format("%d",m_i
myreg.SaveKey(MyKey, TEXT("Highscore3"), TempString);break;
case 4: TempString.Format("%d",m_i
myreg.SaveKey(MyKey, TEXT("Highscore4"), TempString);break;
case 5: TempString.Format("%d",m_i
myreg.SaveKey(MyKey, TEXT("Highscore5"), TempString);break;
}
OnOK();
It's the conditional stuff which I can't get right, can anyone help me on this? All I want to do is if current score (m_iScore) is higher than highscore1 set high score1 or if current score is higher than highscore2 but lower than highscore1 set high score2, etc.
There are five slot's for these scores, any help would be appriciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if(m_iScore > m_Highscore1)
{
//New score is highest, reset all scores below it.
m_HighScore5 = m_HighScore4;
m_HighScore4 = m_HighScore3;
m_HighScore3 = m_HighScore2;
m_HighScore2 = m_HighScore1;
m_HighScore1 = m_iScore;
}
else if(m_iScore > m_Highscore2)
{
m_HighScore5 = m_HighScore4;
m_HighScore4 = m_HighScore3;
m_HighScore3 = m_HighScore2;
m_HighScore2 = m_iScore;
}
else if(m_iScore > m_Highscore3)
{
m_HighScore5 = m_HighScore4;
m_HighScore4 = m_HighScore3;
m_HighScore3 = m_iScore;
}
else if(m_iScore > m_Highscore4)
{
m_HighScore5 = m_HighScore4;
m_HighScore4 = m_iScore;
}
else if(m_iScore > m_Highscore5)
{
m_HighScore5 = m_iScore;
}
Then write in all the keys...
Just one other note: You can rewrite your code to be:
if(m_Highscore5<m_iScore && m_Highscore4>=m_iScore)
{
m_Highscore5 = m_iScore;WhichCase=5;
}
else
if(m_Highscore4<m_iScore && m_Highscore3>=m_iScore)
{
m_Highscore4 = m_iScore;WhichCase=4;
}
else
if(m_Highscore3<m_iScore && m_Highscore2>=m_iScore)
{
m_Highscore3 = m_iScore;WhichCase=3;
}
else
if(m_Highscore2<m_iScore && m_Highscore1>=m_iScore)
{
m_Highscore2 = m_iScore;WhichCase=2;
}
else
if(m_Highscore1<m_iScore)
{
m_Highscore1 = m_iScore;WhichCase=1;
}
This way you get rid of the stop variable too. Also note, I corrected some code above...
if(m_Highscore4<m_iScore && m_Highscore3>=m_iScore)
if(m_Highscore3<m_iScore && m_Highscore2>=m_iScore)
if(m_Highscore2<m_iScore && m_Highscore1>=m_iScore)