lundi 23 novembre 2015

Still new to python. So confused right now. How do I make this program work?

So I'm making a little game to teach myself how python works, and it's been okay up to this point, but now I'm completely stuck. I'm sure the logic and formatting of the if and while statement are all wrong, so I'd be happy if people could point me in the right direction - again, REALLY new to programming in general. I'll paste the code, then explain what I'm trying to make it do:

import random
import time

print("Welcome to the Dojo!")
print("You have three opponents; they are ready...")
print("Are you?")
print("*To view the rules, type 'rules' ")
print("*To view commands, type 'commands' ")
print("*To begin, type 'start' ")

while True:
    userInput = (input())
    # Rules
    if userInput == "rules":
        print("The rules in this Dojo are simple. Kill your opponent! Fight to the death! Show no mercy!")
        print("Each opponent gets progressively more difficult, whether it be in terms of health or damage.")
        print("To attack, type 'attack'")
        print("May the better (luckier) warrior win")
    # Commands - to be added
    elif userInput == "commands":
        print("Commands will be added soon!")
    # Start
    elif userInput == "start":
            damage = random.randint(1, 50)
            userHealth = int(100)
            opponentHealth = int(100)
            print("Your first opponent is Larry Schmidt. Don't sweat it, he'll be a piece of cake.")
            time.sleep(3)
            print("The battle will begin in")
            time.sleep(1)
            print("5")
            time.sleep(1)
            print("4")
            time.sleep(1)
            print("3")
            time.sleep(1)
            print("2")
            time.sleep(1)
            print("1")
            time.sleep(1)
            print("Fight!")
            if userInput == "attack":
                int(userHealth - damage)
                print("You did %(damage) to Larry!")

    # Invalid response
    else:
        print("Enter a valid response, young grasshopper.")
        if userInput == "start" is True:
            continue

If you run the program for yourself, everything is okay until you reach the "5, 4, 3, 2, 1, Fight!" part. Then when you type "attack," it gives you "Enter a valid response, young grasshopper." I understand why this is happening, because "attack" doesn't fall under "rules", "commands", or "start". I just don't get how I'm supposed to format it so that after I enter "attack", it actually proceeds and outputs the damage done, etc. I apologize if this is hard to understand, but I think if you run it for yourself, you'll understand what I'm having problems with. Honestly, something tells me I've messed up the if and while statements up entirely, but hey, I'm learning and having fun :P.

Thanks for any help.

Aucun commentaire:

Enregistrer un commentaire