Game Development Reference
In-Depth Information
•
After the player makes the first move, the hint button should disappear, and the
retry button should appear.
•
If the player chose to switch off hints in the options menu, the hint button should
never be visible.
For the first case, we need to keep track of when then player makes his/her first
move. We add an extra member variable
firstMoveMade
to the
Level
class, as well as
a method
FirstMoveMade
tosetitto
true
. When we give an animal a velocity, this is
done in the
AnimalSelector
class. Once the player has clicked on an arrow and the
animal is moving, we call the
FirstMoveMade
method:
Levell=GameWorld
as
Level;
l.FirstMoveMade();
Secondly, we have to handle the 'hints' setting from the game settings manager.
We do this in the
Update
method of the
Level
class. We simply check what the value
of the 'hints' setting is in the game settings manager, and update the button visibility
state accordingly:
hintButton.Visible = GameSettingsManager.getValue("hints") == "on" && !firstMoveMade;
retryButton.Visible = !hintButton.Visible;
As you can see from these two lines of code, the hint button is only visible if the
'hints' value is equal to 'on' and the player has not yet made a first move. The retry
button visibility status is always the opposite of the hint button's visibility status. So
if the hint button is visible, the retry button is not, and vice versa.
24.3.2 Resetting the Level
After a player moves a couple of penguins around, it happens that the level cannot
be solved anymore. Instead of having to quit and restart the game, let us give the
player a means to
reset
a level to its initial state.
Because of the proper implementation of the
Reset
method everywhere through-
out the game object classes, resetting a level to its initial state is now fairly easy. We
have to call the
Reset
method on all the game objects, and then we have to deal with
resetting things in the
Level
class itself. The only thing we need to do there is set the
firstMoveMade
variable to
false
, so that the player can view a hint again:
public override void
Reset()
{
base
.Reset();
firstMoveMade =
false
;
}