Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.45 KB | None | 0 0
  1. from termcolor import cprint
  2. from random import randint
  3.  
  4. class House:
  5.     residents = list()
  6.  
  7.     def __init__(self):
  8.         self.count_money_in_nightstand = 100
  9.         self.count_food_in_refrigerator = 50
  10.         self.count_mud = 0
  11.         self.food_for_cat = 30
  12.  
  13.     def __str__(self):
  14.         return 'В доме осталось {} денег и {} еды. Дом загрязнен на {}%'.format(
  15.             self.count_money_in_nightstand, self.count_food_in_refrigerator, self.count_mud)
  16. class Man:
  17.     coat = 0
  18.     total_money = 0
  19.     total_food = 0
  20.     total_mud = 0
  21.  
  22.     def __init__(self, name, house):
  23.         self.name = name
  24.         self.fullness = 30
  25.         self.happiness = 100
  26.         self.house = house
  27.         House.residents.append(self)
  28.  
  29.     def eat(self):
  30.         print('{} ест'.format(self.name))
  31.         self.house.count_food_in_refrigerator -= 30
  32.         self.fullness += 30
  33.  
  34.     def stroking_a_cat(self):
  35.         self.happiness += 5
  36.         print('{} гладит кота'.format(self.name))
  37.  
  38.     def __str__(self):
  39.         return '{}: Сытость {}, уровень счастья {}'.format(self.name, self.fullness, self.happiness)
  40. class Husband(Man):
  41.     def work(self):
  42.         cprint('{} целый день работал...'.format(self.name), color='green')
  43.         self.happiness -= 10
  44.         self.fullness -= 10
  45.         self.house.count_money_in_nightstand += 150
  46.         self.total_money += 150
  47.  
  48.     def gaming(self):
  49.         cprint('{} целый день играл...'.format(self.name), color='green')
  50.         self.fullness -= 10
  51.         self.happiness += 20
  52.  
  53.     def act(self):
  54.         if self.happiness <= 0:
  55.             cprint('{} умер...'.format(self.name), color='red')
  56.             return
  57.         if self.fullness <= 0:
  58.             cprint('{} умер...'.format(self.name), color='red')
  59.             return
  60.         if self.house.count_mud > 90:
  61.             self.happiness -= 10
  62.         dice = randint(1, 6)
  63.         if self.fullness <= 10:
  64.             self.eat()
  65.         elif self.house.count_money_in_nightstand <= 50:
  66.             self.work()
  67.         elif self.happiness <= 10:
  68.             self.gaming()
  69.         elif dice == 1:
  70.             self.gaming()
  71.         elif dice == 2:
  72.             self.stroking_a_cat()
  73. class Wife(Man):
  74.  
  75.     def shopping(self):
  76.         if self.house.count_money_in_nightstand >= 50:
  77.             if self.house.count_food_in_refrigerator <= 30:
  78.                 self.house.count_money_in_nightstand -= 30
  79.                 self.house.count_food_in_refrigerator += 30
  80.                 self.fullness -= 10
  81.                 self.total_food += 30
  82.                 cprint('{} сходила за продуктами'.format(self.name), color='cyan')
  83.  
  84.     def buy_fur_coat(self):
  85.         self.house.count_money_in_nightstand -= 350
  86.         self.happiness += 60
  87.         self.coat += 1
  88.         cprint('{} купила шубу, вернулась в 90-ые года, так как только тогда это было модно'.format(
  89.             self.name))
  90.  
  91.     def buy_cat_food(self):
  92.         if self.house.count_money_in_nightstand >= 50:
  93.             if self.house.food_for_cat < 20:
  94.                 self.house.count_money_in_nightstand -= 50
  95.                 self.house.food_for_cat += 50
  96.                 self.total_food += 50
  97.         cprint('{} сходил в магазин за едой для кота'.format(self.name), color='cyan')
  98.  
  99.     def clean_house(self):
  100.         cprint('{} занялась уборкой'.format(self.name), color='cyan')
  101.         self.fullness -= 10
  102.         self.house.count_mud -= 100
  103.  
  104.     def act(self):
  105.         if self.happiness <= 0:
  106.             cprint('{} умерла...'.format(self.name), color='red')
  107.             return
  108.         if self.fullness <= 0:
  109.             cprint('{} умерла...'.format(self.name), color='red')
  110.             return
  111.         dice = randint(1, 6)
  112.         if self.fullness <= 10:
  113.             self.eat()
  114.         elif self.house.count_mud >= 100:
  115.             self.clean_house()
  116.         elif self.house.food_for_cat <= 10:
  117.             self.buy_cat_food()
  118.         elif self.house.count_food_in_refrigerator <= 50:
  119.             self.shopping()
  120.  
  121.         elif self.happiness <= 10:
  122.             self.buy_fur_coat()
  123.         elif dice == 3:
  124.             self.stroking_a_cat()
  125. residents = House.residents
  126.  
  127. for i in residents:
  128.     i.act() ? не могу вызвать функции через i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement