The example in this paper describes the simple RPG game flow implemented by Python. Share to everyone for your reference. Specific as follows:
#RPGrpg = truewhp = 100MAHP = 100hhp = 100MHP = 10def dgrnd (): WA = raw_input ("What does Warrior does?") Ma = raw_input ( "What does Mage does?") Ha = Raw_input ("What does healer does?") if WA = = "Flame Slash": Print ("Warrior uses flame slash!") MHP-20 elif wa = = "Dragon Slash" and M = = "Dragon": Print ("Warrior used Dragon slash!") MHP-80 if wa = = "Dragon" and M = = "Troll" or M = = "Goblin": Print ("Warrior ' s attack did no damage!") if Ma = = "Icicle D ROP ": Print (" Mage used Icicle Drop ") MHP-15 mahp-10 whp-10 hhp-10 If ma = =" Flames of Heck ": MHP-75 mahp-50 wph -50 hhp-50 If ha = = "Heal Warrior": Print ("Healer heals warrior!") WHP + If ha = = "Heal Mage": Print ("Healer heals mage!") MAHP + If ha = = "Heal Healer": Print ("Healer heals healer!") HHP + If Ha = = "Attack": Print ("Healer attacks!") MHP-5 print (m+ "attacks!") if m = = "Dragon": whp-40 mahp-40 hhp-40 if m = = "Troll": whp-30 mahp-30 hhp-30 if m = = "Goblin": whp -20 mahp-20 hhp-20 Print ("Warrior have" +whp+ "HP left, Mage have" +mahp+ "HP left, and healer have" +hhp+ "HP left!") if MHP = = 0:print ("You defeated the" +m+ "!") Print ("That's all I had built so far. Eventually, there'll be more! ") Print ("Thank for playing!!") Dgrnd () if RPG = = True:print ("This mode isn't yet complete. It is contains a dungeon so far. I ' m still working on the rest. ") #Dungeon whp = MAHP = HHP = + MHP = Ten M = "fail" Print ("You enter the Dungeon") RM = Raw_input ("There is thr EE passages. Do I take the first one, the second one, or the third one? ") if rm = = ' One ': M = ' Troll ' MHP = Print ("A" +m+ "appears!") if rm = = ' One ': M = ' Goblin ' MHP = print ("a" + m+ "appears!") if rm = = ' three ': M = ' Dragon ' MHP = + print ("A" +m+ "appears!") while MHP > 0:dgrnd ()
Hopefully this article will help you with Python programming.