AIprojekt-wozek/Package.py

43 lines
1.4 KiB
Python
Raw Normal View History

2022-03-24 20:02:21 +01:00
import glob2
import pygame
import random
from Field import Field
from Global_variables import Global_variables as G_var
from Types_colors import Types_colors
from Package_types import Package_types
import math
2022-05-12 21:16:05 +02:00
from CompanyFactory import CompanyFactory
2022-03-24 20:02:21 +01:00
class Package(Field):
def __init__(self, window, x, y, type):
Field.__init__(self, window, x, y)
2022-03-24 20:02:21 +01:00
self.mark_image = self.get_marking_photo()
self.type = type
2022-05-12 21:16:05 +02:00
self.company = CompanyFactory()
self.payed_upfront = random.randint(0,1)
2022-04-25 17:58:51 +02:00
self.is_placed = False
2022-03-24 20:02:21 +01:00
def get_marking_photo(self):
file_path_type = ["resources/package_markings/*.jpg"]
images = glob2.glob(random.choice(file_path_type))
random_image = random.choice(images)
return random_image
def draw(self):
self.color = Types_colors.get_package_color(self.type)
block = pygame.Rect(self.x * G_var().RECT_SIZE, self.y *
G_var().RECT_SIZE, G_var().RECT_SIZE, G_var().RECT_SIZE)
pygame.draw.rect(self.window, self.color, block)
2022-03-24 20:02:21 +01:00
def choose_the_closest_shelf(self, shelves):
array = []
for shelf in shelves:
if shelf.type == self.type:
segment = math.sqrt((shelf.x - self.x) **
2 + (shelf.y - self.y)**2)
array.append((segment, shelf))
array.sort(key=lambda y: y[0])
print(array)
return array[0]