AI_PROJECT/Pole.py

95 lines
3.5 KiB
Python
Raw Normal View History

import displayControler as dCon
import Slot
import Colors
import pygame
import time
import Ui
import math
import random
2024-05-25 02:00:19 +02:00
import neuralnetwork
import Image
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)
2024-05-25 02:00:19 +02:00
def draw_grid(self, nn=False):
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()
2024-05-11 13:25:36 +02:00
if self.gasStation[0] != -1:
st=self.slot_dict[self.gasStation]
st.set_gasStation_image()
2024-05-25 02:00:19 +02:00
def randomize_colors(self, nn = False):
pygame.display.update()
time.sleep(3)
#self.ui.render_text("Randomizing Crops")
for coordinates in self.slot_dict:
if(stoneFlag):
if( coordinates in stoneList or coordinates == self.gasStation ):
continue
if(coordinates==(0,0)):
continue
else:
2024-05-25 02:00:19 +02:00
self.slot_dict[coordinates].set_random_plant(nn)
def setPlantsByList(self, plantList):
pygame.display.update()
time.sleep(3)
for coordinates in self.slot_dict:
if(coordinates==(0,0)):
continue
else:
self.slot_dict[coordinates].set_specifided_plant(plantList[coordinates[1]][coordinates[0]])
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)
2024-03-23 21:00:08 +01:00
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)
2024-04-13 23:49:04 +02:00
if(mouse_x<dCon.NUM_X):
if(mouse_y<dCon.NUM_Y):
collided=self.get_slot_from_cord((mouse_x,mouse_y))
return collided.print_status()
return ""