python - How do I add a constant equation answer to display "hp" in my game? -


i have been working on game quite bit of time running many problems. though, have run 1 not know how fix. quite new python, , coding in general, trying add equation code display health of character , dragon attack each other. understand code horribly formatted , there errors, tell me how create constant equation? (look @ code down below clarity).

import time import sys import random  print "welcome scarlet adventure, text based game (created by: arav seth)"  time.sleep(1.5)  print"controls: yes or no"  startquestion = raw_input("ready start?")  def startgame(): time.sleep(0.75) print"you wake darkness... remember nothing." time.sleep(2) print"you up, off ground, head aches!" time.sleep(1.5) print"you around surroundings, is, forest. until,  eye catches faint light. squint hard , see hazy building." time.sleep(4) print"you conclude it's village." time.sleep(1.5)  def p1(): p1 = raw_input("you can either go village , ask people, or venture off woods. go village?") if p1 == "yes": section2() if p1 == "no": section3()  def section2(): time.sleep(0.5) print"you , start walking village..." time.sleep(1) print "after 30 minutes reach village. bigger  had expected. seems kingdom." p2()  def section3(): print"you , start wandering around forest. see shine.." time.sleep(1.5) print"before know it, 5 guards, in iron armour come out behind tree , run towards you. 1 of yells out- stop right there peasant! we're taking kingdom! -" time.sleep(1.5) p3()  def p2(): p2 = raw_input("you keep head down , @ others. recognize clothes not match ones of citizens. new clothes?") if p2 == "yes": section4() if p2 == "no": section8()  def p3(): p3 = raw_input("you can either run, or listen guards. come guards?") if p3 == "yes": section5() if p3 == "no": section6()  def section4(): time.sleep(1) print"you enter shop different kinds of things." time.sleep(1) print"you see beatiful blue leather tuic, grey pants. tag says- $5 -for each." p4()  def section5(): print"the guards take prison cell , tell discuss matter emperor. give clothes change into" print"another cell mate tells not true. never discuss matters, stay here forever." p5()  def section6(): print "you run hard, fast can. leader of guards yells- fire! -a whistling sound becomes louder , louder until arrow pierces heart... have died." time.sleep(1) lostgame()  def p4(): p4 = raw_input("you reach pocket , find $10. buy them?") if p4 == "yes": section7() if p4 == "no": section8()  def p5(): p5 = raw_input("you on ground , find small piece of malleable metal. must have come blacksmith nextdoor. try pick lock?") if p5 == "yes": section9() if p5 == "no": section10()  def section7(): print"you buy clothes , splendid. walk around town , see poster. talks evil beast, prize of it's death $10000!" p6()  def section8(): print"people murmur , whisper. guard sees , instantly knows outside. runs @ , slices of head, no intruders allowed!..." lostgame()  def section9(): print"it worked! sneak out of prison cell. see man had told staying here forever. open cell, , 2 of sneak out" print"you walk around town in clothes guards gave you. corner of eye spot poster. talks evil beast, prize of it's death $10000!" p6()  def section10(): print"you stay in prison cell day, until gurad comes cell inspection. finds piece of metal , accusing of attempted escape. beheads you..." lostgame()  def p6(): p6 = raw_input("would go slay evil beast?") if p6 == "yes": adventurestart() if p6 == "no": section11()  def section11(): print"you stay in kingdom , live there rest of life. own small hut, little eat. live happy..." endgame()  def lostgame(): time.sleep(1.5) lostgame = raw_input("you have lost game. start over?") if lostgame == "yes": startgame() if lostgame == "no": print"leaving game" time.sleep(0.5) sys.exit  def adventurestart(): print"you walk kingdom castle, there meet group of knights. tell them request , send on adventure..." time.sleep(3) print"you wake , around, in carriage 7 other men. dressed in iron armour. must have fallen asleep!" time.sleep(3) print"after hours arrive @ large stone brick castle. moves out enter. follow them." time.sleep(2) print"inside see corpses of knights, must strong beast!" time.sleep(1.5) print"after walking ways, find bridge. men start cross it, small portion of bridge in front crumbles! 2 men fall down, death. 5 remain." time.sleep(3.5) print"everyone else crosses bridge safely. shortly after bridge come across trap! 3 men fall , killed arrow. , 1 other remain." time.sleep(3) print"the other man flees!" time.sleep(1) print"after time come upon 2 gates, open them , there is, scarlet dragon!" fightoptions1()  def fightoptions1(): time.sleep(2) print"use key 1, 2, 3, & 4 selecting moves.." fightoptions1 = raw_input("1. sword strike [10dmg - 10/10] 2. wind slice [25dmg - 1/1] 3. jab [20dmg - 3/3]4. flee [0dmg - infinite]") if fightoptions1 == "1": time.sleep(1.5) print"you hit dragon: -10 hp" time.sleep(1.5) dragonmove() if fightoptions1 == "2": time.sleep(1.5) print"you hit dragon: -25 hp" dragonmove() if fightoptions1 == "3": time.sleep(1.5) print"you hit dragon: -20hp" time.sleep(1.5) dragonmove() if fightoptions1 == "4": time.sleep(1.5) print"you cant flee! dragon must below 50hp." time.sleep(1.5) else: print"invalid move- try again." fightoptions1()  def dragonmove(): l = 2 r = 3 c = 4 dodgemove = random.randint(2, 4) time.sleep(1.5) dodgechoice = raw_input("the dragon charging up! choose: left (l), right (r), or center (c) dodge move!") if dodgechoice == dodgemove: print"the dragon hit you: -25hp" time.sleep(1.5) else: print"good job! dodged dragon's move: -0hp" time.sleep(1.5) def endgame(): time.sleep(1.5) print"thank playing scarlet adventure." time.sleep(1.5) print"the end" time.sleep(0.75) print"leaving game" time.sleep(0.5) sys.exit if startquestion == "yes": fightoptions1() 

assuming global variable player_hp tracks current hp.

print ("the dragon hit you!  hp=%(player_hp)s" % globals()) 

ok, bring down more:

#global variable, can shared between functions player_hp = 200  def somefight():     #ask stuff / resolve results - i'll assume got hit      damage = 15                       #don't forget global declaration     global player_hp #need refer variable outside of function     #now update variable outside of function     player_hp = player_hp - damage      #grab global variables.     #this result in dictionary {"player_hp" : 185}     the_variables = globals()      #and merge in local variables     #{"player_hp" : 185, "damage" : 15}     the_variables.update(locals())      print "you got hit %(damage)s , have %(player_hp)s" % the_variables      #                                               |      #                               substitute in value      #                               player_hp key in      #                               the_variables dictionary 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -