Advertisement
tokyoedtech

Simple RPG in PYTHON

Jan 4th, 2017
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.83 KB | None | 0 0
  1. #RPG
  2. #User random to create attributes for your character and the computer's character
  3. #Strength: 1 - 20
  4. #Intelligence: 1 - 10
  5. #Magic: 1 - 30
  6. #Have the user choose Fight, Steal, or Magic
  7. #The stronger character wins a fight
  8. #The smarter character can steal from the other
  9. #The more magical character can defeat the other
  10. import os
  11. import random
  12.  
  13. def print_header():
  14.     print ("Welcome to the Labyrinth...prepare to die!")
  15.  
  16. def generate_stats():
  17.     global user_strength
  18.     global user_intelligence
  19.     global user_magic
  20.     global computer_strength
  21.     global computer_intelligence
  22.     global computer_magic
  23.    
  24.     #Generate user stats
  25.     user_strength = random.randint(1, 20)
  26.     user_intelligence = random.randint(1, 10)
  27.     user_magic = random.randint(1, 30)
  28.  
  29.     #Generate computer stats
  30.     computer_strength = random.randint(1, 20)
  31.     computer_intelligence = random.randint(1, 10)
  32.     computer_magic = random.randint(1, 30)
  33.    
  34. def print_fight_type(type):
  35.     if type == "F":
  36.         print ("""
  37.     ___________ ____________  
  38.     |           )._______.-'
  39.     `----------'
  40.     You decide to fight with your knife...
  41.     """)
  42.    
  43.     elif type == "S":
  44.         print ("""
  45.      {O-
  46.     //\\===+-
  47.      \\
  48.       ))
  49.      ||
  50.      You decide to steal from this vagabond...
  51.     """)       
  52.  
  53.     elif type == "M":
  54.         print ("""
  55.            *
  56.          *   *
  57.        *  \\\\* / *
  58.        * --.:. *
  59.       *   * :\\\\ -
  60.         .*  | \\\\
  61.                \\\\
  62.                 \\\\
  63.     You decide to use your magic to fight...
  64.     """)
  65.  
  66. def print_fight_result(type):
  67.     global user_health
  68.     global computer_health
  69.    
  70.     if type == "F":
  71.  
  72.         if user_strength > computer_strength:
  73.             print ("You win the fight!")
  74.             computer_health -= 20
  75.         else:
  76.             print ("You fight well, but ultimately lose.")
  77.             user_health -= 20
  78.  
  79.     elif type == "S":
  80.  
  81.         if user_intelligence > computer_intelligence:
  82.             print ("You steal the Jewel of Power and weaken your enemy.")
  83.             computer_health -= 10
  84.         else:
  85.             print ("You fail...and are lightly injured.")
  86.             user_health -= 10
  87.    
  88.     elif type == "M":
  89.  
  90.         if user_magic > computer_magic:
  91.             print ("You cast a spell and injure your enemy!")
  92.             computer_health -= 30
  93.         else:
  94.             print ("Your enemy turns your spell against you...you feel undescribable pain!")
  95.             user_health -= 30
  96.     else:
  97.         print ("That was not one of the choices.") 
  98.        
  99. def print_stats():
  100.     print ("")
  101.     print ("User Stats")
  102.     print ("Strength: " + str(user_strength))
  103.     print ("Intelligence: " + str(user_intelligence))
  104.     print ("Magic: " + str(user_magic))
  105.     print ("Health: " + str(user_health))
  106.  
  107.     print("")
  108.  
  109.     print ("Computer Stats")
  110.     print ("Strength: " + str(computer_strength))
  111.     print ("Intelligence: " + str(computer_intelligence))
  112.     print ("Magic: " + str(computer_magic))
  113.     print ("Health: " + str(computer_health))
  114.     print ("")
  115.    
  116. def is_player_dead(health):
  117.     if health <= 0:
  118.         return True
  119.     else:
  120.         return False
  121.  
  122. def is_computer_dead(health):
  123.     if health <= 0:
  124.         return True
  125.     else:
  126.         return False
  127.  
  128.  
  129. user_health = 100
  130. computer_health = 100
  131.  
  132. while True:
  133.  
  134.     os.system("clear")
  135.  
  136.     #Generate user stats
  137.     generate_stats()
  138.  
  139.     #Header
  140.     print_header()
  141.    
  142.     #Choose which type of battle: (F)ight, (S)teal, (M)agic
  143.     user_choice = input("What type of battle? (F)ight, (S)teal, (M)agic > ").upper()
  144.  
  145.     print_fight_type(user_choice)
  146.  
  147.     #Determine the winner
  148.     print_fight_result(user_choice)
  149.  
  150.     #Print stats
  151.     print_stats()
  152.    
  153.  
  154.    
  155.     #Check for player death
  156.     if is_player_dead(user_health):
  157.         print ("Your enemy finally defeats you - you are dead!")
  158.        
  159.     if is_computer_dead(computer_health):
  160.         print ("You finally defeat your enemy - he dies cursing your name!")
  161.    
  162.     #Ask for a replay  
  163.     if is_player_dead(user_health) or is_computer_dead(computer_health):
  164.         replay = input("Please type (Y)es to replay, or (N)o to finish. > ")
  165.         if replay == "Y":
  166.             user_health = 100
  167.             computer_health = 100
  168.             continue
  169.         else:
  170.             break
  171.            
  172.     delay = input("Press enter to continue. ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement