Guest User

Untitled

a guest
Mar 15th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. from random import randint
  2.  
  3.  
  4. class Man:
  5.  
  6.     def __init__(self, name):
  7.         self.name = name
  8.         self.mood = 50
  9.         self.money = 0
  10.         self.cat_food = 0
  11.  
  12.     def status(self):
  13.         print('Я - {}, настроение на {}, денег - {}'.format(self.name, self.mood, self.money))
  14.  
  15.  
  16.     def go_work(self):
  17.         print('{} пошел на работу'.format(self.name))
  18.         self.money += 50
  19.         self.mood -= 10
  20.  
  21.     def play_DOTA(self):
  22.         print('{} играл в доту целый день'.format(self.name))
  23.         self.mood += 20
  24.  
  25.     def pick_up_the_cat(self, cat):
  26.         print('{} подобрал кота {}'.format(self.name, cat.name))
  27.         self.cat = cat
  28.         cat.man = self
  29.         self.mood += 10
  30.  
  31.     def buy_cat_food(self):
  32.         print('{} купил кошачьей еды'.format(self.name))
  33.         self.cat_food += 50
  34.         self.money -= 50
  35.  
  36.     def act(self):
  37.         dice = randint(1, 6)
  38.         if dice == 1:
  39.             self.go_work()
  40.         else:
  41.             self.play_DOTA()
  42.  
  43.  
  44.  
  45. class Cat:
  46.  
  47.     def __init__(self, name):
  48.         self.name = name
  49.         self.mood = 10
  50.         self.fullness = 10
  51.         self.man = None
  52.  
  53.     def status(self):
  54.         print('Я - {}, настроение на {}, сытость - {}'.format(self.name, self.mood, self.fullness))
  55.  
  56.     def sleep(self):
  57.         self.mood += 10
  58.         self.fullness -= 10
  59.         print('{} спал целый день'.format(self.name))
  60.  
  61.     def eat(self):
  62.         if self.man is None:
  63.             print('{}: я безхозный! '.format(self.name))
  64.         else:
  65.             if self.man.cat_food and self.man.cat_food > 10:
  66.                 print('{} поел '.format(self.name))
  67.                 self.man.cat_food -= 10
  68.                 self.fullness += 10
  69.             else:
  70.                 print('{}: у меня нет еды!  Мяу!'.format(self.name))
  71.  
  72.     def act(self):
  73.         if self.fullness <= 0:
  74.             print('Кот {} умер...'.format(self.name))
  75.             return
  76.         dice = randint(1, 6)
  77.         if dice == 1:
  78.             self.eat()
  79.         else:
  80.             self.sleep()
  81.  
  82.  
  83. vasya = Man(name='Вася')
  84. murzik = Cat(name='Мурзик')
  85. murzik.status()
  86. murzik.eat()
  87. vasya.pick_up_the_cat(cat=murzik)
  88. murzik.eat()
  89. vasya.buy_cat_food()
  90. murzik.eat()
  91. murzik.status()
  92.  
  93. for day in range(1, 21):
  94.     print('День {} ------------------'.format(day))
  95.     vasya.act()
  96.     murzik.act()
  97.  
  98.     vasya.status()
  99.     murzik.status()
Add Comment
Please, Sign In to add comment