Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.03 KB | None | 0 0
  1. import os
  2. import sys
  3. import random
  4. import pdb
  5.  
  6.  
  7. def get_input():
  8.     return input('-->')
  9.  
  10.  
  11. def bug():
  12.     pdb.set_trace()
  13.  
  14.  
  15. class Player:
  16.     def __init__(self, name, maxhealth, description, attack, defense, damage, dodge, stamina, armor):
  17.         self.name = name
  18.         self.maxhealth = maxhealth
  19.         self.health = self.maxhealth
  20.         self.description = description
  21.         self.attackbonus = attack
  22.         self.defense = defense
  23.         self.damage = damage
  24.         self.dodge = dodge
  25.         self.stamina = stamina
  26.         self.armor = armor
  27.  
  28.     def __str__(self):
  29.         print("Name: ", self.name, "\n""Health: ", self.health, "\n""Description: ", self.description, "\n""Attack: ",
  30.               self.attack, "\n""Defense: ", self.defense, "\n""Damage: ", self.damage, "\n""Dodge: ", self.dodge, "\n"
  31.               "Stamina: ", self.stamina, "\n""Armor: ", self.armor)
  32.  
  33.  
  34. class Monster:
  35.     def __init__(self, name, maxhealth, description, attack, defense, damage, xp, category):
  36.         self.name = name
  37.         self.maxhealth = maxhealth
  38.         self.health = self.maxhealth
  39.         self.description = description
  40.         self.attack = attack
  41.         self.defense = defense
  42.         self.damage = damage
  43.         self.xp = xp
  44.         self.category = category
  45.  
  46.     def __str__(self):
  47.         print("Name: ", self.name, "\n""Description: ", self.description, "\n""Category: ", self.category,
  48.               "\n""Health: ", self.health, "\n""Attack: ", self.attack, "\n""Defense: ", self.defense,
  49.               "\n""Damage: ", self.damage, "\n""XP: ", self.xp)
  50.  
  51.  
  52. player = Player(name="Henk", maxhealth=100, description="Human player", attack=10, defense=10, damage=10, dodge=10, stamina=10, armor=2)
  53. goblin = Monster(name="Goblin", description="Goblin", category="Humanoid", defense=15, maxhealth=7, attack=4, damage=6, xp=50)
  54. hobgoblin = Monster(name="Hobgoblin", description="Hobgoblin", category="Humanoid", defense=18, maxhealth=11, attack=3, damage=8, xp=10)
  55. goblinboss = Monster(name="Goblin Boss", description="Goblin Boss", category="Humanoid", defense=17, maxhealth=21, attack=4, damage=6, xp=200)
  56. skeleton = Monster(name="Skeleton", description="Skeleton", category="Undead", defense=13, maxhealth=13, attack=4, damage=6, xp=50)
  57. zombie = Monster(name="Zombie", description="Zombie", category="Undead", defense=8, maxhealth=22, attack=3, damage=6, xp=50)
  58. ghoul = Monster(name="Ghoul", description="Ghoul", category="Undead", defense=12, maxhealth=22, attack=2, damage=6, xp=200)
  59.  
  60. # part 2. setting actions
  61. # a player should be able to do something, and the same goes for a monster
  62. # make sure both players and monsters can attack vs defense, gain or loose health and run away
  63. # also maybe you want to save the 'state' of the player
  64. # further, write down 3-5 monster categories
  65. # No need to go into deep detail and complex methods
  66. # class methods/static variables
  67. # set the monster categories as a class value to use as choice. and loading a character is a class method
  68.  
  69.  
  70. class Game:
  71.     def main_menu(self):
  72.         print("""This is the mainmenu of the game.
  73.        1. Start
  74.        2. Exit""")
  75.         option = get_input()
  76.         if option == "1":
  77.             self.start()
  78.         elif option == "2":
  79.             sys.exit()
  80.         else:
  81.             self.main_menu()
  82.  
  83.     def start(self):
  84.         print("""This is the mainmenu of the game.
  85.        1. Fight
  86.        2. Show current stats
  87.        3. Exit""")
  88.         option = get_input()
  89.         if option == "1":
  90.             self.encounter()
  91.         elif option == "2":
  92.             self.stats()
  93.         elif option == "3":
  94.             sys.exit()
  95.         else:
  96.             print("You didn't make a valid choice try again.")
  97.             return self.main_menu()
  98.  
  99.     def encounter(self):
  100.         enemytype = random.randint(1, 10)
  101.         if 1 <= enemytype <= 6:
  102.             self.enemy = goblin
  103.         elif 7 <= enemytype <= 9:
  104.             self.enemy = hobgoblin
  105.         elif enemytype == 10:
  106.             self.enemy = goblinboss
  107.         self.fight()
  108.  
  109.     def stats(self):
  110.         print(player.__str__())
  111.         return self.main_menu()
  112.  
  113.     def fight(self):
  114.         if self.enemy.health <= 0:
  115.             print("The %s died of it's wounds." % self.enemy.description)
  116.         else:
  117.             print("""What do you want to do?
  118.            1. Attack
  119.            2. Run""")
  120.             fight_option = get_input()
  121.             if fight_option == "1":
  122.                 return self.attack()
  123.             else:
  124.                 return self.runaway()
  125.  
  126.     def attack(self):
  127.         self.player = player
  128.         self.strike = random.randint(1, 20) + self.player.attackbonus
  129.         self.mob_armor = 10 + self.enemy.defense
  130.         if self.strike >= self.mob_armor:
  131.             self.hit = random.randint(1, self.player.damage)
  132.             print("You hit the %s for %s damage!" % (self.enemy.description, self.hit))
  133.             self.enemy.health -= self.hit
  134.         else:
  135.             print("You missed!")
  136.         return self.fight()
  137.  
  138.  
  139. Game().main_menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement