Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
syntax help
#4
This is how i got it to work.
If anyone has a better way to achieve the same results please let me know.
thanks to @ljmetzger for pointing me in the right direction

### shitty battle simulator ###
import random
import time

playerHealth = 50
compHealth = 50

def battleIntro():
    print ("You enter the arena to the cheers of the crowds. ")
    print ("Across fomr you stands your opponent. ")
    print ("Only one you will leave this place alive. ")
    print ("Prepare to fight!" )
    print()
    
def battlePlayer():
    global compHealth
    global playerHealth
    missChance = 2
    while playerHealth >  0 and compHealth > 0:
        print ("Do you wish to attack")
        #input ("enter")

        miss = random.randint (1, 4)
        
        if (missChance) == (miss):
            print ("You swing wildly and miss your opponent. ")
            print()
        else:
            print ("You strike your opponent doing damage. ")
            print()
            compHealth = compHealth - 5
        break
            
def battleComp():
    global playerHealth
    global compHealth
    missChance = 2
    while playerHealth >  0 and compHealth > 0:
        print ("Your opponent charges at you. ")
        #time.sleep(2)

        miss = random.randint (1, 4)
        
        if (missChance) == (miss):
            print ("You dodge his attack. ")
            print()
        else:
            print ("He manages to strike you doing damage. ")
            print()
            playerHealth = playerHealth - 5
        break
        
def battleResult():
    global comphealth
    global playerHealth
    if compHealth == 0:
        print ("Your hands are slick with his blood. ")
        print ("You have slayen your opponent." )
        print()
        
    elif playerHealth == 0:
        print ("Your opponent stands over you and drives his sword into your chest. ")
        print ("You have died! ")
        print()
        
def battleLoop():
    while playerHealth >  0 and compHealth > 0:
        battlePlayer()
        battleComp()
    #if playerHealth < 0 or compHealth < 0:
        #battleResult()
    
playAgain = "yes"  
while playAgain == "yes" or playAgain == "y":
    playerHealth = playerHealth + 50
    compHealth = compHealth + 50
    battleIntro()
    #battlePlayer()
    #battleComp()
    battleLoop()
    battleResult()

    print ("Do you want to play again?")
    playAgain = input()
Reply


Messages In This Thread
syntax help - by Dieselkaine - Jul-01-2018, 02:03 PM
RE: syntax help - by buran - Jul-01-2018, 02:25 PM
RE: syntax help - by ljmetzger - Jul-01-2018, 03:51 PM
RE: syntax help - by Dieselkaine - Jul-01-2018, 07:53 PM

Forum Jump:

User Panel Messages

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