diff --git a/Tractor.py b/Tractor.py index 13fcf0a..d88ef16 100644 --- a/Tractor.py +++ b/Tractor.py @@ -1,4 +1,4 @@ -from Main.TractorLoad import TillageUnitLoad +from Main.TractorLoad import TillageUnit from Main.constants import HORIZONTAL_TILES_NUMBER, VERTICAL_TILES_NUMBER @@ -8,7 +8,7 @@ class Tractor: self.__vertical_index = vertical_index self.__hitch = hitch self.__header = header - self.__fuel_tank = 100 + self.__fuel_tank = 10000000 self.__engineWorking = False @property @@ -37,7 +37,7 @@ class Tractor: @hitch.setter def hitch(self, hitch): - if hitch == "Tillage unit" or "Crop Trailer" or TillageUnitLoad or "Nothing": + if hitch == "Tillage unit" or hitch == "Crop Trailer" or isinstance(hitch, TillageUnit) or hitch == "Nothing": self.__hitch = hitch @property diff --git a/TractorAction.py b/TractorAction.py index 47b879e..b01c979 100644 --- a/TractorAction.py +++ b/TractorAction.py @@ -1,18 +1,19 @@ from Main import TractorLoad +from Main.TractorLoad import TillageUnit -def action(field, tractor): - if tractor.header and tractor.hitch == "Crop Trailer": +def action(field, tractor, tillageUnit): + if tractor.header and tractor.hitch == "Crop Trailer" and field.state == "toCut": return "toPlow" - elif tractor.hitch == "Tillage Unit" and TractorLoad.TillageUnitLoad == "Fertilizer" and field.state == "toFertilize": + elif isinstance(tractor.hitch, TillageUnit) and tillageUnit.load == "Fertilizer" and field.state == "toFertilize": return "toSeed" - elif tractor.hitch == "Tillage Unit" and TractorLoad.TillageUnitLoad == "Seeds" and field.state == "toSeed": + elif isinstance(tractor.hitch, TillageUnit) and tillageUnit.load == "Seeds" and field.state == "toSeed": return "toWater" - elif tractor.hitch == "Tillage Unit" and TractorLoad.TillageUnitLoad == "Water" and field.state == "toWater": + elif isinstance(tractor.hitch, TillageUnit) and tillageUnit.load == "Water" and field.state == "toWater": return "toCut" - elif tractor.hitch == "Tillage Unit" and TractorLoad.TillageUnitLoad == "None": + elif isinstance(tractor.hitch, TillageUnit) and tillageUnit.load == "Nothing" and field.state == "toPlow": return "toFertilize" diff --git a/TractorLoad.py b/TractorLoad.py index 5966e0c..c304637 100644 --- a/TractorLoad.py +++ b/TractorLoad.py @@ -1,4 +1,4 @@ -class TillageUnitLoad: +class TillageUnit: def __init__(self, __load): self.__load = __load @@ -8,5 +8,5 @@ class TillageUnitLoad: @load.setter def load(self, load): - if self.__load is "Fertilizer" or "Seeds" or "Water": + if load == "Fertilizer" or load == "Seeds" or load == "Water" or load == "Nothing": self.__load = load diff --git a/drawUI.py b/drawUI.py index 7b52c26..2ec584a 100644 --- a/drawUI.py +++ b/drawUI.py @@ -3,25 +3,29 @@ from Main.images import * import pygame -def drawUI(board, display, tractor, direction): +def drawUI(board, display, tractor, direction, tillageUnit, field): display.fill(WHITE) makeField(board, display) drawTractor(display, tractor.horizontal_index, tractor.vertical_index, direction) - drawInfo(display, tractor) + drawInfo(display, tractor, tillageUnit, field) pygame.display.update() -def drawInfo(display, tractor): +def drawInfo(display, tractor, tillageUnit, field): myfont = pygame.font.SysFont('Comic Sans MS', 30) text = f"Fuel: {tractor.fuel_tank} \t Hitches: {tractor.hitch} \t Header: {tractor.header} \t Engine working: {tractor.engineWorking}" textsurface = myfont.render(text, False, (0, 0, 0)) display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 200))) - text = f"" + text = f"Tillage Unit Load: {tillageUnit.load}" textsurface = myfont.render(text, False, (0, 0, 0)) display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 150))) + text = f"Current field: {field.state}" + textsurface = myfont.render(text, False, (0, 0, 0)) + display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 100))) + def makeField(board, screen: pygame.Surface): for i in range(int(HORIZONTAL_TILES_NUMBER)): @@ -48,7 +52,7 @@ def makeField(board, screen: pygame.Surface): def drawTractor(screen: pygame.Surface, tractor_horizontal_index, tractor_vertical_index, direction): if direction == "UP": screen.blit(tractor_up, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE)) - elif direction is "DOWN": + elif direction == "DOWN": screen.blit(tractor_down, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE)) elif direction == "LEFT": screen.blit(tractor_left, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE)) diff --git a/main.py b/main.py index a18a9ff..a19b37b 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ from pygame import sysfont from Main import Board, driving, drawUI from Main.Tractor import Tractor from Main.TractorAction import action +from Main.TractorLoad import TillageUnit from Main.constants import * pygame.init() @@ -13,15 +14,20 @@ display = pygame.display.set_mode((DISPLAY_SIZE_HORIZONTAL, DISPLAY_SIZE_VERTICA pygame.display.set_caption('Tractor') working = True -cruiseControl = True +cruiseControl = False lastDirection = "RIGHT" horizontal_change = 0 vertical_change = 0 + hitchCounter = 0 +loadCounter = 0 + board = Board.generate() tractor = Tractor(horizontal_index=0, vertical_index=0, hitch="nothing", header=False) +tillageUnit = TillageUnit("Nothing") + tractor.turnOnEngine() clock = pygame.time.Clock() @@ -33,13 +39,15 @@ while working: if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: field = board[tractor.horizontal_index][tractor.vertical_index] - field.state = action(field, tractor) + field.state = action(field, tractor, tillageUnit) if event.key == pygame.K_q: hitchCounter = (hitchCounter + 1) % 3 if hitchCounter == 0: tractor.hitch = "Crop Trailer" if hitchCounter == 1: - tractor.hitch = "Tillage Unit" + print(type(tillageUnit)) + print(isinstance(tillageUnit, TillageUnit)) + tractor.hitch = tillageUnit if hitchCounter == 2: tractor.hitch = "Nothing" if event.key == pygame.K_w: @@ -47,6 +55,18 @@ while working: tractor.header = False else: tractor.header = True + if event.key == pygame.K_e: + loadCounter = (loadCounter+1)%4 + if loadCounter == 0: + tillageUnit.load = "Nothing" + elif loadCounter == 1: + tillageUnit.load = "Seeds" + elif loadCounter == 2: + tillageUnit.load = "Water" + elif loadCounter == 3: + tillageUnit.load = "Fertilizer" + + horizontal_change, vertical_change = driving.manualTurning(event, tractor.horizontal_index, tractor.vertical_index, horizontal_change, @@ -60,11 +80,13 @@ while working: direction = driving.getDirection(horizontal_change, vertical_change) + field = board[tractor.horizontal_index][tractor.vertical_index] + if direction != "STOP": lastDirection = direction - drawUI.drawUI(board, display, tractor, direction) + drawUI.drawUI(board, display, tractor, direction, tillageUnit, field) else: - drawUI.drawUI(board, display, tractor, lastDirection) + drawUI.drawUI(board, display, tractor, lastDirection, tillageUnit, field) clock.tick(FPS) tractor.reduce_fuel()