import displayControler as dCon import Slot import Colors import pygame import time import Ui import math import random stoneList = [(3,3), (3,4), (3,5), (3,6), (4,6), (5,6), (6,6), (7,6), (8,6), (9,6), (10,6), (11,6), (12,6), (13,6), (14,6), (15,6), (16,6), (16,7), (16,8), (16,9)] stoneFlag = False class Pole: def __init__(self,screen,image_loader, gasStation = (-1, -1)): 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 self.gasStation=gasStation 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() garage=self.slot_dict[(0,0)] garage.set_garage_image() if stoneFlag: for i in stoneList: st=self.slot_dict[i] st.set_stone_image() if self.gasStation[0] != -1: st=self.slot_dict[self.gasStation] st.set_gasStation_image() def randomize_colors(self): pygame.display.update() time.sleep(3) #self.ui.render_text("Randomizing Crops") for coordinates in self.slot_dict: if(coordinates==(0,0) or coordinates in stoneList or coordinates == self.gasStation): continue else: 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) if(mouse_x