Code:
void PlayGame()
{
InitRandGen();
enum Status { CONTINUE, WON, LOST };
Status GameStatus; // controls individual game
bool quit = false; // controls game loop
HSEntry HighScores[5]; // high scores table
memset(HighScores,0,5*sizeof(HSEntry)); // zero hs table
ReadHS(HighScores);
maximise();
cursoroff();
PrintHS(HighScores);
WelcomeScreen();
long Savings = 10; // This is the players cash. $10 to start.
int Die1 = 0, Die2 = 0; // The dice
int Sum = 0; // total of dice
int Stake = 0; // The bet.
int Point = 0; // The point to make if needed
int HouseWins = 0, PlayerWins = 0;
while (!quit)
{
StatScreen(Die1, Die2, Sum, Stake, Savings, Point, HouseWins, PlayerWins);
if (Savings == 0) // out of money
{
gotoxy(0,8);
colour(BBLUE | TLTYELLOW);
cout << "YOU ARE OUT OF MONEY !!!!! LOSER!!!!! Loser press any key! " << flush;
_getch(); //*****msvc specific call*****
PrintHS(HighScores);
return;
}
Stake = GetWager(Savings); // savings altered here to account for stake
Sum = RollDice(Die1, Die2); // die1,die2 by ref.
switch(Sum)
{
case 7:
case 11: GameStatus = WON;
PlayerWins ++;
Savings += Stake * 2; // Pay up for win
Stake=0; // reset stake ready for statscreen
StatScreen(Die1, Die2, Sum, Stake, Savings, Point, HouseWins, PlayerWins);
PWin();
break;
case 2:
case 3:
case 12: GameStatus = LOST;
HouseWins ++;
Stake=0; // reset for statscreen
StatScreen(Die1, Die2, Sum, Stake, Savings, Point, HouseWins, PlayerWins);
HWin();
break;
default: GameStatus = CONTINUE;
Point = Sum;
StatScreen(Die1, Die2, Sum, Stake, Savings, Point, HouseWins, PlayerWins);
ReThrow();
break;
}
while ( GameStatus == CONTINUE )
{
StatScreen(Die1, Die2, Sum, Stake, Savings, Point, HouseWins, PlayerWins);
Sum = RollDice(Die1, Die2);
if (Sum == Point)
{
GameStatus = WON;
PlayerWins ++;
Savings += Stake * 2;
Stake=0;
Point = 0;
StatScreen(Die1, Die2, Sum, Stake, Savings, Point, HouseWins, PlayerWins);
PWin();
}
else
if (Sum == 7)
{
GameStatus = LOST;
HouseWins ++;
Stake=0;
StatScreen(Die1, Die2, Sum, Stake, Savings, Point, HouseWins, PlayerWins);
Point = 0;
HWin();
}
else
{
StatScreen(Die1, Die2, Sum, Stake, Savings, Point, HouseWins, PlayerWins);
ReThrow();
}
}
if(Savings) quit=AskForContinue();
if(quit == true)
{
if(Savings > HighScores[0].score)
{
clrscr();
const int SIZE = 256;
char buffer[SIZE];
gotoxy(0,8);
colour(BBLUE | TLTYELLOW);
cout << "You have made it onto the high scores board. Congratulations!!!!" << endl;
cout << "Please enter your name :- ";
cin.getline(buffer,SIZE);
HighScores[0].score = Savings;
strncpy(HighScores[0].name,buffer,20);
BubbleSort(HighScores);
WriteHS(HighScores);
PrintHS(HighScores);
}
}
}
}