-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeavAndBut.py
More file actions
88 lines (74 loc) · 2.53 KB
/
BeavAndBut.py
File metadata and controls
88 lines (74 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
from random import randint
from termcolor import cprint
class Man:
def __init__(self, name):
self.name = name
self.fullness = 50
self.house = None
def __str__(self):
return 'Я - {}, сытость {}'.format(self.name, self.fullness)
def eat(self):
if self.house.food >= 10:
cprint('{} поел'.format(self.name), color='yellow')
self.fullness += 10
self.house.food -= 10
else:
cprint('{} нет еды'.format(self.name), color='red')
def work(self):
cprint('{} сходил на работу'.format(self.name), color='blue')
self.house.money += 50
self.fullness -= 10
def watch_MTV(self):
cprint('{} смотрел MTV весь день'.format(self.name), color='green')
self.fullness -= 10
def shopping(self):
if self.house.money >= 50:
cprint('{} сходил в магазин за едой'.format(self.name), color='magenta')
self.house.money -= 50
self.house.food += 50
else:
cprint('{} деньги кончились!'.format(self.name), color='red')
def go_to_the_house(self, house):
self.house = house
self.fullness -= 10
cprint('{} вьехал в дом'.format(self.name), color='cyan')
def act(self):
if self.fullness <= 0:
cprint('{} умер'.format(self.name), color='red')
return
dice = randint(1, 6)
if self.fullness < 20:
self.eat()
elif self.house.food < 10:
self.shopping()
elif self.house.money < 50:
self.work()
elif dice == 1:
self.work()
elif dice == 2:
self.eat()
else:
self.watch_MTV()
class House:
def __init__(self):
self.food = 50
self.money = 0
def __str__(self):
return 'В доме еды осталось {}, денег осталось {}'.format(self.food, self.money)
citizens = [
Man(name='Бивис'),
Man(name='Батхед'),
Man(name='Кенни'),
]
my_sweet_home = House()
for citizen in citizens:
citizen.go_to_the_house(house=my_sweet_home)
for day in range(1, 366):
print('=================== день {} ====================='.format(day))
for citizen in citizens:
citizen.act()
print('---------- в конце дня -----------')
for citizen in citizens:
print(citizen)
print(my_sweet_home)