Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from termcolor import cprint
- from random import randint
- class House:
- residents = list()
- def __init__(self):
- self.count_money_in_nightstand = 100
- self.count_food_in_refrigerator = 50
- self.count_mud = 0
- self.food_for_cat = 30
- def __str__(self):
- return 'В доме осталось {} денег и {} еды. Дом загрязнен на {}%'.format(
- self.count_money_in_nightstand, self.count_food_in_refrigerator, self.count_mud)
- class Man:
- coat = 0
- total_money = 0
- total_food = 0
- total_mud = 0
- def __init__(self, name, house):
- self.name = name
- self.fullness = 30
- self.happiness = 100
- self.house = house
- House.residents.append(self)
- def eat(self):
- print('{} ест'.format(self.name))
- self.house.count_food_in_refrigerator -= 30
- self.fullness += 30
- def stroking_a_cat(self):
- self.happiness += 5
- print('{} гладит кота'.format(self.name))
- def __str__(self):
- return '{}: Сытость {}, уровень счастья {}'.format(self.name, self.fullness, self.happiness)
- class Husband(Man):
- def work(self):
- cprint('{} целый день работал...'.format(self.name), color='green')
- self.happiness -= 10
- self.fullness -= 10
- self.house.count_money_in_nightstand += 150
- self.total_money += 150
- def gaming(self):
- cprint('{} целый день играл...'.format(self.name), color='green')
- self.fullness -= 10
- self.happiness += 20
- def act(self):
- if self.happiness <= 0:
- cprint('{} умер...'.format(self.name), color='red')
- return
- if self.fullness <= 0:
- cprint('{} умер...'.format(self.name), color='red')
- return
- if self.house.count_mud > 90:
- self.happiness -= 10
- dice = randint(1, 6)
- if self.fullness <= 10:
- self.eat()
- elif self.house.count_money_in_nightstand <= 50:
- self.work()
- elif self.happiness <= 10:
- self.gaming()
- elif dice == 1:
- self.gaming()
- elif dice == 2:
- self.stroking_a_cat()
- class Wife(Man):
- def shopping(self):
- if self.house.count_money_in_nightstand >= 50:
- if self.house.count_food_in_refrigerator <= 30:
- self.house.count_money_in_nightstand -= 30
- self.house.count_food_in_refrigerator += 30
- self.fullness -= 10
- self.total_food += 30
- cprint('{} сходила за продуктами'.format(self.name), color='cyan')
- def buy_fur_coat(self):
- self.house.count_money_in_nightstand -= 350
- self.happiness += 60
- self.coat += 1
- cprint('{} купила шубу, вернулась в 90-ые года, так как только тогда это было модно'.format(
- self.name))
- def buy_cat_food(self):
- if self.house.count_money_in_nightstand >= 50:
- if self.house.food_for_cat < 20:
- self.house.count_money_in_nightstand -= 50
- self.house.food_for_cat += 50
- self.total_food += 50
- cprint('{} сходил в магазин за едой для кота'.format(self.name), color='cyan')
- def clean_house(self):
- cprint('{} занялась уборкой'.format(self.name), color='cyan')
- self.fullness -= 10
- self.house.count_mud -= 100
- def act(self):
- if self.happiness <= 0:
- cprint('{} умерла...'.format(self.name), color='red')
- return
- if self.fullness <= 0:
- cprint('{} умерла...'.format(self.name), color='red')
- return
- dice = randint(1, 6)
- if self.fullness <= 10:
- self.eat()
- elif self.house.count_mud >= 100:
- self.clean_house()
- elif self.house.food_for_cat <= 10:
- self.buy_cat_food()
- elif self.house.count_food_in_refrigerator <= 50:
- self.shopping()
- elif self.happiness <= 10:
- self.buy_fur_coat()
- elif dice == 3:
- self.stroking_a_cat()
- residents = House.residents
- for i in residents:
- i.act() ? не могу вызвать функции через i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement