diff --git a/src/Game.py b/src/Game.py index 02262678172e66ed8a73b9186631ce0998600e8b..aeb67043aec0c1e3b89f86e50004a499845b0c3a 100644 --- a/src/Game.py +++ b/src/Game.py @@ -1,448 +1,448 @@ -import pygame -import random -from Champs import * -import numpy as np -from Camera import Camera -from Image import * -from Temps import Temps -from Infrastructure import * - -RAYON_MUR_INVISIBLE = 2000 -SAISONS = ["Printemps", "Été", "Automne", "Hiver"] -MOIS = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"] -police = pygame.font.SysFont("roboto", 30) - -#TODO : MAJEUR : continuer le pourcentage des plantes - #1-> Faire une hiérarchie entre les batiments si il ya un puit et un reservoir appliquer le boost du reservoir et non du puit - #2->quand on place un batiment possable sur un champ il affiche le descripteur du champ et pas de l'infrastructure - - -class Game: - imagestaticplantation = pygame.image.load('../assets/Interface/imagePlantation.jpeg') - imagestaticbatiment = pygame.image.load('../assets/Interface/imageBatiment.jpeg') - imagestaticinfor = pygame.image.load('../assets/Interface/imageinfo.jpg') - def __init__ (self): - self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) - self.image = Image(self.screen) - self.screenSize = np.array(self.screen.get_size()) - self.score = 0 - self.money = 40000 - self.displayMoney = 40000 - self.month = 0 - self.nombreBatiments = 0 - self.nombreChamps = 0 - self.champs = [] - self.batiment = [] - - self.temps = Temps() - for i in range(12): - self.champs.append(Buisson(((i%4)*300-550,(i//4)*250-430))) - self.clock = pygame.time.Clock() - self.selectedChamp = None - self.selectedBatiment = None - - self.imageMoney = pygame.transform.scale(self.image.moneyImage, np.array(self.image.moneyImage.get_size())/5) - - self.camera = Camera(np.array(self.screen.get_size())/2) - - self.frame = 0 - self.buyFrame = -1000 - - self.tourSuivantOriginal = self.image.arrowNextImage - self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (100,100)) - self.coordonneeSuite = self.screenSize[0]-self.tourSuivantModif.get_width() - 120, self.screenSize[1] - self.tourSuivantModif.get_height() - 120 - self.suiteRectangle = pygame.rect.Rect(*self.coordonneeSuite, 100, 100) - - self.coordonne_info = pygame.rect.Rect(self.screen.get_width()*0.82,self.screen.get_height()*0.18,self.screen.get_width()*0.19,self.screen.get_height()*0.5) - self.recInformation = pygame.rect.Rect(self.coordonne_info) - self.rectPlantation = pygame.rect.Rect(0,0,self.temps.getImageSaison().get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height()) - self.recBatiment = pygame.rect.Rect(self.temps.getImageSaison().get_width(), self.screen.get_height() - self.temps.getImageSaison().get_height(), self.screen.get_width() * 0.65, self.temps.getImageSaison().get_height()) - - self.rectPlantationimage = pygame.transform.scale(Game.imagestaticplantation,(self.rectPlantation.w,self.rectPlantation.h)) - self.rectBatimentimage = pygame.transform.scale(Game.imagestaticbatiment,(self.recBatiment.w,self.recBatiment.h)) - self.rectinfoimage = pygame.transform.scale(Game.imagestaticinfor,(self.recInformation.w,self.recInformation.h)) - - self.recTourSuivant = pygame.rect.Rect( - self.recBatiment.x + self.recBatiment.w ,self.screen.get_height() - self.temps.getImageSaison().get_height(), - self.screen.get_width() - self.temps.getImageSaison().get_width() - self.recBatiment.w,self.temps.getImageSaison().get_height()) - - #DragAndDrop - self.dragBatiment = None - self.dragPlantation = None - - - - - def gameLoop (self): - while True: - - self.screen.blit(self.image.backgroundImage, (0,0)) - - #CHAMPS------------------ - # Affichage des champs - for champ in self.champs: - champ.draw(self.screen, self.camera) - - for bat in self.batiment: - bat.draw(self.screen, self.camera) - #DEBUT BOUCLE INTERFACE------------------------ - - #Onglet Information - #pygame.draw.rect(self.screen, (0, 127, 0), self.recInformation) - self.screen.blit(Game.imagestaticinfor,(self.coordonne_info.x,self.coordonne_info.y)) - - # Météo - self.screen.blit(self.temps.getImageSaison(), (0, self.screen.get_height() - 300)) - self.screen.blit(self.temps.iconSaison,(10,self.screen.get_height() - self.temps.iconSaison.get_height())) - self.screen.blit(self.temps.tempsaisonImage,(10,self.screen.get_height() - self.temps.iconSaison.get_height() - 50)) - - self.screen.blit(self.temps.nexticonSaison,(self.temps.getImageSaison().get_width() - self.temps.nexticonSaison.get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height() +20)) - self.screen.blit(self.temps.tempsaisonImageDeuxPosiiton,(self.temps.getImageSaison().get_width() - self.temps.nexticonSaison.get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height())) - - - #Onglet plantation - - self.screen.blit(self.rectPlantationimage,(0,0)) - #Onglet tour suivant - pygame.draw.rect(self.screen,(0, 127, 0),(self.recTourSuivant)) - self.screen.blit(self.tourSuivantModif, (self.recTourSuivant.x+ (self.recTourSuivant.w - self.tourSuivantModif.get_width())/2, - self.recTourSuivant.y+ (self.recTourSuivant.h - self.tourSuivantModif.get_height())/2)) - - for i,c in enumerate(typePlantation): - x = self.rectPlantation.x + ( 0 if i%2 else 170) - y = self.rectPlantation.y + (i//2) * self.rectPlantationimage.get_height()/4 - - # Redimensionner l'image - c.iconStatic = transformImage(c.iconStatic, self.rectPlantationimage.get_width()/3.5, self.rectPlantationimage.get_height()/5.5) - - r = pygame.rect.Rect(x,y,c.iconStatic.get_width(),c.iconStatic.get_height()+ 20 ) - self.screen.blit(c.textStatic, (x,y)) - self.screen.blit(c.iconStatic,(x,y+c.textStatic.get_height() )) - if ( (r.collidepoint(pygame.mouse.get_pos()))): - pygame.draw.rect(self.screen,(138, 227, 237), r,1) - self.screen.blit(c.textDescriptionStatic,(self.recInformation.x,self.recInformation.y)) - - - #Onglet batiment - self.screen.blit(self.rectBatimentimage,(self.temps.getImageSaison().get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height())) - for i,c in enumerate(typeBatiment): - x = self.recBatiment.x + i* self.rectBatimentimage.get_width() / 6 - y = self.recBatiment.y + 50 - r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) - self.screen.blit(c.textStatic, (x,y)) - self.screen.blit(c.iconStatic,(x,y + c.textStatic.get_height())) - if ( (r.collidepoint(pygame.mouse.get_pos()))): - pygame.draw.rect(self.screen,(138, 227, 237), r,1) - self.screen.blit(c.textDescriptionStatic,(self.recInformation.x,self.recInformation.y)) - - # FIN BOUCLE INTERFACE ------------------------ - - - isChamp = False - isbatiment = False - - - if self.money < self.displayMoney: - self.displayMoney -= min(444, self.displayMoney - self.money) # Si quelque chose coûte moins que 100, changer par -= min(100, self.displayMoney - self.money) - elif self.money > self.displayMoney: - self.displayMoney+= min(444, self.money - self.displayMoney) # Si quelque chose coûte moins que 100, changer par -= min(100, self.money - self.displayMoney) - - - #self.displayMoney = self.money - - textMoney = police.render(str(self.displayMoney), True, (255,255,255)) - - self.CoRecArgent = pygame.rect.Rect(self.screen.get_width(), 0, 100, 100) - self.recArgent = pygame.draw.rect(self.screen,(255,0,0),(self.CoRecArgent)) - - self.screen.blit(textMoney, (self.screen.get_width() - self.imageMoney.get_width() - textMoney.get_width(),self.imageMoney.get_height()/2)) - self.screen.blit(self.imageMoney, (self.screen.get_width() - self.imageMoney.get_width() , 0)) - - - for event in pygame.event.get(): - if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: - exit() - - #Deplacement de la souris - elif event.type == pygame.MOUSEMOTION: - #drag and drop + interface des batiment et plantation - if event.buttons[2] == 1: #maintenir enfoncé clic droit - self.camera.setPosition(np.array(event.rel)) - - if event.buttons[0] == 1:#maintenir enfoncé clic gauche - if self.dragBatiment == None and self.dragPlantation == None: - for i,c in enumerate(typeBatiment): - x = self.recBatiment.x + i* self.rectBatimentimage.get_width() / 6 - y = self.recBatiment.y + 50 - r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) - if ( (r.collidepoint(event.pos))): - self.dragBatiment = c - if(self.dragBatiment): - self.screen.blit(self.dragBatiment.iconStatic, (event.pos)) - - - if self.dragPlantation == None and self.dragBatiment == None: - - for i,c in enumerate(typePlantation): - - x = self.rectPlantation.x + ( 0 if i%2 else 170) - y = self.rectPlantation.y + (i//2) * self.rectPlantationimage.get_height()/4 - r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) - if ( (r.collidepoint(event.pos))): - self.dragPlantation = c - - if(self.dragPlantation): - self.screen.blit(self.dragPlantation.iconStatic, (event.pos)) - - - else: - if self.dragPlantation: - for champ in self.champs: - if champ.rectScale.collidepoint(event.pos): - if self.dragPlantation == Pesticide: - champ.isInfeste = False - - elif isinstance(champ,TerrainVide): - newChamp = self.dragPlantation(champ.pos) - self.champs.append(newChamp) - newChamp.setInformation("Occupe" ,"Champ occupé") - newChamp.setInformation("Nom", "Champ contient "+ self.dragPlantation.__name__) - newChamp.setInformation("coutEntretien","90€ coût d'entretien mensuel") - - self.champs.remove(champ) - #Perdre l'argent - variable = self.dragPlantation.montantAchat - self.moneyDefile(-variable) - - - - if self.dragBatiment: - for champ in self.champs: - if champ.rectScale.collidepoint(event.pos): - if isinstance(champ,TerrainVide) or type(champ) in typePlantation: - newBat = self.dragBatiment(champ.pos) - self.batiment.append(newBat) - champ.isbat = newBat - - newBat.setInformation("Occupe", "Espace occupé") - newBat.setInformation("Nom","Emplacement pour"+str(self.dragBatiment.NameObjet)) - newBat.setInformation("coutEntretien","117€ d'entretien mensuel ") - champ.showInfo(self.screen,self.recInformation,newBat.descripteurInfrastructure) - - #Perdre l'argent - variable = self.dragBatiment.montantAchat - - self.moneyDefile(-variable) - self.nombreBatiments += 1 - - if self.dragBatiment not in [Torche,Serre,Irrigation,IrrigationGoutte]: - self.champs.remove(champ) - - self.nombreChamps -= 1 - - - self.dragPlantation = None - self.dragBatiment = None - - - - - for champ in self.champs + self.batiment: - if champ.rectScale.contains(event.pos[0],event.pos[1],0,0): - self.selectedChamp = champ - self.selectedBatiment = champ - isChamp = True - isbatiment = True - - - if not isChamp: - self.selectedChamp = None - - if not isbatiment: - self.selectedBatiment = None - - if (*event.pos,0,0) in self.recTourSuivant: - self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (200, 200)) - else: - self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (100, 100)) - - - - elif event.type == pygame.MOUSEWHEEL: - self.camera.zoomInOut(event.y) - - - elif event.type == pygame.MOUSEBUTTONDOWN: - - if event.button == 1: # Click gauche - #Declanchement du tour suivant - if(self.recTourSuivant.collidepoint(event.pos)): - self.coutEntretien() - self.temps.NextTurn() - - - #Code qui implemente la variation du pourcentage des plantes - #Vérification de la construction de batiment d'eau quand il fait chaud avec different cas - #self.ChangePourcentFanne(Serre,["orage"],2) - if (self.temps.currentSeason == "été"): - #self.ChangePourcentFanne(ReservoirEau,["canicule","secheresse"],20,"chaud",10), - for bat in self.batiment: - print("batiment reconnu") - print("len batiment : "+ str(self.batiment)) - if (type(bat) == ReservoirEau): - self.ChangePourcentFanne(ReservoirEau,["canicule","secheresse"],5,"chaud",2) - elif(type(bat) == Puit): - self.ChangePourcentFanne(Puit,["canicule","secheresse"],10,"chaud",5) - elif(type(bat) == Irrigation): - self.ChangePourcentFanne(Irrigation,["canicule","secheresse"],10,"chaud",5) - elif(type(bat) == IrrigationGoutte): - self.ChangePourcentFanne(irrigationGoutte,["canicule","secheresse"],5,"chaud",2) - if(len(self.batiment) == 0): - print("pas de batiment") - for champ in self.champs: - champ.pourcentagePlanteFane += 20 - champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) - - elif (self.temps.currentSeason == "Automne"): - #self.ChangePourcentFanne(Serre,["neige","froid"],20) - for bat in self.batiment: - if (type(bat) == Serre): - self.ChangePourcentFanne(Serre,["neige","froid"],5) - elif(type(bat) == Puit): - self.ChangePourcentFanne(Torche,["neige","froid"],10) - if(len(self.batiment) == 0): - print("pas de batiment") - for champ in self.champs: - champ.pourcentagePlanteFane += 15 - champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) - - elif (self.temps.currentSeason == "Hiver"): - self.AideEtat() - #self.ChangePourcentFanne(Serre,["neige","froid"],30) - for bat in self.batiment: - if (type(bat) == Serre): - self.ChangePourcentFanne(Serre,["neige","froid"],5) - elif(type(bat) == Puit): - self.ChangePourcentFanne(Torche,["neige","froid"],10) - if(len(self.batiment) == 0): - print("pas de batiment") - for champ in self.champs: - champ.pourcentagePlanteFane += 15 - champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) - - #Ajouter torche est faire une hiérarchie - elif(self.temps.currentSeason == "Printemps"): - #self.ChangePourcentFanne(ReservoirEau,["chaud"],15) - for bat in self.batiment: - if (type(bat) == ReservoirEau): - self.ChangePourcentFanne(ReservoirEau,["chaud"],2) - elif(type(bat) == Puit): - self.ChangePourcentFanne(Puit,["chaud"],5,) - elif(type(bat) == Irrigation): - self.ChangePourcentFanne(Irrigation,["chaud"],5) - elif(type(bat) == IrrigationGoutte): - self.ChangePourcentFanne(irrigationGoutte,["chaud"],2) - if(len(self.batiment) == 0): - print("pas de batiment") - for champ in self.champs: - champ.pourcentagePlanteFane += 15 - champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) - - - for champ in self.champs: - if type(champ) in typePlantation: - if champ.isInfeste: - champ.indiceImage = 4 - self.VerifPlantFane(champ) - if(random.random()< 0.10): - champ.isInfeste = True - - for bat in self.batiment: - print("passe ici") - print(type(bat)) - if(bat.verifDureeVie()): - print("changer") - self.champs.append(TerrainVide(bat.pos)) - self.batiment.remove(bat) - - # Achat - for champ in self.champs: - - #click sur un champ - if champ.rectScale.collidepoint(event.pos): - #Vente des plantes - if(champ.indiceImage > 3): - self.champs.append(TerrainVide(champ.pos)) - self.champs.remove(champ) - elif(champ.indiceImage == 3): - self.moneyDefile(champ.montantVente) - self.champs.append(TerrainVide(champ.pos)) - self.champs.remove(champ) - - - #Achat d'un terrain vide - if isinstance(champ, Buisson): - #if self.money >= champ.prix: - self.moneyDefile(-champ.prix) - self.champs.append(champ.buyField()) - self.champs.remove(champ) - self.nombreChamps += 1 - - - - if self.frame < self.buyFrame + 20: - self.screen.blit(self.moneyChange, (self.screen.get_width() - self.imageMoney.get_width() - textMoney.get_width(), (self.frame-self.buyFrame)*1.5)) - #self.screen.blit(self.moneyChange, (200, self.screen.get_height()-textMoney.get_height()*4+(self.frame-self.buyFrame)*1.5)) - - if self.selectedChamp and self.selectedBatiment: - self.selectedChamp.showInfo(self.screen,self.recInformation) - self.selectedBatiment.showInfo(self.screen,self.recInformation) - pygame.display.update() - self.clock.tick(50) - self.frame += 1 - - def moneyDefile(self,montant): - self.moneyChange = police.render(str(montant), True, (200,0,0) if montant < 0 else (0,250,0) ) - self.buyFrame = self.frame - self.money+= montant - - def AideEtat(self): - self.moneyDefile(5000) - - def ChangePourcentFanne(self,infra,case1,augmentation1, case2 = "",augmentation2 = 0): - print("fonction rentrer avec : ") - print(case1) - print(case2) - print("compare avec : "+ str(self.temps.currentTempsName) +" et les cas : "+str(case1)) - print("rentre dans le premier if batiment : "+str(not (infra in [type(bat) for bat in self.batiment]))) - print("chaud" in ["chaud","secheresse"]) - print(self.temps.currentTempsName) - if not (infra in [type(bat) for bat in self.batiment]): - print(self.temps.currentTempsName in case1) - if(self.temps.currentTempsName in case1): - for champ in self.champs: - champ.pourcentagePlanteFane += augmentation1 - champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) - elif(self.temps.currentTempsName == case2): - for champ in self.champs: - champ.pourcentagePlanteFane += augmentation2 - champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) - - - def VerifPlantFane(self,champ): - nbrrandom = random.randint(0,100) - if nbrrandom < champ.pourcentagePlanteFane: - champ.indiceImage = 4 - champ.plantationGrandit() - - def coutEntretien(self): - cout = 0 - # Entretien des batiments pendant 3 mois - if self.nombreBatiments > 0: - cout += (-117 * self.nombreBatiments) * 3 - - # Entretien des champs pendant 3 mois - if self.nombreChamps > 0: - cout += (-90 * self.nombreChamps) * 3 - - self.moneyDefile(cout) +import pygame +import random +from Champs import * +import numpy as np +from Camera import Camera +from Image import * +from Temps import Temps +from Infrastructure import * + +RAYON_MUR_INVISIBLE = 2000 +SAISONS = ["Printemps", "Été", "Automne", "Hiver"] +MOIS = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"] +police = pygame.font.SysFont("roboto", 30) + +#TODO : MAJEUR : continuer le pourcentage des plantes + #1-> Faire une hiérarchie entre les batiments si il ya un puit et un reservoir appliquer le boost du reservoir et non du puit + #2->quand on place un batiment possable sur un champ il affiche le descripteur du champ et pas de l'infrastructure + + +class Game: + imagestaticplantation = pygame.image.load('../assets/Interface/imagePlantation.jpeg') + imagestaticbatiment = pygame.image.load('../assets/Interface/imageBatiment.jpeg') + imagestaticinfor = pygame.image.load('../assets/Interface/imageinfo.jpg') + def __init__ (self): + self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) + self.image = Image(self.screen) + self.screenSize = np.array(self.screen.get_size()) + self.score = 0 + self.money = 40000 + self.displayMoney = 40000 + self.month = 0 + self.nombreBatiments = 0 + self.nombreChamps = 0 + self.champs = [] + self.batiment = [] + + self.temps = Temps() + for i in range(12): + self.champs.append(Buisson(((i%4)*300-550,(i//4)*250-430))) + self.clock = pygame.time.Clock() + self.selectedChamp = None + self.selectedBatiment = None + + self.imageMoney = pygame.transform.scale(self.image.moneyImage, np.array(self.image.moneyImage.get_size())/5) + + self.camera = Camera(np.array(self.screen.get_size())/2) + + self.frame = 0 + self.buyFrame = -1000 + + self.tourSuivantOriginal = self.image.arrowNextImage + self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (100,100)) + self.coordonneeSuite = self.screenSize[0]-self.tourSuivantModif.get_width() - 120, self.screenSize[1] - self.tourSuivantModif.get_height() - 120 + self.suiteRectangle = pygame.rect.Rect(*self.coordonneeSuite, 100, 100) + + self.coordonne_info = pygame.rect.Rect(self.screen.get_width()*0.82,self.screen.get_height()*0.18,self.screen.get_width()*0.19,self.screen.get_height()*0.5) + self.recInformation = pygame.rect.Rect(self.coordonne_info) + self.rectPlantation = pygame.rect.Rect(0,0,self.temps.getImageSaison().get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height()) + self.recBatiment = pygame.rect.Rect(self.temps.getImageSaison().get_width(), self.screen.get_height() - self.temps.getImageSaison().get_height(), self.screen.get_width() * 0.65, self.temps.getImageSaison().get_height()) + + self.rectPlantationimage = pygame.transform.scale(Game.imagestaticplantation,(self.rectPlantation.w,self.rectPlantation.h)) + self.rectBatimentimage = pygame.transform.scale(Game.imagestaticbatiment,(self.recBatiment.w,self.recBatiment.h)) + self.rectinfoimage = pygame.transform.scale(Game.imagestaticinfor,(self.recInformation.w,self.recInformation.h)) + + self.recTourSuivant = pygame.rect.Rect( + self.recBatiment.x + self.recBatiment.w ,self.screen.get_height() - self.temps.getImageSaison().get_height(), + self.screen.get_width() - self.temps.getImageSaison().get_width() - self.recBatiment.w,self.temps.getImageSaison().get_height()) + + #DragAndDrop + self.dragBatiment = None + self.dragPlantation = None + + + + + def gameLoop (self): + while True: + + self.screen.blit(self.image.backgroundImage, (0,0)) + + #CHAMPS------------------ + # Affichage des champs + for champ in self.champs: + champ.draw(self.screen, self.camera) + + for bat in self.batiment: + bat.draw(self.screen, self.camera) + #DEBUT BOUCLE INTERFACE------------------------ + + #Onglet Information + #pygame.draw.rect(self.screen, (0, 127, 0), self.recInformation) + self.screen.blit(Game.imagestaticinfor,(self.coordonne_info.x,self.coordonne_info.y)) + + # Météo + self.screen.blit(self.temps.getImageSaison(), (0, self.screen.get_height() - 300)) + self.screen.blit(self.temps.iconSaison,(10,self.screen.get_height() - self.temps.iconSaison.get_height())) + self.screen.blit(self.temps.tempsaisonImage,(10,self.screen.get_height() - self.temps.iconSaison.get_height() - 50)) + + self.screen.blit(self.temps.nexticonSaison,(self.temps.getImageSaison().get_width() - self.temps.nexticonSaison.get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height() +20)) + self.screen.blit(self.temps.tempsaisonImageDeuxPosiiton,(self.temps.getImageSaison().get_width() - self.temps.nexticonSaison.get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height())) + + + #Onglet plantation + + self.screen.blit(self.rectPlantationimage,(0,0)) + #Onglet tour suivant + pygame.draw.rect(self.screen,(0, 127, 0),(self.recTourSuivant)) + self.screen.blit(self.tourSuivantModif, (self.recTourSuivant.x+ (self.recTourSuivant.w - self.tourSuivantModif.get_width())/2, + self.recTourSuivant.y+ (self.recTourSuivant.h - self.tourSuivantModif.get_height())/2)) + + for i,c in enumerate(typePlantation): + x = self.rectPlantation.x + ( 0 if i%2 else 170) + y = self.rectPlantation.y + (i//2) * self.rectPlantationimage.get_height()/4 + + # Redimensionner l'image + c.iconStatic = transformImage(c.iconStatic, self.rectPlantationimage.get_width()/3.5, self.rectPlantationimage.get_height()/5.5) + + r = pygame.rect.Rect(x,y,c.iconStatic.get_width(),c.iconStatic.get_height()+ 20 ) + self.screen.blit(c.textStatic, (x,y)) + self.screen.blit(c.iconStatic,(x,y+c.textStatic.get_height() )) + if ( (r.collidepoint(pygame.mouse.get_pos()))): + pygame.draw.rect(self.screen,(138, 227, 237), r,1) + self.screen.blit(c.textDescriptionStatic,(self.recInformation.x,self.recInformation.y)) + + + #Onglet batiment + self.screen.blit(self.rectBatimentimage,(self.temps.getImageSaison().get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height())) + for i,c in enumerate(typeBatiment): + x = self.recBatiment.x + i* self.rectBatimentimage.get_width() / 6 + y = self.recBatiment.y + 50 + r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) + self.screen.blit(c.textStatic, (x,y)) + self.screen.blit(c.iconStatic,(x,y + c.textStatic.get_height())) + if ( (r.collidepoint(pygame.mouse.get_pos()))): + pygame.draw.rect(self.screen,(138, 227, 237), r,1) + self.screen.blit(c.textDescriptionStatic,(self.recInformation.x,self.recInformation.y)) + + # FIN BOUCLE INTERFACE ------------------------ + + + isChamp = False + isbatiment = False + + + if self.money < self.displayMoney: + self.displayMoney -= min(444, self.displayMoney - self.money) # Si quelque chose coûte moins que 100, changer par -= min(100, self.displayMoney - self.money) + elif self.money > self.displayMoney: + self.displayMoney+= min(444, self.money - self.displayMoney) # Si quelque chose coûte moins que 100, changer par -= min(100, self.money - self.displayMoney) + + + #self.displayMoney = self.money + + textMoney = police.render(str(self.displayMoney), True, (255,255,255)) + + self.CoRecArgent = pygame.rect.Rect(self.screen.get_width(), 0, 100, 100) + self.recArgent = pygame.draw.rect(self.screen,(255,0,0),(self.CoRecArgent)) + + self.screen.blit(textMoney, (self.screen.get_width() - self.imageMoney.get_width() - textMoney.get_width(),self.imageMoney.get_height()/2)) + self.screen.blit(self.imageMoney, (self.screen.get_width() - self.imageMoney.get_width() , 0)) + + + for event in pygame.event.get(): + if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: + exit() + + #Deplacement de la souris + elif event.type == pygame.MOUSEMOTION: + #drag and drop + interface des batiment et plantation + if event.buttons[2] == 1: #maintenir enfoncé clic droit + self.camera.setPosition(np.array(event.rel)) + + if event.buttons[0] == 1:#maintenir enfoncé clic gauche + if self.dragBatiment == None and self.dragPlantation == None: + for i,c in enumerate(typeBatiment): + x = self.recBatiment.x + i* self.rectBatimentimage.get_width() / 6 + y = self.recBatiment.y + 50 + r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) + if ( (r.collidepoint(event.pos))): + self.dragBatiment = c + if(self.dragBatiment): + self.screen.blit(self.dragBatiment.iconStatic, (event.pos)) + + + if self.dragPlantation == None and self.dragBatiment == None: + + for i,c in enumerate(typePlantation): + + x = self.rectPlantation.x + ( 0 if i%2 else 170) + y = self.rectPlantation.y + (i//2) * self.rectPlantationimage.get_height()/4 + r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) + if ( (r.collidepoint(event.pos))): + self.dragPlantation = c + + if(self.dragPlantation): + self.screen.blit(self.dragPlantation.iconStatic, (event.pos)) + + + else: + if self.dragPlantation: + for champ in self.champs: + if champ.rectScale.collidepoint(event.pos): + if self.dragPlantation == Pesticide: + champ.isInfeste = False + + elif isinstance(champ,TerrainVide): + newChamp = self.dragPlantation(champ.pos) + self.champs.append(newChamp) + newChamp.setInformation("Occupe" ,"Champ occupé") + newChamp.setInformation("Nom", "Champ contient "+ self.dragPlantation.__name__) + newChamp.setInformation("coutEntretien","90€ coût d'entretien mensuel") + + self.champs.remove(champ) + #Perdre l'argent + variable = self.dragPlantation.montantAchat + self.moneyDefile(-variable) + + + + if self.dragBatiment: + for champ in self.champs: + if champ.rectScale.collidepoint(event.pos): + if isinstance(champ,TerrainVide) or type(champ) in typePlantation: + newBat = self.dragBatiment(champ.pos) + self.batiment.append(newBat) + champ.isbat = newBat + + newBat.setInformation("Occupe", "Espace occupé") + newBat.setInformation("Nom","Emplacement pour"+str(self.dragBatiment.NameObjet)) + newBat.setInformation("coutEntretien","117€ d'entretien mensuel ") + champ.showInfo(self.screen,self.recInformation,newBat.descripteurInfrastructure) + + #Perdre l'argent + variable = self.dragBatiment.montantAchat + + self.moneyDefile(-variable) + self.nombreBatiments += 1 + + if self.dragBatiment not in [Torche,Serre,Irrigation,IrrigationGoutte]: + self.champs.remove(champ) + + self.nombreChamps -= 1 + + + self.dragPlantation = None + self.dragBatiment = None + + + + + for champ in self.champs + self.batiment: + if champ.rectScale.contains(event.pos[0],event.pos[1],0,0): + self.selectedChamp = champ + self.selectedBatiment = champ + isChamp = True + isbatiment = True + + + if not isChamp: + self.selectedChamp = None + + if not isbatiment: + self.selectedBatiment = None + + if (*event.pos,0,0) in self.recTourSuivant: + self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (200, 200)) + else: + self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (100, 100)) + + + + elif event.type == pygame.MOUSEWHEEL: + self.camera.zoomInOut(event.y) + + + elif event.type == pygame.MOUSEBUTTONDOWN: + + if event.button == 1: # Click gauche + #Declanchement du tour suivant + if(self.recTourSuivant.collidepoint(event.pos)): + self.coutEntretien() + self.temps.NextTurn() + + + #Code qui implemente la variation du pourcentage des plantes + #Vérification de la construction de batiment d'eau quand il fait chaud avec different cas + #self.ChangePourcentFanne(Serre,["orage"],2) + if (self.temps.currentSeason == "été"): + #self.ChangePourcentFanne(ReservoirEau,["canicule","secheresse"],20,"chaud",10), + for bat in self.batiment: + print("batiment reconnu") + print("len batiment : "+ str(self.batiment)) + if (type(bat) == ReservoirEau): + self.ChangePourcentFanne(ReservoirEau,["canicule","secheresse"],5,"chaud",2) + elif(type(bat) == Puit): + self.ChangePourcentFanne(Puit,["canicule","secheresse"],10,"chaud",5) + elif(type(bat) == Irrigation): + self.ChangePourcentFanne(Irrigation,["canicule","secheresse"],10,"chaud",5) + elif(type(bat) == IrrigationGoutte): + self.ChangePourcentFanne(IrrigationGoutte,["canicule","secheresse"],5,"chaud",2) + if(len(self.batiment) == 0): + print("pas de batiment") + for champ in self.champs: + champ.pourcentagePlanteFane += 20 + champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) + + elif (self.temps.currentSeason == "Automne"): + #self.ChangePourcentFanne(Serre,["neige","froid"],20) + for bat in self.batiment: + if (type(bat) == Serre): + self.ChangePourcentFanne(Serre,["neige","froid"],5) + elif(type(bat) == Puit): + self.ChangePourcentFanne(Torche,["neige","froid"],10) + if(len(self.batiment) == 0): + print("pas de batiment") + for champ in self.champs: + champ.pourcentagePlanteFane += 15 + champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) + + elif (self.temps.currentSeason == "Hiver"): + self.AideEtat() + #self.ChangePourcentFanne(Serre,["neige","froid"],30) + for bat in self.batiment: + if (type(bat) == Serre): + self.ChangePourcentFanne(Serre,["neige","froid"],5) + elif(type(bat) == Puit): + self.ChangePourcentFanne(Torche,["neige","froid"],10) + if(len(self.batiment) == 0): + print("pas de batiment") + for champ in self.champs: + champ.pourcentagePlanteFane += 15 + champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) + + #Ajouter torche est faire une hiérarchie + elif(self.temps.currentSeason == "Printemps"): + #self.ChangePourcentFanne(ReservoirEau,["chaud"],15) + for bat in self.batiment: + if (type(bat) == ReservoirEau): + self.ChangePourcentFanne(ReservoirEau,["chaud"],2) + elif(type(bat) == Puit): + self.ChangePourcentFanne(Puit,["chaud"],5,) + elif(type(bat) == Irrigation): + self.ChangePourcentFanne(Irrigation,["chaud"],5) + elif(type(bat) == IrrigationGoutte): + self.ChangePourcentFanne(IrrigationGoutte,["chaud"],2) + if(len(self.batiment) == 0): + print("pas de batiment") + for champ in self.champs: + champ.pourcentagePlanteFane += 15 + champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) + + + for champ in self.champs: + if type(champ) in typePlantation: + if champ.isInfeste: + champ.indiceImage = 4 + self.VerifPlantFane(champ) + if(random.random()< 0.10): + champ.isInfeste = True + + for bat in self.batiment: + print("passe ici") + print(type(bat)) + if(bat.verifDureeVie()): + print("changer") + self.champs.append(TerrainVide(bat.pos)) + self.batiment.remove(bat) + + # Achat + for champ in self.champs: + + #click sur un champ + if champ.rectScale.collidepoint(event.pos): + #Vente des plantes + if(champ.indiceImage > 3): + self.champs.append(TerrainVide(champ.pos)) + self.champs.remove(champ) + elif(champ.indiceImage == 3): + self.moneyDefile(champ.montantVente) + self.champs.append(TerrainVide(champ.pos)) + self.champs.remove(champ) + + + #Achat d'un terrain vide + if isinstance(champ, Buisson): + #if self.money >= champ.prix: + self.moneyDefile(-champ.prix) + self.champs.append(champ.buyField()) + self.champs.remove(champ) + self.nombreChamps += 1 + + + + if self.frame < self.buyFrame + 20: + self.screen.blit(self.moneyChange, (self.screen.get_width() - self.imageMoney.get_width() - textMoney.get_width(), (self.frame-self.buyFrame)*1.5)) + #self.screen.blit(self.moneyChange, (200, self.screen.get_height()-textMoney.get_height()*4+(self.frame-self.buyFrame)*1.5)) + + if self.selectedChamp and self.selectedBatiment: + self.selectedChamp.showInfo(self.screen,self.recInformation) + self.selectedBatiment.showInfo(self.screen,self.recInformation) + pygame.display.update() + self.clock.tick(50) + self.frame += 1 + + def moneyDefile(self,montant): + self.moneyChange = police.render(str(montant), True, (200,0,0) if montant < 0 else (0,250,0) ) + self.buyFrame = self.frame + self.money+= montant + + def AideEtat(self): + self.moneyDefile(5000) + + def ChangePourcentFanne(self,infra,case1,augmentation1, case2 = "",augmentation2 = 0): + print("fonction rentrer avec : ") + print(case1) + print(case2) + print("compare avec : "+ str(self.temps.currentTempsName) +" et les cas : "+str(case1)) + print("rentre dans le premier if batiment : "+str(not (infra in [type(bat) for bat in self.batiment]))) + print("chaud" in ["chaud","secheresse"]) + print(self.temps.currentTempsName) + if not (infra in [type(bat) for bat in self.batiment]): + print(self.temps.currentTempsName in case1) + if(self.temps.currentTempsName in case1): + for champ in self.champs: + champ.pourcentagePlanteFane += augmentation1 + champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) + elif(self.temps.currentTempsName == case2): + for champ in self.champs: + champ.pourcentagePlanteFane += augmentation2 + champ.setInformation(hash('fane'),champ.pourcentagePlanteFane) + + + def VerifPlantFane(self,champ): + nbrrandom = random.randint(0,100) + if nbrrandom < champ.pourcentagePlanteFane: + champ.indiceImage = 4 + champ.plantationGrandit() + + def coutEntretien(self): + cout = 0 + # Entretien des batiments pendant 3 mois + if self.nombreBatiments > 0: + cout += (-117 * self.nombreBatiments) * 3 + + # Entretien des champs pendant 3 mois + if self.nombreChamps > 0: + cout += (-90 * self.nombreChamps) * 3 + + self.moneyDefile(cout)