Lives counter

Hello! I want to make my “Terminal Hacker” game better and I want to add a counter which will count lives! For example: if the player will try to enter the password, and he doesn’t succeeded from 3 tries, the game will end and the display will show “You have been detected! The police is coming!”.
I hope you understood my desire :)) !
Someone who can help me with an advice or a tutorial, please?

Hi Sebastian,

Your idea is fairly easy to implement. Have you already completed the Terminal Hacker section? If so, you should know the relevant techniques to make your idea work.

  1. Create a variable of type int for your lives.
  2. Whenever the player guesses, decrease the variable by one. For example with:
lives = lives - 1;
  1. Use an if-statement to determine whether the player is allowed to guess or if he is supposed to lose. If you don’t know the condition, think of the rule in English. When is the player supposed to lose?
  2. Last but not least, don’t forget to assign a value to the variable when the game starts.

Good luck! :slight_smile:

Thank you very much! I will try it!

How are you getting on with this, Sebastian?

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms