forked from s452751/AI_PRO
v. 1.10
This commit is contained in:
parent
aa9e61f921
commit
91106af2a8
3
Board.py
3
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
|
||||
|
@ -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
|
||||
|
21
TractorAction.py
Normal file
21
TractorAction.py
Normal file
@ -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"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
class TractorTrailer:
|
||||
class TillageUnitLoad:
|
||||
def __init__(self, __load):
|
||||
self.__load = __load
|
||||
|
||||
|
13
drawUI.py
13
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)
|
||||
|
||||
|
3
main.py
3
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)
|
||||
|
Loading…
Reference in New Issue
Block a user