SHARE
TWEET

Untitled

a guest Oct 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import random
  3.  
  4.  
  5. def get_input():
  6.     return input('-->')
  7.  
  8.  
  9. class Player:
  10.     def __init__(self, name, maxhealth, description, attack, defense, damage):
  11.         self.name = name
  12.         self.maxhealth = maxhealth
  13.         self.health = self.maxhealth
  14.         self.description = description
  15.         self.attackbonus = attack
  16.         self.defense = defense
  17.         self.damage = damage
  18.  
  19.     def __str__(self):
  20.         print("Name: ", self.name, "\n""Health: ", self.health, "\n""Description: ", self.description, "\n""Attack: ",
  21.               self.attackbonus, "\n""Defense: ", self.defense, "\n""Damage: ", self.damage)
  22.  
  23.  
  24. class Monster:
  25.     def __init__(self, name, maxhealth, description, attack, defense, damage, xp, category):
  26.         self.name = name
  27.         self.maxhealth = maxhealth
  28.         self.health = self.maxhealth
  29.         self.description = description
  30.         self.attackbonus = attack
  31.         self.defense = defense
  32.         self.damage = damage
  33.         self.xp = xp
  34.         self.category = category
  35.  
  36.     def __str__(self):
  37.         print("Name: ", self.name, "\n""Description: ", self.description, "\n""Category: ", self.category,
  38.               "\n""Health: ", self.health, "\n""Attack: ", self.attackbonus, "\n""Defense: ", self.defense,
  39.               "\n""Damage: ", self.damage, "\n""XP: ", self.xp)
  40.  
  41.  
  42. player = Player(name="Henk", maxhealth=100, description="Human player", attack=10, defense=10, damage=10)
  43. goblin = Monster(name="Goblin", description="Goblin", category="Humanoid", defense=15, maxhealth=7, attack=4, damage=6, xp=50)
  44. hobgoblin = Monster(name="Hobgoblin", description="Hobgoblin", category="Humanoid", defense=18, maxhealth=11, attack=3, damage=8, xp=10)
  45. goblinboss = Monster(name="Goblin Boss", description="Goblin Boss", category="Humanoid", defense=17, maxhealth=21, attack=4, damage=6, xp=200)
  46. skeleton = Monster(name="Skeleton", description="Skeleton", category="Undead", defense=13, maxhealth=13, attack=4, damage=6, xp=50)
  47. zombie = Monster(name="Zombie", description="Zombie", category="Undead", defense=8, maxhealth=22, attack=3, damage=6, xp=50)
  48. ghoul = Monster(name="Ghoul", description="Ghoul", category="Undead", defense=12, maxhealth=22, attack=2, damage=6, xp=200)
  49.  
  50.  
  51. class Actions:
  52.     def encounter(self):
  53.         self.player = player
  54.         enemytype = random.randint(1, 10)
  55.         if 1 <= enemytype <= 6:
  56.             self.enemy = goblin
  57.         elif 7 <= enemytype <= 9:
  58.             self.enemy = hobgoblin
  59.         elif enemytype == 10:
  60.             self.enemy = goblinboss
  61.         self.fight()
  62.  
  63.     def fight(self):
  64.         if self.enemy.health <= 0:
  65.             print("The %s died of it's wounds." % self.enemy.description)
  66.             return Game().start()
  67.         if self.player.health <= 0:
  68.             print("You died!")
  69.             return Game().main_menu()
  70.         else:
  71.             print("""You see a %s blocking your way.
  72.             What do you want to do?
  73.            1. Attack
  74.            2. Run""" % self.enemy.description)
  75.             fight_option = get_input()
  76.             if fight_option == "1":
  77.                 return self.attack()
  78.             elif fight_option == "2":
  79.                 return self.runaway()
  80.             else:
  81.                 print("You didn't make a valid choice try again.")
  82.                 return self.fight()
  83.  
  84.     def attack(self):
  85.         if random.randint(1, 20) + self.player.attackbonus >= 10 + self.enemy.defense:
  86.             self.hit = random.randint(1, self.player.damage)
  87.             print("You hit the %s for %s damage!" % (self.enemy.description, self.hit))
  88.             self.enemy.health -= self.hit
  89.         else:
  90.             print("You missed!")
  91.         if random.randint(1, 20) + self.enemy.attackbonus >= 10 + self.player.defense:
  92.             self.hit = random.randint(1, self.enemy.damage)
  93.             print("You are hit for %s damage!" % self.hit)
  94.             self.player.health -= self.hit
  95.             print("You have %s hitpoints left." % self.player.health)
  96.         else:
  97.             print("You dodged the attack!")
  98.         return self.fight()
  99.  
  100.     def runaway(self):
  101.         run = random.randint(1, 10)
  102.         if 1 <= run <= 8:
  103.             print("You managed to run away.")
  104.         else:
  105.             print("You didn't managed to run away.")
  106.             return self.fight()
  107.  
  108.  
  109. class Game:
  110.     def main_menu(self):
  111.         print("""This is the mainmenu of the game.
  112.        1. Start
  113.        2. Exit""")
  114.         option = get_input()
  115.         if option == "1":
  116.             self.start()
  117.         elif option == "2":
  118.             sys.exit()
  119.         else:
  120.             self.main_menu()
  121.  
  122.     def start(self):
  123.         print("""You stand in an empty room.
  124.        1. Go to next room.
  125.        2. Show current stats
  126.        3. Exit""")
  127.         option = get_input()
  128.         if option == "1":
  129.             Actions().encounter()
  130.         elif option == "2":
  131.             print(player.__str__())
  132.             return self.start()
  133.         elif option == "3":
  134.             sys.exit()
  135.         else:
  136.             print("You didn't make a valid choice try again.")
  137.             return self.main_menu()
  138.  
  139.  
  140. Game().main_menu()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top