Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. class Warrior:
  2.     def __init__(self):
  3.         pass
  4.     h = 50
  5.     a = 5
  6.  
  7.     @property
  8.     def health(self):
  9.         return self.h
  10.    
  11.     @health.setter
  12.     def health(self, value):
  13.         self.h = value
  14.  
  15.     def attack(self):
  16.         return self.a
  17.  
  18.     @property
  19.     def is_alive(self):
  20.         if self.health > 0:
  21.             return True
  22.         return False
  23.            
  24. class Knight(Warrior):
  25.     a = 7
  26.  
  27. def fight(unit_1, unit_2):
  28.     while True:
  29.         unit_2.health = unit_2.health - unit_1.attack()
  30.         if not unit_2.is_alive:
  31.             return True
  32.         unit_1.health = unit_1.health - unit_2.attack()
  33.         if not unit_1.is_alive:
  34.             return False
  35.  
  36. if __name__ == '__main__':
  37.     #These "asserts" using only for self-checking and not necessary for auto-testing
  38.  
  39.     chuck = Warrior()
  40.     bruce = Warrior()
  41.     carl = Knight()
  42.     dave = Warrior()
  43.     mark = Warrior()
  44.  
  45.     assert fight(chuck, bruce) == True
  46.     assert fight(dave, carl) == False
  47.     assert chuck.is_alive == True
  48.     assert bruce.is_alive == False
  49.     assert carl.is_alive == True
  50.     assert dave.is_alive == False
  51.     assert fight(carl, mark) == False
  52.     assert carl.is_alive == False
  53.  
  54.     print("Coding complete? Let's try tests!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement