AI_PROJECT/Tractor.py

48 lines
1.8 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):
if self.osprzet is not None:
print("Wyposazenie:", self.osprzet.marka, self.osprzet.model)
else:
print("Brak")