From 8098a258f2b3031514e72be2d100a7c882020619 Mon Sep 17 00:00:00 2001 From: secret_dude Date: Tue, 27 Apr 2021 21:35:58 +0200 Subject: [PATCH] field cost final --- Board.py | 15 +++------------ Field.py | 22 +++++++++++++--------- main.py | 2 ++ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Board.py b/Board.py index b6639be..f2b6de6 100644 --- a/Board.py +++ b/Board.py @@ -11,17 +11,8 @@ def generate(): for i in range(0, int(HORIZONTAL_TILES_NUMBER)): board.append([]) for j in range(0, int(VERTICAL_TILES_NUMBER)): - current_state = random.choice(states) - current_cost = getCost(current_state) - board[i].append(Field(int(i * TILE_SIZE), int(j * TILE_SIZE), current_state, current_cost)) + board[i].append(Field(int(i * TILE_SIZE), int(j * TILE_SIZE), random.choice(states))) - board[0][0] = Field(int(0 * TILE_SIZE), int(0 * TILE_SIZE), "TOOLS_FIELD", cost=0) - board[1][0] = Field(int(1 * TILE_SIZE), int(0 * TILE_SIZE), "FUEL_FIELD", cost=0) + board[0][0] = Field(int(0 * TILE_SIZE), int(0 * TILE_SIZE), "TOOLS_FIELD") + board[1][0] = Field(int(1 * TILE_SIZE), int(0 * TILE_SIZE), "FUEL_FIELD") return board - -def getCost(state): - if state == 'toPlow': return 1 - if state == 'toSeed': return 2 - if state == 'toFertilize': return 3 - if state == 'toWater': return 4 - if state == 'toCut': return 5 diff --git a/Field.py b/Field.py index e9f48a9..3167904 100644 --- a/Field.py +++ b/Field.py @@ -1,9 +1,8 @@ class Field: - def __init__(self, horizontal_index, vertical_index, state, cost): + def __init__(self, horizontal_index, vertical_index, state): self.__horizontal_index = horizontal_index self.__vertical_index = vertical_index self.__state = state - self.__cost = cost @property def state(self): @@ -11,7 +10,18 @@ class Field: @property def cost(self): - return self.__cost + if self.state == 'toPlow': + return 1 + elif self.state == 'toSeed': + return 2 + elif self.state == 'toFertilize': + return 3 + elif self.state == 'toWater': + return 4 + elif self.state == 'toCut': + return 5 + else: + return 0 @property def horizontal_index(self): @@ -26,9 +36,3 @@ class Field: if state == "toPlow" or state == "toWater" or state == "toSeed" or \ state == "toFertilize" or state == "toCut" or state == "TOOLS_FIELD" or state == "FUEL_FIELD": self.__state = state - - @cost.setter - def cost(self, cost): - if cost == 1 or cost == 2 or cost == 3 or \ - cost == 4 or cost == 5 or cost == 0: - self.__cost = cost \ No newline at end of file diff --git a/main.py b/main.py index 8b4b095..3b14263 100644 --- a/main.py +++ b/main.py @@ -45,6 +45,8 @@ while working: field = board[tractor.horizontal_index][tractor.vertical_index] + print("curr field cost", field.cost) + print("tractor dir", tractor.direction) if tractor.autodrive and tractor.engineWorking: animationSpeed = ANIMATION_PART else: