Prześlij pliki do 'models'
This commit is contained in:
parent
015bda6d7d
commit
679b8f0c66
105
models/Garbagetruck.py
Normal file
105
models/Garbagetruck.py
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
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
|
84
models/dumpster.py
Normal file
84
models/dumpster.py
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
import numpy as np
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
class trash():
|
||||||
|
def __init__(self):
|
||||||
|
self.id = 0
|
||||||
|
self.plastic = 0
|
||||||
|
self.paper = 0
|
||||||
|
self.mixed = 0
|
||||||
|
self.organic = 0
|
||||||
|
self.glass = 0
|
||||||
|
self.color = 0
|
||||||
|
self.xy = 0
|
||||||
|
self.value = 1
|
||||||
|
|
||||||
|
def giveID(self,id):
|
||||||
|
self.id = id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def throwAway(self):
|
||||||
|
trash = np.random.randint(1,6)
|
||||||
|
if trash == 1:
|
||||||
|
self.plastic += 1
|
||||||
|
return True
|
||||||
|
elif trash == 2:
|
||||||
|
self.paper += 1
|
||||||
|
return True
|
||||||
|
elif trash == 3:
|
||||||
|
self.glass += 1
|
||||||
|
return True
|
||||||
|
elif trash == 4:
|
||||||
|
self.organic += 1
|
||||||
|
return True
|
||||||
|
elif trash == 5:
|
||||||
|
self.mixed += 1
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def empty(self):
|
||||||
|
if self.plastic > 0:
|
||||||
|
self.plastic -= 1
|
||||||
|
print("taking plastic")
|
||||||
|
return True
|
||||||
|
elif self.paper > 0:
|
||||||
|
self.paper -= 1
|
||||||
|
print("taking paper")
|
||||||
|
return True
|
||||||
|
elif self.glass > 0:
|
||||||
|
self.glass -= 1
|
||||||
|
print("taking glass")
|
||||||
|
return True
|
||||||
|
elif self.organic > 0:
|
||||||
|
self.organic -= 1
|
||||||
|
print("taking organic")
|
||||||
|
return True
|
||||||
|
elif self.mixed > 0:
|
||||||
|
self.mixed -= 1
|
||||||
|
print("taking mixed")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("can't take trash from this dumpster")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def colour(self):
|
||||||
|
if self.plastic > 0:
|
||||||
|
self.color = 1
|
||||||
|
return True
|
||||||
|
elif self.paper > 0:
|
||||||
|
self.color = 2
|
||||||
|
return True
|
||||||
|
elif self.glass > 0:
|
||||||
|
self.color = 3
|
||||||
|
return True
|
||||||
|
elif self.organic > 0:
|
||||||
|
self.color = 4
|
||||||
|
return True
|
||||||
|
elif self.mixed > 0:
|
||||||
|
self.color = 5
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
Loading…
Reference in New Issue
Block a user