import displayControler as dCon import Slot import Colors import pygame import time import Ui import math class Pole: def __init__(self,screen,image_loader): self.screen=screen self.slot_dict={} #Slot are stored in dictionary with key being a Tuple of x and y coordinates so top left slot key is (0,0) and value is slot object self.ui=Ui.Ui(screen) self.image_loader=image_loader def get_slot_from_cord(self,coordinates): (x_axis,y_axis)=coordinates return self.slot_dict[(x_axis,y_axis)] def set_slot(self,coodrinates,slot): #set slot in these coordinates (x_axis,y_axis)=coodrinates self.slot_dict[(x_axis,y_axis)]=slot def get_slot_dict(self): #returns whole slot_dict return self.slot_dict #Draw grid and tractor (new one) def draw_grid(self): for x in range(0,dCon.NUM_X): #Draw all cubes in X axis for y in range(0,dCon.NUM_Y): #Draw all cubes in Y axis new_slot=Slot.Slot(x,y,Colors.BROWN,self.screen,self.image_loader) #Creation of empty slot self.set_slot((x,y),new_slot) #Adding slots to dict slot_dict=self.get_slot_dict() for coordinates in slot_dict: slot_dict[coordinates].draw() def randomize_colors(self): pygame.display.update() time.sleep(3) self.ui.render_text("Randomizing Crops") for coordinates in self.slot_dict: self.slot_dict[coordinates].set_random_plant() def change_color_of_slot(self,coordinates,color): #Coordinates must be tuple (x,y) (left top slot has cord (0,0) ), color has to be from defined in Colors.py or custom in RGB value (R,G,B) self.get_slot_from_cord(coordinates).color_change(color) def get_neighbor(self, slot, dx, dy): neighbor_x = slot.x_axis + dx neighbor_y = slot.y_axis + dy return self.get_slot_from_cord((neighbor_x, neighbor_y)) def is_valid_move(self, coordinates): return coordinates in self.slot_dict def check_collision(self,mouse_x,mouse_y): mouse_x=math.floor(mouse_x/dCon.CUBE_SIZE) mouse_y=math.floor(mouse_y/dCon.CUBE_SIZE) collided=self.get_slot_from_cord((mouse_x,mouse_y)) return collided.print_status()