Game Development Reference
In-Depth Information
We also add a method to the class for checking if the player has pressed the 'quit'
button:
public bool PlayerQuit
{
get { return quitButton.Pressed; }
}
Inside the PlayingState , we then call the game loop methods on the currently running
level, and if the player has pressed the 'quit' button, we reset the level, and return to
the level menu, as can be seen in the HandleInput method of the PlayerState class:
public virtual void HandleInput(InputHelper inputHelper)
{
CurrentLevel.HandleInput(inputHelper);
if (CurrentLevel.PlayerQuit)
{
CurrentLevel.Reset();
PenguinPairs.GameStateManager.SwitchTo("levelMenu");
}
}
Finally, for each level, we maintain whether the level is locked or not and whether
the player already solved the level. We need two boolean member variables for that,
and we add two properties to the Level class to access them.
22.8 Maintaining the Player's Progress
One more nice thing that is now possible with file I/O is that we can keep track of
the player's progress, and we can remember it for the next time the player wants to
play the game. To do that, we created a text file 'levels_status.txt' which contains
for each level both the locked and solved status. This file has the following contents:
false,false
true,false
true,false
true,false
true,false
true,false
true,false
true,false
true,false
true,false
true,false
true,false
In total, there are 12 lines, each one corresponding to a level. The first boolean in-
dicates whether the level is locked or not, and the second boolean indicates whether
Search WWH ::




Custom Search