Game Development Reference
In-Depth Information
else
{
cout << "I do not recognize that option, try again!"
<< endl << endl;
}
return chosenOption;
}
The RunGame function returns a bool , the shouldEnd variable. This function is designed to be called
from a loop and simply calls the other functions that represent the different stages of our game at
the moment. The return value from EvaluateInput is checked to determine if the player has decided
to quit the game.
bool RunGame()
{
bool shouldEnd = false;
GivePlayerOptions();
string playerInput;
GetPlayerInput(playerInput);
shouldEnd = EvaluateInput(playerInput) == PlayerOptions::Quit;
return !shouldEnd;
}
Our program's entry point is still the main function. This function calls WelcomePlayer then executes a
while loop that will iterate until the player has selected the quit option.
int main(int argc, const char * argv[])
{
Player player;
WelcomePlayer(player);
bool isPlaying = true;
while (isPlaying)
{
isPlaying = RunGame();
}
return 0;
}
We have now written a program that is beginning to resemble a game. We have put the core game
loop into place and from here we will be able to add new functionality to our existing functions.
 
Search WWH ::




Custom Search