AI2020_Project/models/Garbagetruck.py

106 lines
3.5 KiB
Python

import pygame
import random
from models.dumpster import trash
class GarbageTruck():
def __init__(self):
self.coor = [0,0]
self.capacity = 5
self.plastic = 0
self.paper = 0
self.mixed = 0
self.organic = 0
self.glass = 0
self.trash=trash()
self.dir = 'R'
self.picture=pygame.image.load('./images/truckR.png')
def start(self):
self.coor = [random.randint(0,19),random.randint(0,19)]
return self.coor
def amIFull(self):
#check id garbage truck full
if ( self.plastic==self.capacity and self.paper==self.capacity and
self.glass==self.capacity and self.mixed==self.capacity and
self.organic==self.capacity):
return True
#otherwise see if a category is full
elif self.plastic!=self.capacity:
return False
elif self.paper!=self.capacity:
return False
elif self.glass!=self.capacity:
return False
elif self.mixed!=self.capacity:
return False
elif self.organic!=self.capacity:
return False
def move(self):
if(self.dir=="R"):
self.coor[0]+=1
elif(self.dir=="L"):
self.coor[0]-=1
elif(self.dir=="U"):
self.coor[1]-=1
elif(self.dir=="D"):
self.coor[1]+=1
def turn(self,goal):
if(goal[0]-self.coor[0]==1):
self.dir='R'
self.picture = pygame.image.load('./images/truckR.png')
elif(goal[0]-self.coor[0]==-1):
self.dir='L'
self.picture = pygame.image.load('./images/truckL.png')
elif(goal[1]-self.coor[1]==-1):
self.dir='U'
self.picture = pygame.image.load('./images/truckU.png')
elif(goal[1]-self.coor[1]==1):
self.dir='D'
self.picture = pygame.image.load('./images/truckD.png')
return dir
''' #old move
def move(self, coor, moving, size):
if(moving == 0 and coor[0] > 0):
coor[0] = coor[0] - 1
return(coor)
elif(moving == 1 and coor[1] > 0):
coor[1] = coor[1] - 1
return(coor)
elif(moving == 2 and coor[0] < size - 1):
coor[0] = coor[0] + 1
return(coor)
elif(moving == 3 and coor[1] < size - 1):
coor[1] = coor[1] + 1
return(coor)
else:
return(coor)'''
def collectingTrash(self, trash, id):
#1st if recognizes the dumpster kind
if trash[id].color==1:
#2nd if check if there is space in the garbage truck and if there is still trash
if self.plastic<self.capacity and trash[id].plastic > 0:
self.plastic+=1
return True
elif trash[id].color==2:
if self.paper<self.capacity and trash[id].paper > 0:
self.paper+=1
return True
elif trash[id].color==3:
if self.glass<self.capacity and trash[id].glass > 0:
self.glass+=1
return True
elif trash[id].color==4:
if self.organic<self.capacity and trash[id].organic > 0:
self.organic+=1
return True
elif trash[id].color==5:
if self.mixed<self.capacity and trash[id].mixed > 0:
self.mixed+=1
return True
else:
return False