2024-03-23 13:46:48 +01:00
|
|
|
import pygame
|
|
|
|
import Colors
|
|
|
|
import Tractor
|
|
|
|
import Pole
|
|
|
|
import time
|
|
|
|
import displayControler as dCon
|
|
|
|
import Image
|
2024-03-23 21:00:08 +01:00
|
|
|
import Osprzet
|
2024-04-13 01:39:39 +02:00
|
|
|
import Ui
|
2024-03-23 13:46:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
pygame.init()
|
2024-04-13 01:51:52 +02:00
|
|
|
show_console=True
|
|
|
|
screen = pygame.display.set_mode((dCon.getScreenWidth(show_console), dCon.getScreenHeihgt()))
|
2024-04-13 01:39:39 +02:00
|
|
|
FPS=5
|
|
|
|
clock=pygame.time.Clock()
|
2024-03-23 13:46:48 +01:00
|
|
|
image_loader=Image.Image()
|
|
|
|
image_loader.load_images()
|
|
|
|
pole=Pole.Pole(screen,image_loader)
|
2024-03-23 21:00:08 +01:00
|
|
|
pole.draw_grid() #musi byc tutaj wywołane ponieważ inicjalizuje sloty do slownika
|
2024-04-13 01:39:39 +02:00
|
|
|
ui=Ui.Ui(screen)
|
2024-03-23 21:00:08 +01:00
|
|
|
#Tractor creation
|
|
|
|
traktor_slot = pole.get_slot_from_cord((0, 0))
|
2024-04-13 23:55:58 +02:00
|
|
|
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.opryskiwacz,clock)
|
2024-03-23 13:46:48 +01:00
|
|
|
|
2024-03-24 23:30:02 +01:00
|
|
|
|
2024-03-23 21:00:08 +01:00
|
|
|
def init_demo(): #Demo purpose
|
2024-03-24 23:30:02 +01:00
|
|
|
old_info=""
|
2024-03-23 13:46:48 +01:00
|
|
|
traktor.draw_tractor()
|
|
|
|
time.sleep(2)
|
|
|
|
pole.randomize_colors()
|
|
|
|
traktor.draw_tractor()
|
2024-04-13 01:39:39 +02:00
|
|
|
start_flag=True
|
2024-03-23 13:46:48 +01:00
|
|
|
while True:
|
2024-04-13 01:39:39 +02:00
|
|
|
clock.tick(FPS)
|
|
|
|
if(start_flag):
|
|
|
|
ui.render_text_to_console(string_to_print="Przejazd inicjalizujacy- traktor sprawdza poziom nawodnienia")
|
|
|
|
traktor.initial_move(pole)
|
|
|
|
traktor.reset_pos(pole)
|
2024-04-13 23:55:58 +02:00
|
|
|
bfsRoot = Tractor.BFS({"x": 0, "y": 0, "direction": "E", "hydradeIndex": traktor.slot_hydrate_dict})
|
|
|
|
bfsRoot.reverse()
|
2024-04-14 00:41:18 +02:00
|
|
|
# ui.render_text_to_console(string_to_print="traktor porusza się ścieżką bfs")
|
2024-04-14 00:13:27 +02:00
|
|
|
traktor.move_by_root(bfsRoot, pole, [traktor.irrigateSlot])
|
2024-04-13 01:39:39 +02:00
|
|
|
start_flag=False
|
2024-04-13 23:55:58 +02:00
|
|
|
# demo_move()
|
2024-03-24 23:30:02 +01:00
|
|
|
old_info=get_info(old_info)
|
2024-03-23 13:46:48 +01:00
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
quit()
|
|
|
|
|
|
|
|
def init(demo):
|
|
|
|
pygame.display.update()
|
|
|
|
if(demo==True):
|
|
|
|
init_demo()
|
|
|
|
#TODO: Implement
|
|
|
|
|
|
|
|
|
2024-04-13 01:39:39 +02:00
|
|
|
|
2024-03-23 13:46:48 +01:00
|
|
|
def demo_move():
|
2024-03-23 21:00:08 +01:00
|
|
|
current_slot = traktor.slot
|
|
|
|
if current_slot:
|
|
|
|
current_slot.redraw_image() # Przerysowanie obrazu dla aktualnego slotu
|
|
|
|
traktor.random_move(pole)
|
2024-03-23 13:46:48 +01:00
|
|
|
|
2024-03-24 23:30:02 +01:00
|
|
|
def get_info(old_info):
|
|
|
|
(x,y)=pygame.mouse.get_pos()
|
|
|
|
new_info=pole.check_collision(x,y)
|
|
|
|
if(old_info!=new_info):
|
|
|
|
print(new_info)
|
|
|
|
return new_info
|
|
|
|
|
2024-03-23 13:46:48 +01:00
|
|
|
|
|
|
|
|