Advertisement
BERKYT

Untitled

Sep 30th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.00 KB | None | 0 0
  1. class Unit:
  2.     def __init__(self, name, health, armor):
  3.         self.name = name
  4.         self.health = health
  5.         self.armor = armor
  6.  
  7.     def print_info(self):
  8.         print(F"Name: {self.name} Health: {self.health} Armor: {self.armor}", end=" ")
  9.  
  10. class Warrior (Unit):
  11.     def __init__(self, name, health, armor, ammo, gun):
  12.         Unit.__init__(self, name, health, armor)
  13.         self.ammo = ammo
  14.         self.gun = gun
  15.  
  16.     def print_info(self):
  17.         Unit.print_info(self)
  18.         print(F"Ammo: {self.ammo} Gun: {self.health}")
  19.  
  20. class Mech (Unit):
  21.     def __init__(self, name, health, armor, ammo, gun):
  22.         Unit.__init__(self, name, health, armor)
  23.         self.ammo = ammo
  24.         self.gun = gun
  25.  
  26.     def print_info(self):
  27.         Unit.print_info(self)
  28.         print(F"Ammo: {self.ammo} Gun: {self.health}")
  29.  
  30. class Init:
  31.     list_names = ["Tim", "Sergey", "Leha", "Mech1", "Mech2"]
  32.     list_health = [115, 360, 228,712,876]
  33.     list_armor = [10, 10, 10,0,0]
  34.     list_ammo = ["9 × 19 mm Parabellum (pistol)", "5.56 mm NATO (interim)", "7.62 mm NATO (rifle)", "Draining Dexterous Dagger", "Energetic Power Wall"]
  35.     list_gun = ["M-16", "MP-5", "MP-40", "Bullet", "Bullet"]
  36.     all_armor = 0
  37.     all_health = 0
  38.  
  39.     def main(self):
  40.         warrior = [Warrior(self.list_names[i], self.list_health[i], self.list_armor[i], self.list_ammo[i], self.list_gun[i])for i in range(3)]
  41.         mech = [Mech(self.list_names[i+3], self.list_health[i+3], self.list_armor[i+3], self.list_ammo[i+3], self.list_gun[i])for i in range(2)]
  42.         check_out = True
  43.         all_health = 0
  44.         all_armor = 0
  45.  
  46.         for i in warrior + mech:
  47.             self.all_health += i.health
  48.             self.all_armor += i.armor
  49.  
  50.         while check_out:
  51.             print("1 = info about every unit")
  52.             print("2 = info about all army")
  53.             print("3 = attack")
  54.             print("4 = exit")
  55.             check_enter = input()
  56.             if check_enter == '1':
  57.                 for i in warrior + mech:
  58.                     i.print_info()
  59.             if check_enter == '2':
  60.                 print(F"All health: {self.all_health} all armor: {self.all_armor}")
  61.             if check_enter == '3':
  62.                 i = Init()
  63.                 i.attack(warrior, mech)
  64.             if check_enter == '4':
  65.                 check_out = False
  66.  
  67.     def attack(self, warrior, mech):
  68.         for i in warrior + mech:
  69.             self.all_health += i.health
  70.             self.all_armor += i.armor
  71.         print("Enter damage: ", end=" ")
  72.         damage = int(input())
  73.         for i in warrior + mech:
  74.             if self.all_health > 0:
  75.                 for j in warrior + mech:
  76.                     if i.health < 0:
  77.                         continue
  78.  
  79.                     damage -= self.all_armor
  80.                     if damage <= 0:
  81.                         print("Defeat")
  82.                         break
  83.                     else:
  84.                         self.all_armor = 0
  85.  
  86. init = Init()
  87. init.main()
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement