Skip to content
Snippets Groups Projects
Commit be1a6d6d authored by KALCK DAMIEN's avatar KALCK DAMIEN
Browse files

Merge branch 'main' into 'Damien'

Merde request

See merge request l.duchmann/climate-simulator-global-organization!11
parents cee6ee38 65792b20
Branches
No related merge requests found
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
assets/Temps/nice_weather.png

3.63 KiB

src/Champs.py 100755 → 100644
This diff is collapsed.
src/Game.py 100755 → 100644
This diff is collapsed.
src/T3.py 100755 → 100644
import pygame import pygame
pygame.init() pygame.init()
from datetime import date from datetime import date
import Game import Game
pygame.display.set_caption("Climate Simulator : Global Organization") pygame.display.set_caption("Climate Simulator : Global Organization")
screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN)
#on récupère le mois actuelle pour le faire commencer à ce moment #on récupère le mois actuelle pour le faire commencer à ce moment
class month: class month:
def __init__ (self, str): def __init__ (self, str):
self.month = str self.month = str
current_month = month(date.today().strftime("%b")) current_month = month(date.today().strftime("%b"))
#background (2è scène) #background (2è scène)
background = pygame.image.load('../assets/Interface/intro.webp') background = pygame.image.load('../assets/Interface/intro.webp')
background = pygame.transform.scale(background, (screen.get_width(), screen.get_height())) background = pygame.transform.scale(background, (screen.get_width(), screen.get_height()))
#bouton #bouton
play_button = pygame.image.load('../assets/Interface/button.png') play_button = pygame.image.load('../assets/Interface/button.png')
play_button = pygame.transform.scale(play_button,(400,150)) play_button = pygame.transform.scale(play_button,(400,150))
play_button_rect = play_button.get_rect() play_button_rect = play_button.get_rect()
play_button_rect.x = screen.get_width() / 2 - play_button.get_width()/2 play_button_rect.x = screen.get_width() / 2 - play_button.get_width()/2
play_button_rect.y = screen.get_height() / 2 - play_button.get_height()/2 play_button_rect.y = screen.get_height() / 2 - play_button.get_height()/2
#buisson #buisson
#bush = pygame.image.load('../assets/buisson.png') #bush = pygame.image.load('../assets/buisson.png')
#cadenas #cadenas
#lock = pygame.image.load('../assets/cadenas.png') #lock = pygame.image.load('../assets/cadenas.png')
screen.blit(background, (0,0)) screen.blit(background, (0,0))
screen.blit(play_button, play_button_rect) screen.blit(play_button, play_button_rect)
#screen.blit(bush, (100,100)) #screen.blit(bush, (100,100))
#screen.blit(lock, (bush.get_width()/2,bush.get_height()/2+40)) #screen.blit(lock, (bush.get_width()/2,bush.get_height()/2+40))
pygame.display.update() pygame.display.update()
inMenu = True inMenu = True
while inMenu: while inMenu:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN and play_button_rect.contains(*event.pos,0,0): if event.type == pygame.MOUSEBUTTONDOWN and play_button_rect.contains(*event.pos,0,0):
inMenu = False inMenu = False
elif event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: elif event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
exit(0) exit(0)
# à l'appui du bouton start # à l'appui du bouton start
Game.Game().gameLoop() Game.Game().gameLoop()
\ No newline at end of file
src/Temps.py 100755 → 100644
import random import random
import pygame import pygame
from Image import transformImage from Image import transformImage
from random import triangular from random import triangular
police = pygame.font.SysFont("Alef", 30) police = pygame.font.SysFont("Alef", 30)
police2 = pygame.font.SysFont("Alef", 20) police2 = pygame.font.SysFont("Alef", 20)
class Temps: class Temps:
""" """
climats = { climats = {
"janvier" : { "janvier" : {
"temp" : [2,7.8], "temp" : [2,7.8],
"humidité" : [78,90] "humidité" : [78,90]
}, },
"février" : { "février" : {
"temp" : [4.5,11.8], "temp" : [4.5,11.8],
"humidité" : [60,85] "humidité" : [60,85]
}, },
"mars" : { "mars" : {
"temp" : [3.7,13.7], "temp" : [3.7,13.7],
"humidité" : [45,90] "humidité" : [45,90]
}, },
"avril" : { "avril" : {
"temp" : [15.4,4.7], "temp" : [15.4,4.7],
"humidité" : [42,76] "humidité" : [42,76]
}, },
"mai" : { "mai" : {
"temp" : [18.1,8.7], "temp" : [18.1,8.7],
"humidité" : [43,80] "humidité" : [43,80]
}, },
"juin" : { "juin" : {
"temp" : [24.5,14.6], "temp" : [24.5,14.6],
"humidité" : [60,84] "humidité" : [60,84]
}, },
"juillet" : { "juillet" : {
"temp" : [24.9,15.5], "temp" : [24.9,15.5],
"humidité" : [45,84] "humidité" : [45,84]
}, },
"août" : { "août" : {
"temp" : [24.6,14.8], "temp" : [24.6,14.8],
"humidité" : [64,81] "humidité" : [64,81]
}, },
"septembre" : { "septembre" : {
"temp" : [24,14], "temp" : [24,14],
"humidité" : [58,90] "humidité" : [58,90]
}, },
"octobre" : { "octobre" : {
"temp" : [18.3,8.6], "temp" : [18.3,8.6],
"humidité" : [70, 89] "humidité" : [70, 89]
}, },
"novembre" : { "novembre" : {
"temp" : [11.3,4.9], "temp" : [11.3,4.9],
"humidité" : [75,99] "humidité" : [75,99]
}, },
"décembre" : { "décembre" : {
"temp" : [10.3,3.8], "temp" : [10.3,3.8],
"humidité" : [77,99] "humidité" : [77,99]
} }
} }
""" """
climats = { climats = {
"Automne" : { "Automne" : {
"temp" : [4.8,13.3], "temp" : [4.8,13.3],
"humidité" : [70,95] "humidité" : [70,95]
}, },
"Hiver" : { "Hiver" : {
"temp" : [-5,10.3], "temp" : [-5,10.3],
"humidité" : [50,90] "humidité" : [50,90]
}, },
"Printemps" : { "Printemps" : {
"temp" : [13,27], "temp" : [13,27],
"humidité" : [40,90] "humidité" : [40,90]
}, },
"été" : { "été" : {
"temp" : [25,40], "temp" : [25,40],
"humidité" : [40,96] "humidité" : [40,96]
} }
} }
def __init__(self): def __init__(self):
self.indice = 2 self.indice = 2
self.currentSeason = self.getSaisonName(self.indice) self.currentSeason = self.getSaisonName(self.indice)
self.globaltemp = self.tirageAuSortChiffreIntervalleTemp(self.currentSeason) self.globaltemp = self.tirageAuSortChiffreIntervalleTemp(self.currentSeason)
self.humidite = self.tirageAuSortChiffreIntervallehumidite(self.currentSeason) self.humidite = self.tirageAuSortChiffreIntervallehumidite(self.currentSeason)
self.temps = pygame.image.load(self.tempAAfficher(self.globaltemp,self.humidite)) self.temps = pygame.image.load(self.tempAAfficher(self.globaltemp,self.humidite))
self.iconSaison = transformImage(self.temps,200,200) self.iconSaison = transformImage(self.temps,200,200)
self.nextSaison = self.getSaisonName(self.indice+1) self.nextSaison = self.getSaisonName(self.indice+1)
self.nextglobalTemps = self.tirageAuSortChiffreIntervalleTemp(self.nextSaison) self.nextglobalTemps = self.tirageAuSortChiffreIntervalleTemp(self.nextSaison)
self.nexthumidite = self.tirageAuSortChiffreIntervallehumidite(self.nextSaison) self.nexthumidite = self.tirageAuSortChiffreIntervallehumidite(self.nextSaison)
self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps,self.nexthumidite)) self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps,self.nexthumidite))
self.nexticonSaison = transformImage(self.nextTemps,100,100) self.nexticonSaison = transformImage(self.nextTemps,100,100)
self.tempsaisonImage = police.render(self.currentSeason +" : "+ str(round(self.globaltemp,1))+" °C",True,(0,0,0)) self.tempsaisonImage = police.render(self.currentSeason +" : "+ str(round(self.globaltemp,1))+" °C",True,(0,0,0))
self.tempsaisonImageDeuxPosiiton = police2.render(self.nextSaison +" : "+ str(round(self.nextglobalTemps,1))+" °C",True,(0,0,0)) self.tempsaisonImageDeuxPosiiton = police2.render(self.nextSaison +" : "+ str(round(self.nextglobalTemps,1))+" °C",True,(0,0,0))
for key,value in self.climats.items(): for key,value in self.climats.items():
self.climats.get(key)['image'] = transformImage(pygame.image.load("../assets/Saison/"+key+".png"),400,300) self.climats.get(key)['image'] = transformImage(pygame.image.load("../assets/Saison/"+key+".png"),400,300)
self.ListTemps = [] self.ListTemps = []
def NextTurn(self): def NextTurn(self):
#Le next qui devien current #Le next qui devien current
self.indice += 1 self.indice += 1
self.currentSeason = self.nextSaison self.currentSeason = self.nextSaison
self.globaltemp = self.nextglobalTemps self.globaltemp = self.nextglobalTemps
self.humidite = self.nexthumidite self.humidite = self.nexthumidite
self.temps = self.nextTemps self.temps = self.nextTemps
self.iconSaison = self.nexticonSaison self.iconSaison = self.nexticonSaison
self.tempsaisonImage = police.render(self.currentSeason +" : "+ str(round(self.globaltemp,1))+" °C",True,(0,0,0)) self.tempsaisonImage = police.render(self.currentSeason +" : "+ str(round(self.globaltemp,1))+" °C",True,(0,0,0))
#Nouveau turn #Nouveau turn
self.nextSaison = self.getSaisonName(self.indice+1) self.nextSaison = self.getSaisonName(self.indice+1)
self.nextglobalTemps = self.tirageAuSortChiffreIntervalleTemp(self.nextSaison) self.nextglobalTemps = self.tirageAuSortChiffreIntervalleTemp(self.nextSaison)
self.nexthumidite = self.tirageAuSortChiffreIntervallehumidite(self.nextSaison) self.nexthumidite = self.tirageAuSortChiffreIntervallehumidite(self.nextSaison)
self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps,self.nexthumidite)) self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps,self.nexthumidite))
self.nexticonSaison = transformImage(self.nextTemps,100,100) self.nexticonSaison = transformImage(self.nextTemps,100,100)
self.tempsaisonImageDeuxPosiiton = police2.render(self.nextSaison +" : "+ str(round(self.nextglobalTemps,1))+" °C",True,(0,0,0)) self.tempsaisonImageDeuxPosiiton = police2.render(self.nextSaison +" : "+ str(round(self.nextglobalTemps,1))+" °C",True,(0,0,0))
def getSaisonName(self,indice:int)->str: def getSaisonName(self,indice:int)->str:
return list(self.climats.keys())[indice%4] return list(self.climats.keys())[indice%4]
def tirageAuSortChiffreIntervalleTemp(self,clef): def tirageAuSortChiffreIntervalleTemp(self,clef):
#tirage au sort pour avoir un nombre representatif dans son domaine; par exemple [0,10], la temp sera de 5 #tirage au sort pour avoir un nombre representatif dans son domaine; par exemple [0,10], la temp sera de 5
intervalle = self.getClimatTemp(clef) intervalle = self.getClimatTemp(clef)
""" """
randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0] randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0]
return randomNombre return randomNombre
""" """
return random.triangular(low = intervalle[0],high = intervalle[1]) return random.triangular(low = intervalle[0],high = intervalle[1])
def tirageAuSortChiffreIntervallehumidite(self,clef): def tirageAuSortChiffreIntervallehumidite(self,clef):
#tirage au sort pour avoir un nombre representatif dans son domaine; par exemple [0,10], la temp sera de 5 #tirage au sort pour avoir un nombre representatif dans son domaine; par exemple [0,10], la temp sera de 5
intervalle = self.getClimatHumidite(clef) intervalle = self.getClimatHumidite(clef)
#randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0] #randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0]
return random.triangular(low = intervalle[0],high = intervalle[1]) return random.triangular(low = intervalle[0],high = intervalle[1])
def tempAAfficher(self,temperature:float,humidite)-> str: def tempAAfficher(self,temperature:float,humidite)-> str:
#Determination du temps a afficher #Determination du temps a afficher
if( temperature < 0 and humidite >80): if( temperature < 0 and humidite >80):
return "../assets/Temps/neige.png" return "../assets/Temps/neige.png"
elif (temperature < 10): elif (temperature < 10):
return "../assets/Temps/froid.png" return "../assets/Temps/froid.png"
elif (temperature < 35): elif (temperature < 30):
return "../assets/Temps/chaud.png" if(humidite > 80):
elif (temperature > 34): return "../assets/Temps/pluie.png"
if(humidite > 85): else:
return "../assets/Temps/orage.png" return "../assets/Temps/nice_weather.png"
elif (temperature < 35):
if(humidite < 65): return "../assets/Temps/chaud.png"
return "../assets/Temps/secheresse.png" elif (temperature > 34):
else:
return "../assets/Temps/canicule.png" if(humidite > 85):
else: return "../assets/Temps/orage.png"
pass
if(humidite < 40):
def getClimatTemp(self,clef): return "../assets/Temps/secheresse.png"
return self.climats[clef]["temp"] else:
return "../assets/Temps/canicule.png"
def getClimatHumidite(self,clef): else:
return self.climats[clef]["humidité"] pass
def getcurrentSeason(self): def getClimatTemp(self,clef):
return self.currentSeason return self.climats[clef]["temp"]
def getImageSaison(self): def getClimatHumidite(self,clef):
return self.climats.get(self.currentSeason).get('image') return self.climats[clef]["humidité"]
def getcurrentSeason(self):
return self.currentSeason
\ No newline at end of file
def getImageSaison(self):
return self.climats.get(self.currentSeason).get('image')
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment