field cost final

This commit is contained in:
secret_dude 2021-04-27 21:35:58 +02:00
parent 5e4af5773b
commit 8098a258f2
3 changed files with 18 additions and 21 deletions

View File

@ -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

View File

@ -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

View File

@ -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: