This: -added weather cycle

This commit is contained in:
jakzar 2024-05-10 18:33:38 +02:00
parent 2b3170d10c
commit feeca26892
3 changed files with 82 additions and 1 deletions

5
App.py
View File

@ -10,7 +10,7 @@ import Ui
import BFS
import AStar
import random
import Condition
bfs1_flag=False
bfs2_flag=False #Change this lines to show different bfs implementation
@ -35,6 +35,7 @@ ui=Ui.Ui(screen)
#Tractor creation
traktor_slot = pole.get_slot_from_cord((0, 0))
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.opryskiwacz,clock,bfs2_flag)
condition=Condition.Condition()
def init_demo(): #Demo purpose
@ -117,6 +118,8 @@ def init_demo(): #Demo purpose
start_flag=False
# demo_move()
condition.cycle()
condition.getCondition()
old_info=get_info(old_info)
for event in pygame.event.get():
if event.type == pygame.QUIT:

40
Climate.py Normal file
View File

@ -0,0 +1,40 @@
seasons={
0:"winter",
1:"spring",
2:"summer",
3:"fall"}
time={
0:"morning",
1:"noon",
2:"afternoon",
3:"night"}
weather={
0:"perfect",
1:"hot",
2:"cold",
3:"freezing",
4:"rainy",
5:"snowy",
6:"storm"}
def getNextSeason(season):
if(season=="winter"):
return seasons[1]
if(season=="spring"):
return seasons[2]
if(season=="summer"):
return seasons[3]
if(season=="fall"):
return seasons[0]
def getNextTime(currentTime):
if(currentTime=="morning"):
return time[1]
if(currentTime=="noon"):
return time[2]
if(currentTime=="afternoon"):
return time[3]
if(currentTime=="night"):
return time[0]

38
Condition.py Normal file
View File

@ -0,0 +1,38 @@
import random
import Climate
class Condition:
def __init__(self):
self.season=self.setRandomSeason()
self.currentTime=self.setRandomTime()
self.weather=self.setRandomWeather()
self.clock=0
def setRandomSeason(self):
return Climate.seasons[self.randomizer(3)]
def setRandomTime(self):
return Climate.time[self.randomizer(3)]
def setRandomWeather(self):
return Climate.weather[self.randomizer(6)]
def randomizer(self,maxIndex):
return random.randint(0,maxIndex)
def cycle(self):
if(self.clock==12):
self.currentTime=Climate.time[0]
self.weather=self.setRandomWeather()
self.season=Climate.getNextSeason(self.season)
self.clock=0
return
else:
self.currentTime=Climate.getNextTime(self.currentTime)
self.weather=self.setRandomWeather()
self.clock=self.clock+1
def getCondition(self):
print(f"Aktualny czas: {self.currentTime},pogoda: {self.weather}, pora roku: {self.season}")