AI_PRO/Tractor.py

143 lines
4.1 KiB
Python
Raw Normal View History

2021-03-29 20:51:47 +02:00
from TractorLoad import TillageUnit
from constants import HORIZONTAL_TILES_NUMBER, VERTICAL_TILES_NUMBER
2021-03-29 02:19:55 +02:00
class Tractor:
2021-04-13 17:52:27 +02:00
def __init__(self, horizontal_index, vertical_index, hitch, header, autodrive, direction):
2021-03-29 02:19:55 +02:00
self.__horizontal_index = horizontal_index
self.__vertical_index = vertical_index
self.__hitch = hitch
self.__header = header
2021-03-30 00:54:29 +02:00
self.__autodrive = autodrive
2021-03-29 19:15:36 +02:00
self.__fuel_tank = 100
2021-03-29 03:41:38 +02:00
self.__engineWorking = False
2021-04-13 17:52:27 +02:00
self.__direction = direction
2021-03-29 02:19:55 +02:00
@property
def horizontal_index(self):
return self.__horizontal_index
2021-03-29 17:18:14 +02:00
def __horizontal_index(self, horizontal_index):
if 1 <= horizontal_index < HORIZONTAL_TILES_NUMBER:
2021-03-29 03:41:38 +02:00
if self.__engineWorking:
self.__horizontal_index = horizontal_index
2021-03-29 02:19:55 +02:00
@property
def vertical_index(self):
return self.__vertical_index
2021-03-29 17:18:14 +02:00
def __vertical_index(self, vertical_index):
if 1 <= self.__vertical_index < VERTICAL_TILES_NUMBER-1:
2021-03-29 03:41:38 +02:00
if self.__engineWorking:
self.__vertical_index = vertical_index
2021-03-29 02:19:55 +02:00
@property
def hitch(self):
return self.__hitch
@hitch.setter
def hitch(self, hitch):
2021-03-29 20:30:21 +02:00
if hitch == "Crop Trailer" or isinstance(hitch, TillageUnit) or hitch == "Nothing":
2021-03-29 02:19:55 +02:00
self.__hitch = hitch
@property
def fuel_tank(self):
return self.__fuel_tank
def __fuel_tank(self, fuel_tank):
if 0 < fuel_tank < 100:
self.__fuel_tank = fuel_tank
def fill_tank(self):
2021-03-29 04:17:31 +02:00
self.__fuel_tank = 100
2021-03-29 02:19:55 +02:00
def reduce_fuel(self):
2021-03-29 03:41:38 +02:00
if 0 < self.fuel_tank <= 100:
2021-06-01 22:31:49 +02:00
self.__fuel_tank = self.__fuel_tank - 0.1
2021-03-29 03:41:38 +02:00
if self.__fuel_tank <= 0:
self.__engineWorking = False
2021-03-29 02:19:55 +02:00
@property
def header(self):
return self.__header
@header.setter
def header(self, header):
2021-03-29 13:46:30 +02:00
if header is True or header is False:
2021-03-29 02:19:55 +02:00
self.__header = header
2021-03-29 03:41:38 +02:00
@property
def engineWorking(self):
return self.__engineWorking
def turnOnEngine(self):
if self.__fuel_tank > 0:
self.__engineWorking = True
else:
print("noFuel")
def turnOffEngine(self):
self.__engineWorking = False
2021-03-29 17:18:14 +02:00
2021-03-30 00:54:29 +02:00
@property
def autodrive(self):
return self.__autodrive
@autodrive.setter
def autodrive(self, autodrive):
if isinstance(autodrive, bool):
self.__autodrive = autodrive
2021-04-13 17:52:27 +02:00
@property
def direction(self):
return self.__direction
@direction.setter
def direction(self, direction):
2021-05-19 04:01:26 +02:00
self.__direction = direction
2021-04-13 17:52:27 +02:00
def drive(self):
2021-03-29 19:15:36 +02:00
mRange = 1
2021-04-13 17:52:27 +02:00
if not self.__engineWorking:
return
if self.__direction == "UP" and self.vertical_index > 0:
2021-03-29 19:15:36 +02:00
self.__vertical_index += - mRange
2021-04-13 17:52:27 +02:00
elif self.__direction == "DOWN" and self.vertical_index < VERTICAL_TILES_NUMBER-1:
2021-03-29 19:15:36 +02:00
self.__vertical_index += mRange
2021-04-13 17:52:27 +02:00
elif self.__direction == "RIGHT" and self.horizontal_index < HORIZONTAL_TILES_NUMBER-1:
2021-03-29 19:15:36 +02:00
self.__horizontal_index += mRange
2021-04-13 17:52:27 +02:00
elif self.__direction == "LEFT" and self.horizontal_index > 0:
2021-03-29 19:15:36 +02:00
self.__horizontal_index += -mRange
2021-04-13 20:29:06 +02:00
self.reduce_fuel()
2021-05-19 04:01:26 +02:00
def left_rotation(self):
if self.__direction == "UP":
self.__direction = "LEFT"
elif self.__direction == "LEFT":
self.__direction = "DOWN"
elif self.__direction == "DOWN":
self.__direction = "RIGHT"
elif self.__direction == "RIGHT":
self.__direction = "UP"
def right_rotation(self):
if self.__direction == "UP":
self.__direction = "RIGHT"
elif self.__direction == "RIGHT":
self.__direction = "DOWN"
elif self.__direction == "DOWN":
self.__direction = "LEFT"
elif self.__direction == "LEFT":
self.__direction = "UP"
def auto_movement(self, move):
if move == "Move":
self.drive()
elif move == "Left_Rotation":
self.left_rotation()
elif move == "Right_Rotation":
self.right_rotation()