v. 1.10
This commit is contained in:
parent
968013d375
commit
f748251d10
30
Tractor.py
30
Tractor.py
@ -3,12 +3,13 @@ from Main.constants import HORIZONTAL_TILES_NUMBER, VERTICAL_TILES_NUMBER
|
|||||||
|
|
||||||
|
|
||||||
class Tractor:
|
class Tractor:
|
||||||
def __init__(self, horizontal_index, vertical_index, hitch, header, fuel_tank):
|
def __init__(self, horizontal_index, vertical_index, hitch, header):
|
||||||
self.__horizontal_index = horizontal_index
|
self.__horizontal_index = horizontal_index
|
||||||
self.__vertical_index = vertical_index
|
self.__vertical_index = vertical_index
|
||||||
self.__hitch = hitch
|
self.__hitch = hitch
|
||||||
self.__header = header
|
self.__header = header
|
||||||
self.__fuel_tank = fuel_tank
|
self.__fuel_tank = 100
|
||||||
|
self.__engineWorking = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def horizontal_index(self):
|
def horizontal_index(self):
|
||||||
@ -17,7 +18,8 @@ class Tractor:
|
|||||||
@horizontal_index.setter
|
@horizontal_index.setter
|
||||||
def horizontal_index(self, horizontal_index):
|
def horizontal_index(self, horizontal_index):
|
||||||
if self.__horizontal_index > 1 or self.__horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
|
if self.__horizontal_index > 1 or self.__horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
|
||||||
self.__horizontal_index = horizontal_index
|
if self.__engineWorking:
|
||||||
|
self.__horizontal_index = horizontal_index
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def vertical_index(self):
|
def vertical_index(self):
|
||||||
@ -26,7 +28,8 @@ class Tractor:
|
|||||||
@vertical_index.setter
|
@vertical_index.setter
|
||||||
def vertical_index(self, vertical_index):
|
def vertical_index(self, vertical_index):
|
||||||
if self.__vertical_index > 1 or self.__vertical_index < VERTICAL_TILES_NUMBER - 1:
|
if self.__vertical_index > 1 or self.__vertical_index < VERTICAL_TILES_NUMBER - 1:
|
||||||
self.__vertical_index = vertical_index
|
if self.__engineWorking:
|
||||||
|
self.__vertical_index = vertical_index
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hitch(self):
|
def hitch(self):
|
||||||
@ -34,7 +37,7 @@ class Tractor:
|
|||||||
|
|
||||||
@hitch.setter
|
@hitch.setter
|
||||||
def hitch(self, hitch):
|
def hitch(self, hitch):
|
||||||
if hitch is "Tillage unit" or "Crop Trailer" or TractorTrailer or "Nothing":
|
if hitch == "Tillage unit" or "Crop Trailer" or TractorTrailer or "Nothing":
|
||||||
self.__hitch = hitch
|
self.__hitch = hitch
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -49,8 +52,10 @@ class Tractor:
|
|||||||
self.__fuel_tank(100)
|
self.__fuel_tank(100)
|
||||||
|
|
||||||
def reduce_fuel(self):
|
def reduce_fuel(self):
|
||||||
if 0 < self.fuel_tank < 100:
|
if 0 < self.fuel_tank <= 100:
|
||||||
self.__fuel_tank = self.__fuel_tank - 1
|
self.__fuel_tank = self.__fuel_tank - 1
|
||||||
|
if self.__fuel_tank <= 0:
|
||||||
|
self.__engineWorking = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def header(self):
|
def header(self):
|
||||||
@ -60,3 +65,16 @@ class Tractor:
|
|||||||
def header(self, header):
|
def header(self, header):
|
||||||
if header is True or False:
|
if header is True or False:
|
||||||
self.__header = header
|
self.__header = header
|
||||||
|
|
||||||
|
@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
|
||||||
|
@ -29,7 +29,7 @@ TRACTOR_WIDTH = TILE_SIZE
|
|||||||
TRACTOR_HEIGHT = TILE_SIZE
|
TRACTOR_HEIGHT = TILE_SIZE
|
||||||
|
|
||||||
#FRAMES PER SECOND
|
#FRAMES PER SECOND
|
||||||
FPS = 100
|
FPS = 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,13 +2,13 @@ from Main.drawUI import *
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor_horizontal_index, tractor_vertical_index):
|
def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor):
|
||||||
if not cruiseControl:
|
if cruiseControl == False or tractor.engineWorking == False:
|
||||||
horizontal_change = 0
|
horizontal_change = 0
|
||||||
vertical_change = 0
|
vertical_change = 0
|
||||||
if tractor_horizontal_index <= 0 or tractor_horizontal_index >= HORIZONTAL_TILES_NUMBER - 1:
|
if tractor.horizontal_index <= 0 or tractor.horizontal_index >= HORIZONTAL_TILES_NUMBER - 1:
|
||||||
horizontal_change = 0
|
horizontal_change = 0
|
||||||
if tractor_vertical_index <= 0 or tractor_vertical_index >= VERTICAL_TILES_NUMBER - 1:
|
if tractor.vertical_index <= 0 or tractor.vertical_index >= VERTICAL_TILES_NUMBER - 1:
|
||||||
vertical_change = 0
|
vertical_change = 0
|
||||||
return horizontal_change, vertical_change
|
return horizontal_change, vertical_change
|
||||||
|
|
||||||
|
11
main.py
11
main.py
@ -19,7 +19,8 @@ vertical_change = 0
|
|||||||
|
|
||||||
board = Board.generate()
|
board = Board.generate()
|
||||||
|
|
||||||
tractor = Tractor(horizontal_index=0, vertical_index=0, hitch="nothing", header=False, fuel_tank=100)
|
tractor = Tractor(horizontal_index=0, vertical_index=0, hitch="nothing", header=False)
|
||||||
|
tractor.turnOnEngine()
|
||||||
|
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
@ -35,11 +36,11 @@ while working:
|
|||||||
tractor.vertical_index, horizontal_change,
|
tractor.vertical_index, horizontal_change,
|
||||||
vertical_change)
|
vertical_change)
|
||||||
#todo usunąć /10
|
#todo usunąć /10
|
||||||
tractor.horizontal_index += horizontal_change/10
|
tractor.horizontal_index += horizontal_change
|
||||||
tractor.vertical_index += vertical_change/10
|
tractor.vertical_index += vertical_change
|
||||||
|
|
||||||
horizontal_change, vertical_change = driving.cruiseControl(cruiseControl, horizontal_change, vertical_change,
|
horizontal_change, vertical_change = driving.cruiseControl(cruiseControl, horizontal_change, vertical_change,
|
||||||
tractor.horizontal_index, tractor.vertical_index)
|
tractor)
|
||||||
|
|
||||||
direction = driving.getDirection(horizontal_change, vertical_change)
|
direction = driving.getDirection(horizontal_change, vertical_change)
|
||||||
|
|
||||||
@ -52,6 +53,8 @@ while working:
|
|||||||
lastDirection)
|
lastDirection)
|
||||||
|
|
||||||
clock.tick(FPS)
|
clock.tick(FPS)
|
||||||
|
tractor.reduce_fuel()
|
||||||
|
print(tractor.fuel_tank)
|
||||||
|
|
||||||
print(tractor.horizontal_index + horizontal_change, " ", tractor.vertical_index + vertical_change)
|
print(tractor.horizontal_index + horizontal_change, " ", tractor.vertical_index + vertical_change)
|
||||||
print(horizontal_change, " ", vertical_change)
|
print(horizontal_change, " ", vertical_change)
|
||||||
|
Loading…
Reference in New Issue
Block a user