diff --git a/src/Camera.py b/src/Camera.py index e2871627c242c3c66bf187358621c711615c1304..1d41e133279e65c6e06fa232157cf9f951436fad 100644 --- a/src/Camera.py +++ b/src/Camera.py @@ -40,4 +40,3 @@ class Camera: return pygame.transform.scale(img, np.array(img.get_size())*self.zoom) return None - diff --git a/src/Champs.py b/src/Champs.py index 5cc2832696c9d24aaf4b81da5b984ae4f471d6ed..826baeae897b1adae316d766dc09ed0b8ca0960b 100755 --- a/src/Champs.py +++ b/src/Champs.py @@ -1,10 +1,14 @@ import pygame import numpy as np from Temps import * +from Image import transformImage + +listeImage = [pygame.transform.scale(pygame.image.load('../assets/crop'+str(i)+'phase.png'),(120,120)) for i in range(1,5)] class Champs: + def __init__ (self, temperature, humidite, tempsAvantMaturation, pos, image): self.temperature = temperature self.humidite = humidite @@ -16,7 +20,7 @@ class Champs: self.rectScale = self.rect self.police = pygame.font.SysFont("Alef", 22) #pygame.font.get_fonts() -> liste des fonts self.imgZoom = pygame.transform.scale(self.image, self.imageSize) - + self.indiceImage = 0 self.descripteurChamps = { "Temperature" : None, @@ -36,20 +40,55 @@ class Champs: self.setInformation("Occupe", False) + + + def plantationGrandit(self): + self.indiceImage +=1 + if self.indiceImage <4: + self.imageChamp = listeImage[self.indiceImage] + else: + self.imageChamp =pygame.transform.scale(pygame.image.load('../assets/damage.png'),(120,120)) + + + + def draw (self, screen, camera): scaleImage = camera.scaleImage(self.image) if scaleImage: # != None self.imgZoom = scaleImage self.rectScale = pygame.rect.Rect(camera.convertLocation(self.pos), self.imgZoom.get_size()) + + screen.blit(self.imgZoom, camera.convertLocation(self.pos)) + if hasattr(self,'imageChamp'): + scaleChamp = camera.scaleImage(self.imageChamp) + if scaleChamp: + self.champZoom = scaleChamp + varlongueur = camera.convertLocation(self.pos) + self.rectChampScal = pygame.rect.Rect(camera.convertLocation(self.pos), self.champZoom.get_size()) + screen.blit( + self.champZoom, + ( + varlongueur[0] + + (self.rectScale.w-self.rectChampScal.w) + /2, + varlongueur[1] + + (self.rectScale.h-self.rectChampScal.h) + /2) + ) + self.setInformation("Occupe", True) + def changeText (self, camera): scaleText = camera.scaleImage(self.text) if scaleText: self.zoomText = scaleText + def setInformation(self,clef,valeur): + self.descr + def setInformation(self,clef,valeur): self.descripteurChamps[clef] = valeur self.imageSurfaceinfo[clef] = police.render(clef+ " : "+ str(valeur),False,(0,0,0)) @@ -72,57 +111,99 @@ class Buisson (Champs): screen.blit(self.text,(rectangle.x,rectangle.y)) def buyField (self): - return Houblon(self.pos) + return TerrainVide(self.pos) + + +class TerrainVide(Champs): + def __init__ (self, pos): + super().__init__(0, 0, 0, pos,'../assets/champ.png') + self.text = self.police.render("Température : " + str(self.temperature), False, (0,0,0)) + self.zoomText = self.text + class Houblon (Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/neige.png'),(150,150)) + iconStatic = pygame.transform.scale(pygame.image.load('../assets/houblon.png'),(150,150)) textStatic = police.render('Houblon',False, (0,0,0)) textDescriptionStatic = police.render("Houblon sa marche bien",False,(0,0,0)) + montantAchat = 250 + montantVente = 600 def __init__ (self, pos): super().__init__(0, 0, 0, pos,'../assets/champ.png') self.text = self.police.render("Température : " + str(self.temperature), False, (0,0,0)) self.zoomText = self.text + + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/crop1phase.png'),(120,120)) class Ble (Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Automne.png'),(150,150)) + iconStatic = pygame.transform.scale(pygame.image.load('../assets/wheat.png'),(150,150)) textStatic = police.render('Ble',False, (0,0,0)) textDescriptionStatic = police.render("Ble sa marche bien",False,(0,0,0)) - def __init__ (self,pos,icon): + montantAchat = 250 + montantVente = 800 + def __init__ (self,pos): super().__init__(0,0,0,pos,'../assets/champ.png') + + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/crop1phase.png'),(120,120)) class Malt (Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Hiver.png'),(150,150)) + iconStatic = pygame.transform.scale(pygame.image.load('../assets/malt.png'),(150,150)) textStatic = police.render('Malt',False, (0,0,0)) textDescriptionStatic = police.render("Malt sa marche bien",False,(0,0,0)) - def __init__ (self,pos,icon): + montantAchat = 300 + montantVente = 800 + def __init__ (self,pos): super().__init__(0,0,0,pos,'../assets/champ.png') + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/crop1phase.png'),(120,120)) + + +class Chanvre(Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/weed.png'),(150,150)) + textStatic = police.render("Chanvre",False, (0,0,0)) + textDescriptionStatic = police.render("Pour des spaces bières",False,(0,0,0)) + montantAchat = 1000 + montantVente = 5000 + def __init__ (self,pos): + super().__init__(0,0,0,pos,'../assets/champ.png') + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/crop1phase.png'),(120,120)) class OrgeHiver(Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/canicule.png'),(150,150)) - textStatic = police.render("Orge d'hiver",False, (0,0,0)) - textDescriptionStatic = police.render("Orge Hiver sa marche bien",False,(0,0,0)) - def __init__ (self,pos,icon): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/orge.png'),(150,150)) + textStatic = police.render("Orge hiver",False, (0,0,0)) + textDescriptionStatic = police.render("Orge hiver sa marche bien",False,(0,0,0)) + montantAchat = 300 + montantVente = 800 + def __init__ (self,pos): super().__init__(0,0,0,pos,'../assets/champ.png') + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/crop1phase.png'),(120,120)) + class OrgePrintemps(Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/canicule.png'),(150,150)) + iconStatic = pygame.transform.scale(pygame.image.load('../assets/barleySpring.png'),(150,150)) textStatic = police.render("Orge printemps",False, (0,0,0)) textDescriptionStatic = police.render("Orge printemps sa marche bien",False,(0,0,0)) - def __init__ (self,pos,icon): + montantAchat = 500 + montantVente = 1000 + def __init__ (self,pos): super().__init__(0,0,0,pos,'../assets/champ.png') + + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/crop1phase.png'),(120,120)) + class Seigle(Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/orage.png'),(150,150)) + iconStatic = pygame.transform.scale(pygame.image.load('../assets/seigle.png'),(150,150)) textStatic = police.render("Seigle",False, (0,0,0)) textDescriptionStatic = police.render("Seigle sa marche bien",False,(0,0,0)) - def __init__ (self,pos,icon): + montantAchat = 200 + montantVente = 600 + def __init__ (self,pos): super().__init__(0,0,0,pos,'../assets/champ.png') + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/crop1phase.png'),(120,120)) -typePlantation = [Houblon,Ble,Malt,OrgeHiver,OrgePrintemps,Seigle] +typePlantation = [Houblon,Ble,Malt,Chanvre,OrgeHiver,OrgePrintemps,Seigle] \ No newline at end of file diff --git a/src/Game.py b/src/Game.py index 14151fd80dc4cf7aae179e39bcfd520b76f37d80..f733dfab655aa514cb47512e7f0cbd716b4de658 100755 --- a/src/Game.py +++ b/src/Game.py @@ -1,5 +1,5 @@ import pygame -from Champs import Champs,Houblon,Buisson,typePlantation +from Champs import Champs,Houblon,Buisson,TerrainVide,typePlantation import numpy as np from Camera import Camera from Image import transformImage,Image @@ -9,7 +9,7 @@ from Infrastructure import Infrastructure,typeBatiment 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("calibri", 30) +police = pygame.font.SysFont("roboto", 30) class Game: def __init__ (self): @@ -17,17 +17,20 @@ class Game: self.image = Image(self.screen) self.screenSize = np.array(self.screen.get_size()) self.score = 0 - self.money = 20000 - self.displayMoney = 20000 + self.money = 40000 + self.displayMoney = 40000 self.month = 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.imageMoney = pygame.transform.scale(self.image.moneyImage, np.array(self.image.moneyImage.get_size())/3) + self.imageMoney = pygame.transform.scale(self.image.moneyImage, np.array(self.image.moneyImage.get_size())/2) self.camera = Camera(np.array(self.screen.get_size())/2) @@ -45,8 +48,12 @@ class Game: 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.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() - ) + self.screen.get_width() - self.temps.getImageSaison().get_width() - self.recBatiment.w,self.temps.getImageSaison().get_height()) + + #DragAndDrop + self.dragBatiment = None + self.dragPlantation = None + @@ -60,7 +67,8 @@ class Game: 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 @@ -115,27 +123,86 @@ class Game: isChamp = False + # + if self.money < self.displayMoney: - self.displayMoney -= 500 # Si quelque chose coûte moins que 100, changer par -= min(100, self.displayMoney - self.money) + 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 += 500 # Si quelque chose coûte moins que 100, changer par -= min(100, 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) + - textMoney = police.render(str(self.displayMoney), True, (255,255,255)) - pygame.draw.rect(self.screen, (0,0,0), (200, self.screen.get_height() - 50, 100, 50)) - self.screen.blit(textMoney, (200, self.screen.get_height()-30)) - self.screen.blit(self.imageMoney, (300, self.screen.get_height()-self.imageMoney.get_height())) + #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() + elif event.type == pygame.MOUSEMOTION: + 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* (c.iconStatic.get_width() + 30) +50 + 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) * 200 + 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)) - for champ in self.champs: + + else: + if self.dragPlantation: + for champ in self.champs: + if champ.rectScale.collidepoint(event.pos): + if isinstance(champ,TerrainVide): + self.champs.append(self.dragPlantation(champ.pos)) + 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): + self.batiment.append(self.dragBatiment(champ.pos)) + self.champs.remove(champ) + #Perdre l'argent + variable = self.dragBatiment.montantAchat + self.moneyDefile(-variable) + + 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 isChamp = True @@ -155,24 +222,43 @@ class Game: # Achat d'un champ elif event.type == pygame.MOUSEBUTTONDOWN: - + if event.button == 1: if(self.recTourSuivant.collidepoint(event.pos)): self.temps.NextTurn() - for champ in self.champs: - if isinstance(champ, Buisson): - if champ.rectScale.contains(event.pos[0],event.pos[1],0,0): - if self.money >= champ.prix: - self.moneyChange = police.render(str(-champ.prix), True, (255,0,0)) - self.buyFrame = self.frame - self.champs.append(champ.buyField()) - self.champs.remove(champ) - self.money -= champ.prix - + """ + if(self.temps.currentSeason == "Hiver"): + self.AideEtat() + """ + + for champ in self.champs: + if type(champ) in typePlantation: + champ.plantationGrandit() + + for champ in self.champs: + if champ.rectScale.collidepoint(event.pos): + + 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) + + + if isinstance(champ, Buisson): + #if self.money >= champ.prix: + self.moneyDefile(-champ.prix) + self.champs.append(champ.buyField()) + self.champs.remove(champ) + + if self.frame < self.buyFrame + 20: - self.screen.blit(self.moneyChange, (200, self.screen.get_height()-textMoney.get_height()*4-(self.frame-self.buyFrame)*1.5)) + self.screen.blit(self.moneyChange, (self.screen.get_width() -200, (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: self.selectedChamp.showInfo(self.screen,self.recInformation) @@ -180,4 +266,13 @@ class Game: pygame.display.update() self.clock.tick(50) - self.frame += 1 \ No newline at end of file + 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) + diff --git a/src/Infrastructure.py b/src/Infrastructure.py index 6431cf9edee287b6a813da39ba59d34adb62e283..ff432c4fdef315f1283f02d40b69e72b06c0d495 100644 --- a/src/Infrastructure.py +++ b/src/Infrastructure.py @@ -13,13 +13,13 @@ class Infrastructure: self.rectScale = self.rect self.descripteurInfrastructure = { - "CoutProd" : None, - + "temperature" : None, } self.imageSurfaceinfo = { - "CoutProd" : None, + } - self.setInformation("CoutProd",2000) + self.setInformation("temperature",2000) + #self.setInformation("Occupe", True) @@ -30,7 +30,26 @@ class Infrastructure: self.imgZoom = scaleImage self.rectScale = pygame.rect.Rect(camera.convertLocation(self.pos), self.imgZoom.get_size()) - screen.blit(self.imgZoom, camera.convertLocation(self.pos)) + + if hasattr(self,'imagebat'): + scaleBat = camera.scaleImage(self.imagebat) + if scaleBat: + self.BatZoom = scaleBat + varlongueur = camera.convertLocation(self.pos) + self.rectbatScal = pygame.rect.Rect(camera.convertLocation(self.pos), self.BatZoom.get_size()) + screen.blit( + self.BatZoom, + ( + varlongueur[0] + + (self.rectScale.w-self.rectbatScal.w) + /2, + varlongueur[1] + + (self.rectScale.h-self.rectbatScal.h) + /2) + ) + + + def changeText (self, camera): scaleText = camera.scaleImage(self.text) @@ -38,35 +57,68 @@ class Infrastructure: self.zoomText = scaleText def setInformation(self,clef,valeur): - self.descripteurChamps[clef] = valeur + self.descripteurInfrastructure[clef] = valeur self.imageSurfaceinfo[clef] = police.render(clef+ " : "+ str(valeur),False,(0,0,0)) def showInfo(self,screen,rectangle): i = 0 - for k,v in self.descripteurChamps.items(): + for k,v in self.descripteurInfrastructure.items(): screen.blit(self.imageSurfaceinfo[k],(rectangle.x,rectangle.y + i)) i += 30 class Puit (Infrastructure): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/money.png'),(150,150)) + iconStatic = pygame.transform.scale(pygame.image.load('../assets/puit.png'),(150,150)) textStatic = police.render('Puits',False, (0,0,0)) textDescriptionStatic = police.render("C'est un puit",False,(0,0,0)) - def __init__ (self,pos,icon): - super().__init__(0,0,0,pos,'../assets/champ.png') + montantAchat = 2000 + def __init__ (self,pos): + super().__init__(pos,'../assets/champ.png') + self.imagebat = pygame.transform.scale(pygame.image.load('../assets/puit.png'),(120,120)) -class Capteur (Infrastructure): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Hiver.png'),(150,150)) +class ReservoirEau (Infrastructure): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/storagetank.png'),(150,150)) textStatic = police.render('Capteur eau de pluie',False, (0,0,0)) textDescriptionStatic = police.render("Permet de capturer l'eau de pluit",False,(0,0,0)) - def __init__ (self,pos,icon): - super().__init__(0,0,0,pos,'../assets/champ.png') + montantAchat = 3000 + def __init__ (self,pos): + super().__init__(pos,'../assets/champ.png') + self.imagebat = pygame.transform.scale(pygame.image.load('../assets/storagetank.png'),(120,120)) class Irrigation (Infrastructure): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Printemps.png'),(150,150)) - textStatic = police.render('Irrigation goute à goute',False, (0,0,0)) + iconStatic = pygame.transform.scale(pygame.image.load('../assets/irrigation.png'),(150,150)) + textStatic = police.render('Arrosoir automatique longue portée',False, (0,0,0)) + textDescriptionStatic = police.render("Permet d'arroser les plantes",False,(0,0,0)) + montantAchat = 5000 + def __init__ (self,pos): + super().__init__(pos,'../assets/champ.png') + self.imagebat = pygame.transform.scale(pygame.image.load('../assets/irrigation.png'),(120,120)) + +class IrrigationGoutte (Infrastructure): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/irrigationGoutte.png'),(150,150)) + textStatic = police.render('Irrigation goutte à goutte',False, (0,0,0)) textDescriptionStatic = police.render("Permet d'arroser les plantes en économisant l'eau",False,(0,0,0)) - def __init__ (self,pos,icon): - super().__init__(0,0,0,pos,'../assets/champ.png') - -typeBatiment = [Puit,Capteur,Irrigation] \ No newline at end of file + montantAchat = 10000 + def __init__ (self,pos): + super().__init__(pos,'../assets/champ.png') + self.imagebat = pygame.transform.scale(pygame.image.load('../assets/irrigationGoutte.png'),(120,120)) + +class Serre (Infrastructure): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/serre.png'),(150,150)) + textStatic = police.render('Serre',False, (0,0,0)) + textDescriptionStatic = police.render("Permet de proteger les cultures du froid et de la chaleur",False,(0,0,0)) + montantAchat = 1500 + def __init__ (self,pos): + super().__init__(pos,'../assets/champ.png') + #self.imagebat = pygame.transform.scale(pygame.image.load('../assets/serre.png'),(120,120)) + +class Torche (Infrastructure): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/torche.png'),(150,150)) + textStatic = police.render('Torche',False, (0,0,0)) + textDescriptionStatic = police.render("Permet de proteger les cultures du froid ",False,(0,0,0)) + montantAchat = 1000 + def __init__ (self,pos): + super().__init__(pos,'../assets/champ.png') + #self.imagebat = pygame.transform.scale(pygame.image.load('../assets/torche.png'),(120,120)) + +typeBatiment = [Puit,ReservoirEau,Irrigation,IrrigationGoutte,Serre,Torche] \ No newline at end of file diff --git a/src/Temps.py b/src/Temps.py index 08647cb77328d8d80d4c759ce73e5a0140e900b3..323544d99bc916372078762ae4b76eda3557bc55 100755 --- a/src/Temps.py +++ b/src/Temps.py @@ -63,21 +63,21 @@ class Temps: climats = { "Automne" : { - "temp" : [5.8,13.3], - "humidité" : [72,94] + "temp" : [4.8,13.3], + "humidité" : [70,95] }, "Hiver" : { - "temp" : [-2.3,12.3], - "humidité" : [51,88] + "temp" : [-5,10.3], + "humidité" : [50,90] }, "Printemps" : { - "temp" : [8,35], - "humidité" : [44,80] + "temp" : [13,27], + "humidité" : [40,90] }, "été" : { - "temp" : [15,27], - "humidité" : [56,85] + "temp" : [25,40], + "humidité" : [40,96] } } @@ -86,13 +86,13 @@ class Temps: self.currentSeason = self.getSaisonName(self.indice) self.globaltemp = self.tirageAuSortChiffreIntervalleTemp(self.currentSeason) self.humidite = self.tirageAuSortChiffreIntervallehumidite(self.currentSeason) - self.temps = pygame.image.load(self.tempAAfficher(self.globaltemp)) + self.temps = pygame.image.load(self.tempAAfficher(self.globaltemp,self.humidite)) self.iconSaison = transformImage(self.temps,200,200) self.nextSaison = self.getSaisonName(self.indice+1) self.nextglobalTemps = self.tirageAuSortChiffreIntervalleTemp(self.nextSaison) self.nexthumidite = self.tirageAuSortChiffreIntervallehumidite(self.nextSaison) - self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps)) + self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps,self.nexthumidite)) self.nexticonSaison = transformImage(self.nextTemps,100,100) self.tempsaisonImage = police.render(self.currentSeason +" : "+ str(round(self.globaltemp,1))+" °C",True,(0,0,0)) @@ -116,7 +116,7 @@ class Temps: self.nextSaison = self.getSaisonName(self.indice+1) self.nextglobalTemps = self.tirageAuSortChiffreIntervalleTemp(self.nextSaison) self.nexthumidite = self.tirageAuSortChiffreIntervallehumidite(self.nextSaison) - self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps)) + self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps,self.nexthumidite)) self.nexticonSaison = transformImage(self.nextTemps,100,100) @@ -128,27 +128,39 @@ class Temps: def tirageAuSortChiffreIntervalleTemp(self,clef): #tirage au sort pour avoir un nombre representatif dans son domaine; par exemple [0,10], la temp sera de 5 + intervalle = self.getClimatTemp(clef) + """ randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0] return randomNombre + """ + return random.triangular(low = intervalle[0],high = intervalle[1]) def tirageAuSortChiffreIntervallehumidite(self,clef): #tirage au sort pour avoir un nombre representatif dans son domaine; par exemple [0,10], la temp sera de 5 intervalle = self.getClimatHumidite(clef) - randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0] - return randomNombre - def tempAAfficher(self,temperature:float)-> str: + #randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0] + return random.triangular(low = intervalle[0],high = intervalle[1]) + + def tempAAfficher(self,temperature:float,humidite)-> str: #Determination du temps a afficher - if( temperature < 0): + if( temperature < 0 and humidite >80): return "../assets/neige.png" elif (temperature < 10): return "../assets/froid.png" elif (temperature < 35): return "../assets/chaud.png" - elif (temperature > 35): - return "../assets/canicule.png" - + elif (temperature > 34): + if(humidite > 85): + return "../assets/orage.png" + + if(humidite < 65): + return "../assets/secheresse.png" + else: + return "../assets/canicule.png" + else: + pass def getClimatTemp(self,clef): return self.climats[clef]["temp"]