Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def duel(x, y):
- while y.hp > x.damage or x.hp > y.damage:
- priority = randint(0, 1)
- if priority == 1:
- y.attack(x)
- else:
- x.attack(y)
- if y.hp <= 0:
- print(x.name, 'won duel')
- x.add_exp(1)
- else:
- print(y.name, 'won duel')
- y.add_exp(1)
- x.hp = 100
- y.hp = 100
- class Human:
- def __init__(self, name, hands_slot=None, hp=100, coord_x=0, coord_y=0, profession=None, defence=0, exp=0, lvl=0):
- self.name = name
- self.hands_slot = hands_slot
- self.hp = hp
- self.coord_x = coord_x
- self.coord_y = coord_y
- self.profession = profession
- self.defence = defence
- self.exp = exp
- self.lvl = lvl
- def display(self):
- print("\n Name: {} \n hp = {} \n in hands = {} \n profession: {} \n".format(self.name, self.hp, self.hands_slot,
- self.profession))
- def __repr__(self):
- return '\n Name: {} \n hp = {} \n in hands: {} \n profession: {} \n def = {}'.format(self.name, self.hp,
- self.hands_slot, self.profession, self.defence)
- def add_exp(self, count):
- self.exp += count
- if self.exp - self.lvl*10 > 99:
- self.lvl += 1
- self.hp += 10
- class Warrior(Human):
- def __init__(self, name, hands_slot=None, hp=100, coord_x=0, coord_y=0, profession='warrior'):
- Human.__init__(self, name, hands_slot, hp, coord_x, coord_y, profession)
- self.weapon = 'sword'
- def attack(self):
- print('{} cut monster by {}'.format(self.name, self.weapon))
- def receive_damage(self, damage):
- self.hp -= damage
- #print('{} receive {} damage'.format(self.name, damage))
- def print_hp(self):
- print('{} has {}hp'.format(self.name, self.hp))
- class Defender(Warrior):
- def __init__(self, name, hands_slot=None, hp=100, coord_x=0, coord_y=0, profession='defender'):
- Warrior.__init__(self, name, hands_slot, hp, coord_x, coord_y, profession)
- self.damage = 10
- def attack(self, enemy):
- #print('{} damaged {} {} damage \n'.format(self.name, enemy.name, self.damage))
- enemy.receive_damage(self.damage)
- #enemy.print_hp()
- x = Defender('Leha')
- y = Defender("Gosha")
- for i in range(1000):
- duel(x, y)
- print(x.name, x.exp, x.lvl)
- print(y.name, y.exp, y.lvl)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement