Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Unit:
- def __init__(self, name, health, armor):
- self.name = name
- self.health = health
- self.armor = armor
- def print_info(self):
- print(F"Name: {self.name} Health: {self.health} Armor: {self.armor}", end=" ")
- class Warrior (Unit):
- def __init__(self, name, health, armor, ammo, gun):
- Unit.__init__(self, name, health, armor)
- self.ammo = ammo
- self.gun = gun
- def print_info(self):
- Unit.print_info(self)
- print(F"Ammo: {self.ammo} Gun: {self.health}")
- class Mech (Unit):
- def __init__(self, name, health, armor, ammo, gun):
- Unit.__init__(self, name, health, armor)
- self.ammo = ammo
- self.gun = gun
- def print_info(self):
- Unit.print_info(self)
- print(F"Ammo: {self.ammo} Gun: {self.health}")
- class Init:
- list_names = ["Tim", "Sergey", "Leha", "Mech1", "Mech2"]
- list_health = [115, 360, 228,712,876]
- list_armor = [10, 10, 10,0,0]
- list_ammo = ["9 × 19 mm Parabellum (pistol)", "5.56 mm NATO (interim)", "7.62 mm NATO (rifle)", "Draining Dexterous Dagger", "Energetic Power Wall"]
- list_gun = ["M-16", "MP-5", "MP-40", "Bullet", "Bullet"]
- all_armor = 0
- all_health = 0
- def main(self):
- 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)]
- 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)]
- check_out = True
- all_health = 0
- all_armor = 0
- for i in warrior + mech:
- self.all_health += i.health
- self.all_armor += i.armor
- while check_out:
- print("1 = info about every unit")
- print("2 = info about all army")
- print("3 = attack")
- print("4 = exit")
- check_enter = input()
- if check_enter == '1':
- for i in warrior + mech:
- i.print_info()
- if check_enter == '2':
- print(F"All health: {self.all_health} all armor: {self.all_armor}")
- if check_enter == '3':
- i = Init()
- i.attack(warrior, mech)
- if check_enter == '4':
- check_out = False
- def attack(self, warrior, mech):
- for i in warrior + mech:
- self.all_health += i.health
- self.all_armor += i.armor
- print("Enter damage: ", end=" ")
- damage = int(input())
- for i in warrior + mech:
- if self.all_health > 0:
- for j in warrior + mech:
- if i.health < 0:
- continue
- damage -= self.all_armor
- if damage <= 0:
- print("Defeat")
- break
- else:
- self.all_armor = 0
- init = Init()
- init.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement