Ask coding questions

← Back to all posts
How can I add health system in this decision making game?
ArafatSami (0)

I want to add health system in this game...

Comments
hotnewtop
RYANTADIPARTHI (6019)

Solution

you can add health to the user, whenever he/she accomplishes a task.

import time

health = 10

name = input("What is your name? ")
age = int(input('How old are you? ' ))
if age >=13:
    print("Your are old enough to play")
    time.sleep(1.6)
    ask = input("Do you want play? ").lower()
    time.sleep(1.5)
    if ask == 'yes':
        print(" Let's play...")
        time.sleep(1.5)
        ans1 = input("Your first decision?(left/right) ")
        time.sleep(1)
        if ans1 == 'right':
            print("Hey,you reached a cave...")
            health += 1    # adding a health point
            time.sleep(2)
            ans2 = input("Will you enter the cave?(yes/no)" ).lower()
            time.sleep(1)
            if ans2 == 'yes':
                print("A Jaguar jumped on you and killed you....")
                time.sleep(2)
            elif ans2 == 'no':
                print("oh...you reached a Castle... something is shining in the Castle.. ")
                time.sleep(2)
                ans4 = input('Enter the castle(yes/no) ')
                time.sleep(1)
                if ans4 == 'yes':
                    print("You get treasure in the castle and you become rich.")
                    time.sleep(2)
                    print("You won the game")
                elif ans4 == 'no':
                    print("You reached your home safely...")
                    time.sleep(2)
        elif ans1 == 'left':
            print("you reached a lake...")
            time.sleep(2)
            ans3 = input("What will you do?(swim/no)").lower()
            time.sleep(1)
            if ans3 == 'swim':
                print("water is too cold...pneumonia caught you..and you lost.")
                time.sleep(2)
            elif ans3 == 'no':
                print("A dog is waiting for you...when you go closer it will beat and you will die.")
                time.sleep(2)
        else:
            print('you lost')
            health -= 1       # Losing health
    else:
        print("as you wish")
else:
    print("Sorry,You are not enough to play...")

like that, you can add or subtract health wherever you want.
That should work