diff --git a/Tractor.py b/Tractor.py index dcaafa6..f305a31 100644 --- a/Tractor.py +++ b/Tractor.py @@ -3,12 +3,13 @@ from Main.constants import HORIZONTAL_TILES_NUMBER, VERTICAL_TILES_NUMBER class Tractor: - def __init__(self, horizontal_index, vertical_index, hitch, header, fuel_tank): + def __init__(self, horizontal_index, vertical_index, hitch, header): self.__horizontal_index = horizontal_index self.__vertical_index = vertical_index self.__hitch = hitch self.__header = header - self.__fuel_tank = fuel_tank + self.__fuel_tank = 100 + self.__engineWorking = False @property def horizontal_index(self): @@ -17,7 +18,8 @@ class Tractor: @horizontal_index.setter def horizontal_index(self, horizontal_index): if self.__horizontal_index > 1 or self.__horizontal_index < HORIZONTAL_TILES_NUMBER - 1: - self.__horizontal_index = horizontal_index + if self.__engineWorking: + self.__horizontal_index = horizontal_index @property def vertical_index(self): @@ -26,7 +28,8 @@ class Tractor: @vertical_index.setter def vertical_index(self, vertical_index): if self.__vertical_index > 1 or self.__vertical_index < VERTICAL_TILES_NUMBER - 1: - self.__vertical_index = vertical_index + if self.__engineWorking: + self.__vertical_index = vertical_index @property def hitch(self): @@ -34,7 +37,7 @@ class Tractor: @hitch.setter def hitch(self, hitch): - if hitch is "Tillage unit" or "Crop Trailer" or TractorTrailer or "Nothing": + if hitch == "Tillage unit" or "Crop Trailer" or TractorTrailer or "Nothing": self.__hitch = hitch @property @@ -49,8 +52,10 @@ class Tractor: self.__fuel_tank(100) def reduce_fuel(self): - if 0 < self.fuel_tank < 100: + if 0 < self.fuel_tank <= 100: self.__fuel_tank = self.__fuel_tank - 1 + if self.__fuel_tank <= 0: + self.__engineWorking = False @property def header(self): @@ -60,3 +65,16 @@ class Tractor: def header(self, header): if header is True or False: self.__header = header + + @property + def engineWorking(self): + return self.__engineWorking + + def turnOnEngine(self): + if self.__fuel_tank > 0: + self.__engineWorking = True + else: + print("noFuel") + + def turnOffEngine(self): + self.__engineWorking = False diff --git a/constants.py b/constants.py index 3e0ccf4..09a50e2 100644 --- a/constants.py +++ b/constants.py @@ -29,7 +29,7 @@ TRACTOR_WIDTH = TILE_SIZE TRACTOR_HEIGHT = TILE_SIZE #FRAMES PER SECOND -FPS = 100 +FPS = 5 diff --git a/driving.py b/driving.py index 1f47f8f..610c6f4 100644 --- a/driving.py +++ b/driving.py @@ -2,13 +2,13 @@ from Main.drawUI import * import pygame -def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor_horizontal_index, tractor_vertical_index): - if not cruiseControl: +def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor): + if cruiseControl == False or tractor.engineWorking == False: horizontal_change = 0 vertical_change = 0 - if tractor_horizontal_index <= 0 or tractor_horizontal_index >= HORIZONTAL_TILES_NUMBER - 1: + if tractor.horizontal_index <= 0 or tractor.horizontal_index >= HORIZONTAL_TILES_NUMBER - 1: horizontal_change = 0 - if tractor_vertical_index <= 0 or tractor_vertical_index >= VERTICAL_TILES_NUMBER - 1: + if tractor.vertical_index <= 0 or tractor.vertical_index >= VERTICAL_TILES_NUMBER - 1: vertical_change = 0 return horizontal_change, vertical_change diff --git a/main.py b/main.py index 68ff90d..461c682 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,8 @@ vertical_change = 0 board = Board.generate() -tractor = Tractor(horizontal_index=0, vertical_index=0, hitch="nothing", header=False, fuel_tank=100) +tractor = Tractor(horizontal_index=0, vertical_index=0, hitch="nothing", header=False) +tractor.turnOnEngine() clock = pygame.time.Clock() @@ -35,11 +36,11 @@ while working: tractor.vertical_index, horizontal_change, vertical_change) #todo usunąć /10 - tractor.horizontal_index += horizontal_change/10 - tractor.vertical_index += vertical_change/10 + tractor.horizontal_index += horizontal_change + tractor.vertical_index += vertical_change horizontal_change, vertical_change = driving.cruiseControl(cruiseControl, horizontal_change, vertical_change, - tractor.horizontal_index, tractor.vertical_index) + tractor) direction = driving.getDirection(horizontal_change, vertical_change) @@ -52,6 +53,8 @@ while working: lastDirection) clock.tick(FPS) + tractor.reduce_fuel() + print(tractor.fuel_tank) print(tractor.horizontal_index + horizontal_change, " ", tractor.vertical_index + vertical_change) print(horizontal_change, " ", vertical_change)