53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
import pygame
|
|
import random
|
|
import displayControler as dCon
|
|
import Slot
|
|
import Osprzet
|
|
|
|
class Tractor:
|
|
def __init__(self,slot,screen, osprzet):
|
|
self.tractor_image = pygame.image.load('images/traktor.png')
|
|
self.tractor_image = pygame.transform.scale(self.tractor_image, (dCon.CUBE_SIZE, dCon.CUBE_SIZE))
|
|
self.screen=screen
|
|
self.slot=slot
|
|
self.osprzet = osprzet
|
|
|
|
def draw_tractor(self):
|
|
self.screen.blit(self.tractor_image, (self.slot.x_axis*dCon.CUBE_SIZE,self.slot.y_axis*dCon.CUBE_SIZE))
|
|
pygame.display.update()
|
|
|
|
def move_tractor(self, pole, direction):
|
|
next_slot = None
|
|
if direction == "right" and pole.is_valid_move((self.slot.x_axis + 1, self.slot.y_axis)):
|
|
next_slot = pole.get_neighbor(self.slot, 1, 0)
|
|
elif direction == "left" and pole.is_valid_move((self.slot.x_axis - 1, self.slot.y_axis)):
|
|
next_slot = pole.get_neighbor(self.slot, -1, 0)
|
|
elif direction == "down" and pole.is_valid_move((self.slot.x_axis, self.slot.y_axis + 1)):
|
|
next_slot = pole.get_neighbor(self.slot, 0, 1)
|
|
elif direction == "up" and pole.is_valid_move((self.slot.x_axis, self.slot.y_axis - 1)):
|
|
next_slot = pole.get_neighbor(self.slot, 0, -1)
|
|
|
|
if next_slot:
|
|
self.slot = next_slot
|
|
self.draw_tractor()
|
|
|
|
def random_move(self, pole):
|
|
directions = ["right", "left", "down", "up"]
|
|
direction = random.choice(directions)
|
|
self.move_tractor(pole, direction)
|
|
|
|
|
|
#to tak zrobiłam już na później, może się przyda
|
|
def change_osprzet(self, new_osprzet):
|
|
self.osprzet = new_osprzet
|
|
|
|
def print_osprzet_info(self):
|
|
print("ID:", self.osprzet.id)
|
|
print("Marka:", self.osprzet.marka)
|
|
print("Model:", self.osprzet.model)
|
|
if self.osprzet.akcje:
|
|
print("Akcje:")
|
|
for akcja in self.osprzet.akcje:
|
|
print("- Typ:", akcja.typ)
|
|
else:
|
|
print("Brak akcji przypisanych do tego sprzętu.") |