As promised, here are my suggestions about the program. The way you tried to implement the exit condition is almost good, but you put this block inside the main loop (LoopGDK):
if (playerChoice > cpuChoice)
{
Playerscore++;
}
else
{
CpuScore++;
}
It's not in a very good place there. What you need is to increment a counter only at the moment when somebody wins. The proper place to handle the counters will be in the winLose() function. Delete this block from the main loop.
The counter variables are not initialized. Always initialize your variables because in C++ they are not guaranteed to be zero!
Instead, they may contain a random garbage value and cause strange bugs. When you declare a variable, give it an initial value:
int Playerscore = 0;
int CpuScore = 0;
To continue playing through several rounds, all you need to do is move your game playing functions inside the main loop:
while ( LoopGDK() && stillPlaying )
{
GamePlay();
cpuPlay();
winLose();
These are at present before the loop. If you put them inside, they will be repeatedly called until you set stillPlaying to false.
There should be dbSync and wait commands after the final announcements, otherwise the program exits without displaying the final result:
if (Playerscore == 5 )
{
dbCLS();
dbWait(200);
dbPrint("YOU WIN");
stillPlaying = false;
dbSync();
dbWait(5000);
}
if (CpuScore == 5 )
{
dbCLS();
dbWait(200);
dbPrint("YOU LOSE!");
stillPlaying = false;
dbSync();
dbWait(5000);
}
dbSync();
} // end of LoopGDK
} // end of program
In the cpuPlay() function, you generate random numbers with dbRnd(2), but this will give numbers between 0-2 and you need numbers between 1-3. Add one to it:
cpuChoice = dbRnd(2) + 1;
In the GamePlay() function, you get the player input:
playerChoice = atoi ( dbInput() );
Dark GDK functions which return a pointer to a string (char*) tend to cause memory leaks because the temporary string does not get deleted. It is better to use such function this way:
char* playerChoiceString = dbInput();
playerChoice = atoi(playerChoiceString);
delete[] playerChoiceString;
The winLose() function tries to determine who won by comparing the choices:
if (playerChoice > cpuChoice)
...
if (playerChoice < cpuChoice)
Unfortunately it's not that simple. Consider what happens when the player chose Scissors (3) and the CPU chose rock (1). The program would say that the player wins, but the CPU should win. The problem is that the comparison is "circular", not linear. (The "if" structure is not completely correct anyway, because I think an "else" is missing from the second block.) I modified the comparisons in this function, and also included incrementing the counters:
void winLose()
{
dbWait(5000);
if (playerChoice == cpuChoice)
{
dbPasteImage(Tie, 0, 0);
}
else if (playerChoice == Rock && cpuChoice == Scissors)
{
dbPasteImage(Win, 0, 0);
Playerscore++;
}
else if (playerChoice == Scissors && cpuChoice == Rock)
{
dbPasteImage(Lose, 0, 0);
CpuScore++;
}
else if (playerChoice > cpuChoice)
{
dbPasteImage(Win, 0, 0);
Playerscore++;
}
else
{
dbPasteImage(Lose, 0, 0);
CpuScore++;
}
dbSync();
}
(Notice also that I put the wait command in the beginning, because if there is something that you execute in every branch in an "if" command, then it is not conditional any more.)
After these changes, I think the program works well. Since I don't have your images, I tested it by printing text on the screen instead, but I did run it several times.
A final remark: the program currently does not have a protection against the user entering an invalid value (a number not between 1-3 or a text that is not a number at all). You might try to validate the user input, this is a bigger task so I don't have a ready-made suggestion, but it would also be a good programming exercise.