Project 1 Solution
Project 1 Solution
#include<iostream>
#include<cstdlib>
struct stRoundInfo
{
short RoundNumber = 0;
enGameChoice Player1Choice;
enGameChoice ComputerChoice;
enWinner Winner;
string WinnerName;
};
struct stGameResults
{
short GameRounds = 0;
short Player1WinTimes = 0;
short Computer2WinTimes = 0;
short DrawTimes = 0;
enWinner GameWinner;
string WinnerName = "";
};
ProgrammingAdvices.com
© Copyright 2022
Project 1 Solution Using C++
if (RoundInfo.Player1Choice == RoundInfo.ComputerChoice)
{
return enWinner::Draw;
}
switch (RoundInfo.Player1Choice)
{
case enGameChoice::Stone:
if (RoundInfo.ComputerChoice == enGameChoice::Paper)
{
return enWinner::Computer;
}
break;
case enGameChoice::Paper:
if (RoundInfo.ComputerChoice == enGameChoice::◌
ٍScissors)
{
return enWinner::Computer;
}
break;
case enGameChoice::◌
ٍScissors:
if (RoundInfo.ComputerChoice == enGameChoice::Stone)
{
return enWinner::Computer;
}
break;
ProgrammingAdvices.com
© Copyright 2022
Project 1 Solution Using C++
case enWinner::Computer:
system("color 4F"); //turn screen to Red
cout << "\a";
break;
default:
system("color 6F"); //turn screen to Yellow
break;
}
}
SetWinnerScreenColor(RoundInfo.Winner);
ProgrammingAdvices.com
© Copyright 2022
Project 1 Solution Using C++
stGameResults GameResults;
GameResults.GameRounds = GameRounds;
GameResults.Player1WinTimes = Player1WinTimes;
GameResults.Computer2WinTimes = ComputerWinTimes;
GameResults.DrawTimes = DrawTimes;
GameResults.GameWinner = WhoWonTheGame(Player1WinTimes,
ComputerWinTimes);
GameResults.WinnerName = WinnerName(GameResults.GameWinner);
return GameResults;
}
enGameChoice ReadPlayer1Choice()
{
short Choice = 1;
do
{
return (enGameChoice)Choice;
enGameChoice GetComputerChoice()
{
return (enGameChoice) RandomNumber(1, 3);
}
ProgrammingAdvices.com
© Copyright 2022
Project 1 Solution Using C++
{
stRoundInfo RoundInfo;
short Player1WinTimes = 0, ComputerWinTimes = 0, DrawTimes = 0;
PrintRoundResults(RoundInfo);
}
ProgrammingAdvices.com
© Copyright 2022
Project 1 Solution Using C++
void ShowGameOverScreen()
{
cout << Tabs(2) <<
"__________________________________________________________\n\n";
cout << Tabs(2) << " +++ G a m e O v e r
+++\n";
cout << Tabs(2) <<
"__________________________________________________________\n\n";
SetWinnerScreenColor(GameResults.GameWinner);
}
short ReadHowManyRounds()
{
short GameRounds = 1;
do
{
cout << "How Many Rounds 1 to 10 ? \n";
cin >> GameRounds;
return GameRounds;
}
ProgrammingAdvices.com
© Copyright 2022
Project 1 Solution Using C++
void ResetScreen()
{
system("cls");
system("color 0F");
void StartGame()
{
char PlayAgain = 'Y';
do
{
ResetScreen();
stGameResults GameResults = PlayGame(ReadHowManyRounds());
ShowGameOverScreen();
ShowFinalGameResults(GameResults);
cout << endl << Tabs(3) << "Do you want to play again? Y/N? ";
int main()
{
//Seeds the random number generator in C++, called only once
srand((unsigned)time(NULL));
StartGame();
return 0;
}
ProgrammingAdvices.com
© Copyright 2022