You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes people will perform so poorly that we just need to stop them. We
don't want players to embarrass themselves, after all. It's about dignity.
There are two different ways a player's score can go down: when the player
clicks and misses, and when a mole escapes. Both events may trigger a "game
over".
Unfortunately, at the moment, the Director cannot respond to changes to the
miss count or the escape count. We could look through the code for every
place we increment those counters, but (1) we might miss one, and (2) we might
forget to add this new "game over" check if we add more code in the future.
Let's create a centralized function that "knows" about all the changes to those
counter variables. Then, we'll update all the places we increment the instance
variables to instead call the function.
At this point, the game will work exactly the same as it did before. But we
can add our new "game over" check to that new function.
director.js
Define an increment method. This should take a single argument: the
name of the instance variable to increment. When you call director.increment('miss');, for example, the miss count should increase
by 1.
Replace any line of code that increments a counter variable with a call
to the new increment method.
Update the increment method to check if the player has lost. If they
have lost, call the endGame method.
We haven't decided how badly the player has to perform before losing. It's not
in the spec, so it could be anything. Maybe they lose after missing 5 times. Or
when 8 moles escape. Or both. It's up to you!
The text was updated successfully, but these errors were encountered:
Sometimes people will perform so poorly that we just need to stop them. We
don't want players to embarrass themselves, after all. It's about dignity.
There are two different ways a player's score can go down: when the player
clicks and misses, and when a mole escapes. Both events may trigger a "game
over".
Unfortunately, at the moment, the Director cannot respond to changes to the
miss count or the escape count. We could look through the code for every
place we increment those counters, but (1) we might miss one, and (2) we might
forget to add this new "game over" check if we add more code in the future.
Let's create a centralized function that "knows" about all the changes to those
counter variables. Then, we'll update all the places we increment the instance
variables to instead call the function.
At this point, the game will work exactly the same as it did before. But we
can add our new "game over" check to that new function.
director.js
increment
method. This should take a single argument: thename of the instance variable to increment. When you call
director.increment('miss');
, for example, the miss count should increaseby 1.
to the new
increment
method.increment
method to check if the player has lost. If theyhave lost, call the
endGame
method.We haven't decided how badly the player has to perform before losing. It's not
in the spec, so it could be anything. Maybe they lose after missing 5 times. Or
when 8 moles escape. Or both. It's up to you!
The text was updated successfully, but these errors were encountered: