From 679b8f0c66c50cb2a68aa270e4b7a59f1daa2e9e Mon Sep 17 00:00:00 2001 From: Kamila Bobkowska Date: Fri, 1 May 2020 10:36:39 +0000 Subject: [PATCH] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20'models'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/Garbagetruck.py | 105 +++++++++++++++++++++++++++++++++++++++++ models/dumpster.py | 84 +++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 models/Garbagetruck.py create mode 100644 models/dumpster.py diff --git a/models/Garbagetruck.py b/models/Garbagetruck.py new file mode 100644 index 0000000..6750311 --- /dev/null +++ b/models/Garbagetruck.py @@ -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 0: + self.plastic+=1 + return True + elif trash[id].color==2: + if self.paper 0: + self.paper+=1 + return True + elif trash[id].color==3: + if self.glass 0: + self.glass+=1 + return True + elif trash[id].color==4: + if self.organic 0: + self.organic+=1 + return True + elif trash[id].color==5: + if self.mixed 0: + self.mixed+=1 + return True + else: + return False diff --git a/models/dumpster.py b/models/dumpster.py new file mode 100644 index 0000000..4cd3078 --- /dev/null +++ b/models/dumpster.py @@ -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