Python Forum
Please help me with this program
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help me with this program
#1
Whenever i run the program it continually loops. Please help!
import random
#Misc. variables
y = 0
monNum = random.randint(1, 2)

#Player variables
player1HP = 10
gold = 0

#Enemy HP
goombaHP = 10
slimeHP = 15

#Monster Number Generator
def monNumCmd():
    monNum = random.randint(1,1)

#Attack command
def attack():
    if(monNum==1):
        global goombaHP
        attackValue = random.randint(1, 10)
        goombaHP = goombaHP - attackValue
        print("Goomba HP:")
        print(goombaHP)
    elif(monNum==2):
        global slimeHP
        attackValue = random.randint(1,10)
        slimeHP = slimeHP - attackValue
        print("Slime HP:")
        print(slimeHP)

#Enemy attack
def enemyAttack():
    if(monNum==1):
        global player1HP
        enemyAttack = random.randint(1, 3)
        player1HP = player1HP - enemyAttack
        print("Player HP:")
        print(player1HP)

#Inventory Screen
def inventory():
    print("Player HP:")
    print(player1HP)
    print()
    print("Gold:")
    print(gold)
    print()

def move():
    y=y-1

#Battle input chain
def enemyBattleChain():
    global y
    global gold
    global monNum
    if(monNum==1):
        if(player1HP<=0):
            print("You have been defeated!")
            y=y+1
        elif(goombaHP<=0):
            print("You have slain the Goomba!")
            gold = gold + random.randint(1,3)
            inventory()
        else:
            print("A goomba has crossed your path!")
            print()
            command = input("What will you do?:")
            print()
            if(command == "help"):
                print("attack")
                
                print()
            elif(command == "attack"):
                attack()
                enemyAttack()
            else:
                print("Command not found")
    elif(monNum==2):
        if(player1HP<=0):
            print("You have been defeated!")
        if(slimeHP<=0):
            print("You have slain the Slime!")
        else:
            print("A slime has crossed your path!")
            print()
            command = input("What will you do?:")
            print()
            if(command=="help"):
                print("attack")
                print()
            elif(command == "attack"):
                attack()
            else:
                print("Command not found")


while(y==0):
    enemyBattleChain()
Reply


Messages In This Thread
Please help me with this program - by William_the_Conqueror - Dec-16-2016, 10:22 PM
RE: Please help me with this program - by nilamo - Dec-16-2016, 10:38 PM
RE: Please help me with this program - by Larz60+ - Dec-16-2016, 10:39 PM
RE: Please help me with this program - by Larz60+ - Dec-16-2016, 10:42 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020