Advertisement
Okorosso

Untitled

Sep 28th, 2019
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | None | 0 0
  1. from random import randint
  2.  
  3.  
  4. def duel(x, y):
  5.     while y.hp > x.damage or x.hp > y.damage:
  6.         priority = randint(0, 1)
  7.         if priority == 1:
  8.             y.attack(x)
  9.         else:
  10.             x.attack(y)
  11.     if y.hp <= 0:
  12.         print(x.name, 'won duel')
  13.         x.add_exp(1)
  14.     else:
  15.         print(y.name, 'won duel')
  16.         y.add_exp(1)
  17.     x.hp = 100
  18.     y.hp = 100
  19.  
  20.  
  21. class Human:
  22.     def __init__(self, name, hands_slot=None, hp=100, coord_x=0, coord_y=0, profession=None, defence=0, exp=0, lvl=0):
  23.         self.name = name
  24.         self.hands_slot = hands_slot
  25.         self.hp = hp
  26.         self.coord_x = coord_x
  27.         self.coord_y = coord_y
  28.         self.profession = profession
  29.         self.defence = defence
  30.         self.exp = exp
  31.         self.lvl = lvl
  32.  
  33.     def display(self):
  34.         print("\n Name: {} \n hp = {} \n in hands = {} \n profession: {} \n".format(self.name, self.hp, self.hands_slot,
  35.                                                                                     self.profession))
  36.  
  37.     def __repr__(self):
  38.         return '\n Name: {} \n hp = {} \n in hands: {} \n profession: {} \n def = {}'.format(self.name, self.hp,
  39.                                                                                      self.hands_slot, self.profession, self.defence)
  40.  
  41.     def add_exp(self, count):
  42.         self.exp += count
  43.         if self.exp - self.lvl*10 > 99:
  44.             self.lvl += 1
  45.             self.hp += 10
  46.  
  47.  
  48.  
  49. class Warrior(Human):
  50.     def __init__(self, name, hands_slot=None, hp=100, coord_x=0, coord_y=0, profession='warrior'):
  51.         Human.__init__(self, name, hands_slot, hp, coord_x, coord_y, profession)
  52.         self.weapon = 'sword'
  53.  
  54.     def attack(self):
  55.         print('{} cut monster by {}'.format(self.name, self.weapon))
  56.  
  57.     def receive_damage(self, damage):
  58.         self.hp -= damage
  59.         #print('{} receive {} damage'.format(self.name, damage))
  60.  
  61.     def print_hp(self):
  62.         print('{} has {}hp'.format(self.name, self.hp))
  63.  
  64. class Defender(Warrior):
  65.     def __init__(self, name, hands_slot=None, hp=100, coord_x=0, coord_y=0, profession='defender'):
  66.         Warrior.__init__(self, name, hands_slot, hp, coord_x, coord_y, profession)
  67.         self.damage = 10
  68.  
  69.     def attack(self, enemy):
  70.         #print('{} damaged {} {} damage \n'.format(self.name, enemy.name, self.damage))
  71.         enemy.receive_damage(self.damage)
  72.         #enemy.print_hp()
  73.  
  74.  
  75. x = Defender('Leha')
  76. y = Defender("Gosha")
  77. for i in range(1000):
  78.     duel(x, y)
  79. print(x.name, x.exp, x.lvl)
  80. print(y.name, y.exp, y.lvl)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement