AI_PROJECT/Tractor.py

48 lines
1.8 KiB
Python
Raw Permalink Normal View History

import pygame
import random
import displayControler as dCon
import Slot
2024-03-23 21:00:08 +01:00
import Osprzet
class Tractor:
2024-03-23 21:00:08 +01:00
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
2024-03-23 21:00:08 +01:00
self.slot=slot
self.osprzet = osprzet
def draw_tractor(self):
2024-03-23 21:00:08 +01:00
self.screen.blit(self.tractor_image, (self.slot.x_axis*dCon.CUBE_SIZE,self.slot.y_axis*dCon.CUBE_SIZE))
pygame.display.update()
2024-03-23 21:00:08 +01:00
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")