def __init__(self):
self.path = 'icons'
self.white_list = cv2.imread('python_snippets/external_data/probe.jpg')
self.cloud = cv2.imread('python_snippets/external_data/weather_img/cloud.jpg')
self.sun = cv2.imread('python_snippets/external_data/weather_img/sun.jpg')
self.rain = cv2.imread('python_snippets/external_data/weather_img/rain.jpg')
self.snow = cv2.imread('python_snippets/external_data/weather_img/snow.jpg')
self.yellow = (0, 255, 255)
self.blue = (255, 255, 0)
self.cyan = (255, 0, 0)
self.black = (0, 0, 0)
self.colors = [self.yellow,self.cyan,self.blue,self.black]
self.weather_icons ={self.black:self.cloud,self.yellow:self.sun,self.cyan:self.rain,self.blue:self.snow}
self.weather = {'Сплошная облачность': self.black,
'Небольшая облачность': self.black,
'Сплошная облачность, мелкий мокрый снег': self.black,
'Сплошная облачность, небольшой снег': self.black,
'Сплошная облачность, мелкий дождь':self.black,
'Облачно с прояснениями': self.black,
'Ясно': self.yellow,
'Дождь': self.cyan,
'Облачно с прояснениями, мелкий дождь':self.cyan,
'Снег': self.blue,
'Сплошная облачность, снег':self.black}
def maker(self, color, degree):
x = 0
y = 400
weather_icon = self.weather_icons[color]
self.painting_background(color, self.white_list)
self.white_list[x:x + weather_icon.shape[0], y:y + weather_icon.shape[1]] = weather_icon
cv2.putText(self.white_list, degree, (360, 150), cv2.FONT_HERSHEY_DUPLEX, 2, (255, 0, 0), 2, cv2.LINE_AA)
class PrimeNumbers:
def __init__(self, n):
self.prime_numbers = []
self.n = n
self.i = 0
def __iter__(self):
self.i = 1
return self
def get_prime_numbers(self):
self.i += 1
for prime in self.prime_numbers:
if self.i % prime == 0:
return False
return True
def __next__(self):
while self.i < self.n:
if self.get_prime_numbers():
self.prime_numbers.append(self.i)
return self.i
else:
raise StopIteration()
class Cat:
def __init__(self, name):
self.name = name
self.fullness = 50
self.house = 'cat_house'
def __str__(self):
return 'Я - {}, сытость {}'.format(
self.name, self.fullness,
)
def eat(self):
if self.house.cat_food >= 10:
cprint('{} поел'.format(self.name), color='yellow')
self.fullness += 20
self.house.cat_food -= 10
else:
cprint('{} нет еды'.format(self.name), color='red')
def go_to_the_house(self, house):
self.house = house
cprint('{} Вьехал в дом'.format(self.name), color='cyan')
def sleep(self):
self.fullness -= 10
def cat_rips_off_wallpaper(self,house):
self.house=house
self.fullness -= 10
self.house.dirt += 5
def act(self):
if self.fullness <= 0:
cprint('{} умер...'.format(self.name), color='red')
return
dice = randint(1, 4)
if self.fullness < 20:
self.eat()
elif dice == (1, 2):
self.eat()
elif dice == 3:
self.cat_rips_off_wallpaper(house)
elif dice == 4:
self.sleep()
class Man:
def __init__(self, name, house):
self.name = name
self.fullness = 50
self.house = house
self.cat = None
self.list = []
self.food = 50
self.money = 50
def __str__(self):
return 'Я - {}, сытость {}'.format(
self.name, self.fullness,
)
def eat(self):
if self.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 += 150
self.fullness -= 10
def catch_cat(self, cat):
self.cat = cat
self.list.append(cat)
cat.house = self.house
cprint('{} словил кота'.format(self.name), color='green')
self.fullness -= 20
def cleaning(self):
cprint('{} убрался'.format(self.name), color='green')
self.fullness -= 20
self.house.dirt -= 100
def shopping(self):
if self.house.money >= 100:
cprint('{} сходил в магазин за едой'.format(self.name), color='magenta')
self.house.money -= 100
self.house.food += 50
self.house.cat_food += 50
else:
cprint('{} деньги кончились!'.format(self.name), color='red')
def act(self):
if self.fullness <= 0:
cprint('{} умер...'.format(self.name), color='red')
return
dice = randint(1, 6)
if self.fullness < 50:
self.eat()
elif self.house.food < 10:
self.shopping()
elif self.house.money < 150:
self.work()
elif self.house.cat_food < 10:
self.work()
elif self.house.dirt == 100:
self.cleaning()
elif dice == 1:
self.work()
elif dice == 2:
self.eat()
class House:
def __init__(self):
self.food = 50
self.cat_food = 50
self.money = 50
self.dirt = 0
def __str__(self):
return 'В доме еды осталось {}, кошачей еды {}, денег осталось {}, грязи {}'.format(
self.food, self.cat_food, self.money, self.dirt
)
house = House()
man = Man(name='Бивис', house=house)
cat = Cat(name='Рыжик')
man.catch_cat(cat)
citizens = [
Man(name='Бивис',house=house),
Cat(name='Рыжик'),
]
for day in range(1, 366):
print('================ день {} =================='.format(day))
for citisen in citizens:
citisen.act()
print('--- в конце дня ---')
for citisen in citizens:
print(citisen)
print(man.house)
class Fire:
def __str__(self):
return 'Огонь'
def __add__(self, other):
if isinstance(other, Aqua):
return Vapor(part1=self, part2=other)
elif isinstance(other, Earth):
return Lava(part1=self, part2=other)
elif isinstance(other, Air):
return Lightning(part1=self, part2=other)