From 91106af2a8c8767b0dbe1f37635663401a1e8a21 Mon Sep 17 00:00:00 2001 From: v7eZ3t Date: Mon, 29 Mar 2021 13:06:57 +0200 Subject: [PATCH] v. 1.10 --- Board.py | 3 ++- Tractor.py | 4 ++-- TractorAction.py | 21 +++++++++++++++++++++ TractorLoad.py | 2 +- drawUI.py | 13 ++++++++----- main.py | 3 ++- 6 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 TractorAction.py diff --git a/Board.py b/Board.py index d58b090..912b72d 100644 --- a/Board.py +++ b/Board.py @@ -3,11 +3,12 @@ import random from Main.Field import Field from Main.constants import * +states = ['toPlow', 'toSeed', 'toFertilize', 'toWater', 'toCut'] def generate(): board = [] for i in range(0, int(HORIZONTAL_TILES_NUMBER)): board.append([]) for j in range(0, int(VERTICAL_TILES_NUMBER)): - board[i].append(Field(int(i * TILE_SIZE), int(j * TILE_SIZE), random.randint(0, 3))) + board[i].append(Field(int(i * TILE_SIZE), int(j * TILE_SIZE), random.choice(states))) return board diff --git a/Tractor.py b/Tractor.py index 02a9f29..0dc074a 100644 --- a/Tractor.py +++ b/Tractor.py @@ -1,4 +1,4 @@ -from Main.TractorLoad import TractorTrailer +from Main.TractorLoad import TillageUnitLoad from Main.constants import HORIZONTAL_TILES_NUMBER, VERTICAL_TILES_NUMBER @@ -37,7 +37,7 @@ class Tractor: @hitch.setter def hitch(self, hitch): - if hitch == "Tillage unit" or "Crop Trailer" or TractorTrailer or "Nothing": + if hitch == "Tillage unit" or "Crop Trailer" or TillageUnitLoad or "Nothing": self.__hitch = hitch @property diff --git a/TractorAction.py b/TractorAction.py new file mode 100644 index 0000000..0083bf6 --- /dev/null +++ b/TractorAction.py @@ -0,0 +1,21 @@ +from Main import TractorLoad + + +def action(field, tractor): + + if tractor.header and tractor.hitch == "Crop Trailer": + return "toPlow" + + elif tractor.hitch == "Tillage Unit" and TractorLoad.TillageUnitLoad == "Fertilizer" and field.state == "toFertilize": + return "toSeed" + + elif tractor.hitch == "Tillage Unit" and TractorLoad.TillageUnitLoad == "Seeds" and field.state == "toSeed": + return "toWater" + + elif tractor.hitch == "Tillage Unit" and TractorLoad.TillageUnitLoad == "Water" and field.state == "toWater": + return "toCut" + + elif tractor.hitch == "Tillage Unit" and TractorLoad.TillageUnitLoad == "None": + return "toFertilize" + + diff --git a/TractorLoad.py b/TractorLoad.py index 93245bc..5966e0c 100644 --- a/TractorLoad.py +++ b/TractorLoad.py @@ -1,4 +1,4 @@ -class TractorTrailer: +class TillageUnitLoad: def __init__(self, __load): self.__load = __load diff --git a/drawUI.py b/drawUI.py index 0d8e6ce..7b52c26 100644 --- a/drawUI.py +++ b/drawUI.py @@ -15,10 +15,13 @@ def drawUI(board, display, tractor, direction): def drawInfo(display, tractor): 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"" + textsurface = myfont.render(text, False, (0, 0, 0)) + display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 150))) + def makeField(board, screen: pygame.Surface): for i in range(int(HORIZONTAL_TILES_NUMBER)): @@ -28,16 +31,16 @@ def makeField(board, screen: pygame.Surface): pos_x = i * TILE_SIZE + TILE_SIZE // 2 pos_y = j * TILE_SIZE + TILE_SIZE // 2 - if field.state == 0: + if field.state == "toWater": do_podlania_rect.center = (pos_x, pos_y) screen.blit(do_podlania, do_podlania_rect) - elif field.state == 1: + elif field.state == "toPlow": do_zaorania_rect.center = (pos_x, pos_y) screen.blit(do_zaorania, do_zaorania_rect) - elif field.state == 2: + elif field.state == "toSeed": do_zasiania_rect.center = (pos_x, pos_y) screen.blit(do_zasiania, do_zasiania_rect) - elif field.state == 3: + elif field.state == "toCut": do_zebrania_rect.center = (pos_x, pos_y) screen.blit(do_zebrania, do_zebrania_rect) diff --git a/main.py b/main.py index d1aa75b..b5f2993 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ from pygame import sysfont from Main import Board, driving, drawUI from Main.Tractor import Tractor +from Main.TractorAction import action from Main.constants import * pygame.init() @@ -32,7 +33,7 @@ while working: if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: field = board[tractor.horizontal_index][tractor.vertical_index] - field.state = 4 + field = action(field, tractor) horizontal_change, vertical_change = driving.manualTurning(event, tractor.horizontal_index, tractor.vertical_index, horizontal_change, vertical_change)