Advertisement
robertvari

AdventureGame

Feb 10th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.37 KB | None | 0 0
  1. import random
  2.  
  3. class Character():
  4.     """
  5.    Base class for all characters in the game.
  6.    """
  7.  
  8.     def __init__(self):
  9.         self.name = None
  10.         self.characterClass = None
  11.         self.gender = None
  12.         self.age = None
  13.  
  14.         self.maxHP = 100
  15.         self.currentHP = self.maxHP
  16.  
  17.         self.strength = 10
  18.         self.inventory = []
  19.         self.gold = 0
  20.  
  21.     def getStats(self, nice=False):
  22.         statDict = {"name":self.name,
  23.                     "characterClass":self.characterClass,
  24.                     "maxHP":self.maxHP,
  25.                     "currentHP":self.currentHP,
  26.                     "gold":self.gold,
  27.                     "strength":self.strength}
  28.  
  29.         if nice:
  30.             print "-"*50
  31.             for k, v in statDict.items():
  32.                 print k, v
  33.             print "-" * 50
  34.  
  35.     def create(self, name, characterClass, gender, age):
  36.         self.name = name
  37.         self.characterClass = characterClass
  38.         self.gender = gender
  39.         self.age = age
  40.  
  41.         # setup attributes based on characterClass
  42.  
  43.         if characterClass == "human":
  44.             self.maxHP = 150
  45.             self.strength =35
  46.  
  47.         elif characterClass == "ork":
  48.             self.maxHP = 300
  49.             self.strength = 80
  50.  
  51.         elif characterClass == "mage":
  52.             self.maxHP = 200
  53.             self.strength = 25
  54.  
  55.         elif characterClass == "elf":
  56.             self.maxHP = 200
  57.             self.strength = 40
  58.  
  59.         self.gold = random.randint(10, 60)
  60.         self.currentHP = self.maxHP
  61.  
  62.     def attack(self, enemy):
  63.         attackStrength = random.randint(0, self.strength)
  64.         enemy.setCurrentHP(attackStrength)
  65.  
  66.         print "{} attacks {}".format(self.name, enemy.name)
  67.         print "{0} {1}HP \t {2} {3} HP".format(self.name, self.currentHP,
  68.                                                enemy.name, enemy.currentHP)
  69.  
  70.     def setCurrentHP(self, valu):
  71.         self.currentHP -= valu
  72.  
  73.     def buy(self):
  74.         pass
  75.  
  76.     def sell(self):
  77.         pass
  78.  
  79.     def __str__(self):
  80.         return "{} {}".format(self.name, self.characterClass)
  81.  
  82.  
  83. class Player(Character):
  84.     def __init__(self):
  85.         Character.__init__(self)
  86.  
  87. class Enemy(Character):
  88.     def __init__(self):
  89.         Character.__init__(self)
  90.  
  91. class NPC(Character):
  92.     def __init__(self):
  93.         Character.__init__(self)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement