Python numbers won't randomize -
i have been making fighting game harm won't randomize.
from random import randint import time #playerhealth = 20 #trollhealth = 10 #dragonhealth = 15 #playerdamage = randint(0,5) #trolldamage = randint(0,4) #dragondamage = randint(0,7) #slay = true #######variables. #print("""random fight""") def fight(enemy): playerh = 20 trollh = 10 dragonh = 15 playerd = randint(0,5) trolld = randint(0,4) dragond = randint(0,7) slay = true if enemy == "troll": enemyh = trollh enemyd = trolld elif enemy == "dragon": enemyh = dragonh enemyd = dragond else: print("invalid") print"you fighting ", enemy while slay: print"your health:",playerh print"enemy health:",enemyh time.sleep(1) #########when player attacking########################### if playerd == 5 or playerd == 4: print"you deal",playerd,"damage points. critical hit!" time.sleep(1) enemyh = enemyh - playerd print"the",enemy,"has",enemyh,"health points remaining." time.sleep(1) elif playerd == 0: print"you missed , deal 0 harm points." time.sleep(1) enemyh = enemyh - playerd print"the enemy has",enemyh,"health points remaining." time.sleep(1) else: print"you deal",playerd,"damage points." time.sleep(1) enemyh = enemyh - playerd print"the enemy has ", enemyh, "health points remaining." time.sleep(1) ############################################################# ########when troll attacking############################## if enemy == "troll": if enemyd == 4: print"the troll deals 4 harm points. critical hit!" time.sleep(1) playerh = playerh - enemyd print"you have",playerh,"health points remaining." time.sleep(1) elif enemyd == 0: print"the troll missed , deals 0 harm points." time.sleep(1) playerh = playerh - enemyd print"you have",playerh,"health points remaining." time.sleep(1) else: print"the troll deals",enemyd,"damage points." time.sleep(1) playerh = playerh - enemyd print"you have",playerh,"health points remaining." time.sleep(1) ############################################################## ##########when dragon attacking############################ if enemy == "dragon": if enemyd == 6 or enemyd == 7: print"the dragon deals",enemyd,"damage points. critical hit!" time.sleep(1) playerh = playerh - enemyd print"you have",playerh,"health points remaining." time.sleep(1) elif enemyd == 0: print"the dragon missed deals 0 points of damage." time.sleep(1) playerh = playerh - enemyd print"you have",playerh,"health points remaining." time.sleep(1) else: print"the dragon deals",enemyd,"damage points." time.sleep(1) playerh = playerh - enemyd print"you have",playerh,"health points remaining." time.sleep(1) ############################################################### if enemyh == 0: slay = false print("you won battle!") elif playerh == 0: slay = false print("you lost battle. improve luck next time.") ##############################end of function################################## #########begining of game############################ enemytest = true print("prepare battle.") time.sleep(1) while enemytest: enemy = raw_input("would fighting 'dragon' or 'troll'? ") enemy = enemy.lower() if enemy == "troll" or enemy == "dragon": enemytest = false else: print("invalid.") time.sleep(1) if enemy == "troll": fight(enemy) elif enemy == "dragon": fight(enemy) else: print("restart program.") time.sleep(3) #to fix: #enemy still attacks after death(test death after each attack. function? #damage doesn't vary #speed fast @ parts in function want maintain randomizing harm set randint each character. however, illustration let's want fighting dragon battle start , if player deals 4 harm first , dragon deals 2 harm first deal 4 , 2 harm throughout whole battle. why that? how can prepare it?
thanks in advance help can give me.
you assign randint values in next function:
def fight(enemy): playerh = 20 trollh = 10 dragonh = 15 playerd = randint(0,5) trolld = randint(0,4) dragond = randint(0,7) import random rand_value= random.randint(0,10) in range(5): print rand_value 2 2 2 2 2 in range(5): print random.randint(0,5) 2 1 3 2 5 then come in while slay loop value never changes in loop. need set randint values in loops.
python
No comments:
Post a Comment