2019-03-19 11:47:23 +01:00
|
|
|
import pygame
|
2019-03-21 01:25:19 +01:00
|
|
|
import sys
|
|
|
|
import random
|
2019-03-25 14:11:25 +01:00
|
|
|
from enum import Enum
|
2019-03-19 11:47:23 +01:00
|
|
|
from sprites.cell import Cell
|
2019-03-25 14:11:25 +01:00
|
|
|
from enums.house_image import House_image
|
2019-03-19 11:47:23 +01:00
|
|
|
|
2019-03-21 01:25:19 +01:00
|
|
|
PLASTIC = 0 # blue
|
|
|
|
GLASS = 1 # green
|
|
|
|
METAL = 2 # yellow
|
|
|
|
|
2019-03-19 18:10:04 +01:00
|
|
|
|
2019-03-19 11:47:23 +01:00
|
|
|
class House(Cell):
|
2019-03-21 01:25:19 +01:00
|
|
|
def __init__(self, x, y, max_plastic, max_glass, max_metal):
|
|
|
|
Cell.__init__(self, x, y)
|
2019-03-25 14:11:25 +01:00
|
|
|
self.image = pygame.image.load(House_image.house.value)
|
2019-03-21 01:25:19 +01:00
|
|
|
self.rubbish = [random.randint(0, max_plastic), random.randint(
|
|
|
|
0, max_glass), random.randint(0, max_metal)] # plastic, glass, metal
|
2019-03-19 18:40:36 +01:00
|
|
|
|
2019-03-21 01:25:19 +01:00
|
|
|
self.max_plastic = max_plastic
|
|
|
|
self.max_glass = max_glass
|
|
|
|
self.max_metal = max_metal
|
2019-03-19 18:40:36 +01:00
|
|
|
|
2019-03-21 01:25:19 +01:00
|
|
|
def generate_rubbish(self):
|
2019-03-25 16:03:25 +01:00
|
|
|
if(random.randint(0, 25) == 1): # 1/25 szansa na wyrzucenie śmiecia w klatce
|
2019-03-21 01:25:19 +01:00
|
|
|
thrash_type = random.randint(0, 2)
|
2019-03-26 23:13:34 +01:00
|
|
|
if(thrash_type == 0 and self.rubbish[thrash_type] < self.max_plastic):
|
|
|
|
self.rubbish[thrash_type] = self.rubbish[thrash_type] + 1
|
|
|
|
if(thrash_type == 1 and self.rubbish[thrash_type] < self.max_glass):
|
|
|
|
self.rubbish[thrash_type] = self.rubbish[thrash_type] + 1
|
|
|
|
if(thrash_type == 2 and self.rubbish[thrash_type] < self.max_metal):
|
|
|
|
self.rubbish[thrash_type] = self.rubbish[thrash_type] + 1
|
2019-03-19 18:40:36 +01:00
|
|
|
|
2019-03-25 14:11:25 +01:00
|
|
|
#mozna ladniej?
|
2019-03-26 23:13:34 +01:00
|
|
|
if(self.rubbish[PLASTIC] == self.max_plastic):
|
|
|
|
if(self.rubbish[GLASS] == self.max_glass):
|
|
|
|
if(self.rubbish[METAL] == self.max_metal):
|
2019-03-25 14:11:25 +01:00
|
|
|
self.image = pygame.image.load(House_image.full.value) #plastik, szklo, metal
|
|
|
|
else:
|
|
|
|
self.image = pygame.image.load(House_image.plastic_glass.value) #plastik, szklo
|
2019-03-26 23:13:34 +01:00
|
|
|
elif(self.rubbish[METAL] == self.max_metal):
|
2019-03-25 14:11:25 +01:00
|
|
|
self.image = pygame.image.load(House_image.plastic_metal.value) #plastik, metal
|
|
|
|
else:
|
|
|
|
self.image = pygame.image.load(House_image.plastic.value) #plastik
|
2019-03-26 23:13:34 +01:00
|
|
|
elif(self.rubbish[GLASS] == self.max_glass):
|
|
|
|
if(self.rubbish[METAL] == self.max_metal):
|
2019-03-25 14:11:25 +01:00
|
|
|
self.image = pygame.image.load(House_image.glass_metal.value) #szklo, metal
|
|
|
|
else:
|
|
|
|
self.image = pygame.image.load(House_image.glass.value) #szklo
|
2019-03-26 23:13:34 +01:00
|
|
|
elif(self.rubbish[METAL] == self.max_metal):
|
2019-03-25 14:11:25 +01:00
|
|
|
self.image = pygame.image.load(House_image.metal.value) #metal
|
2019-03-26 23:13:34 +01:00
|
|
|
else:
|
|
|
|
self.image = pygame.image.load(House_image.house.value) #niezapelnione
|
2019-03-25 17:41:24 +01:00
|
|
|
|
|
|
|
def give_away_rubbish(self, plastic, glass, metal):
|
2019-03-26 23:13:34 +01:00
|
|
|
print("HOUSE>> Before giving away "+str(self.rubbish[PLASTIC])+" plastic, "+str(self.rubbish[GLASS])+" glass, "+str(self.rubbish[METAL])+" metal, ")
|
2019-03-25 17:41:24 +01:00
|
|
|
self.rubbish[PLASTIC] -= plastic
|
|
|
|
self.rubbish[GLASS] -= glass
|
|
|
|
self.rubbish[METAL] -= metal
|
2019-03-26 23:13:34 +01:00
|
|
|
print("HOUSE>> Gave away "+str(plastic)+" plastic, "+str(glass)+" glass, "+str(metal)+" metal, ")
|
|
|
|
print("HOUSE>> After giving away "+str(self.rubbish[PLASTIC])+" plastic, "+str(self.rubbish[GLASS])+" glass, "+str(self.rubbish[METAL])+" metal, ")
|
2019-03-19 18:40:36 +01:00
|
|
|
|
2019-03-21 01:25:19 +01:00
|
|
|
def check_rubbish_status(self):
|
|
|
|
print("plastic: " + str(self.rubbish[PLASTIC]) + " glass: " + str(
|
|
|
|
self.rubbish[GLASS]) + " metal: " + str(self.rubbish[METAL]))
|
2019-03-25 16:03:25 +01:00
|
|
|
|
|
|
|
def get_rubbish_data(self):
|
|
|
|
return self.rubbish
|
2019-03-26 23:13:34 +01:00
|
|
|
|
|
|
|
def get_coordinates(self):
|
|
|
|
return self.x, self.y
|