From a696da09de8fdbbd34f3cdd229d3d9a889bdac5a Mon Sep 17 00:00:00 2001 From: jakzar Date: Mon, 15 Apr 2024 11:20:47 +0200 Subject: [PATCH] -Added way to clear console -Support different dimmension of grid for console --- App.py | 23 +++++++++++++++++++---- Ui.py | 18 ++++++++++++++---- displayControler.py | 7 +++++-- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/App.py b/App.py index 0fe7caa..93c18ba 100644 --- a/App.py +++ b/App.py @@ -21,8 +21,8 @@ pole=Pole.Pole(screen,image_loader) pole.draw_grid() #musi byc tutaj wywołane ponieważ inicjalizuje sloty do slownika ui=Ui.Ui(screen) #Tractor creation -bfs1_flag=False -bfs2_flag=True #Change this lines to show different bfs implementation +bfs1_flag=True +bfs2_flag=False #Change this lines to show different bfs implementation bfs3_flag=False traktor_slot = pole.get_slot_from_cord((0, 0)) traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.opryskiwacz,clock,bfs2_flag) @@ -41,22 +41,33 @@ def init_demo(): #Demo purpose ui.render_text_to_console(string_to_print="Przejazd inicjalizujacy- traktor sprawdza poziom nawodnienia") traktor.initial_move(pole) traktor.reset_pos(pole) + clock.tick(20) + ui.clear_console() + clock.tick(20) + ui.render_text_to_console("Obliczanie sciezki przy uzyciu BFS") + for event in pygame.event.get(): + if event.type == pygame.QUIT: + quit() if(bfs1_flag): bfsRoot1 = BFS.BFS1({"x": 0, "y": 0, "direction": "E", "hydradeIndex": traktor.slot_hydrate_dict}) #displayControler: NUM_X: 6, NUM_Y: 3 (klasyczne) CHANGE THIS BY HAND bfsRoot1.reverse() + print_to_console("Traktor porusza sie obliczona sciezka BFS") traktor.move_by_root(bfsRoot1, pole, [traktor.irrigateSlot]) if(bfs2_flag): bfsRoot2 = [[{'x': 2, 'y': 2, 'direction': 'N', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 1, (1, 2): 1, (2, 2): 1, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 1, (2, 3): 1, (3, 3): 1, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 2, 'y': 2, 'direction': 'E', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 1, (1, 2): 1, (2, 2): 1, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 1, (2, 3): 1, (3, 3): 1, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'left'], [{'x': 1, 'y': 2, 'direction': 'E', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 1, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 1, (2, 3): 1, (3, 3): 1, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 0, 'y': 2, 'direction': 'E', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 1, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 1, (2, 3): 1, (3, 3): 1, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 0, 'y': 2, 'direction': 'N', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 1, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 1, (2, 3): 1, (3, 3): 1, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'right'], [{'x': 0, 'y': 3, 'direction': 'N', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 1, (2, 3): 1, (3, 3): 1, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 0, 'y': 3, 'direction': 'W', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 1, (2, 3): 1, (3, 3): 1, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'right'], [{'x': 1, 'y': 3, 'direction': 'W', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 1, (2, 3): 1, (3, 3): 1, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 2, 'y': 3, 'direction': 'W', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 1, (3, 3): 1, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 3, 'y': 3, 'direction': 'W', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 1, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 4, 'y': 3, 'direction': 'W', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 0, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 4, 'y': 3, 'direction': 'S', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 0, (4, 3): 1, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'right'], [{'x': 4, 'y': 2, 'direction': 'S', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 1, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 0, (4, 3): 0, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 4, 'y': 1, 'direction': 'S', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 1, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 0, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 0, (4, 3): 0, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 4, 'y': 0, 'direction': 'S', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 0, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 0, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 0, (4, 3): 0, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 4, 'y': 0, 'direction': 'E', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 1, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 0, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 0, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 0, (4, 3): 0, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'right'], [{'x': 3, 'y': 0, 'direction': 'E', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 1, (4, 0): 0, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 0, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 0, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 0, (4, 3): 0, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 2, 'y': 0, 'direction': 'E', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 1, (3, 0): 0, (4, 0): 0, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 0, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 0, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 0, (4, 3): 0, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 1, 'y': 0, 'direction': 'E', 'hydradeIndex': {(0, 0): -1, (1, 0): 1, (2, 0): 0, (3, 0): 0, (4, 0): 0, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 0, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 0, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 0, (4, 3): 0, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward'], [{'x': 0, 'y': 0, 'direction': 'E', 'hydradeIndex': {(0, 0): -1, (1, 0): 0, (2, 0): 0, (3, 0): 0, (4, 0): 0, (5, 0): 1, (6, 0): 1, (7, 0): 1, (8, 0): 1, (9, 0): 1, (0, 1): 1, (1, 1): 1, (2, 1): 0, (3, 1): 1, (4, 1): 0, (5, 1): 1, (6, 1): 1, (7, 1): 1, (8, 1): 1, (9, 1): 1, (0, 2): 0, (1, 2): 1, (2, 2): 0, (3, 2): 1, (4, 2): 0, (5, 2): 1, (6, 2): 1, (7, 2): 1, (8, 2): 1, (9, 2): 1, (0, 3): 1, (1, 3): 0, (2, 3): 0, (3, 3): 0, (4, 3): 0, (5, 3): 1, (6, 3): 1, (7, 3): 1, (8, 3): 1, (9, 3): 1, (0, 4): 1, (1, 4): 1, (2, 4): 1, (3, 4): 1, (4, 4): 1, (5, 4): 1, (6, 4): 1, (7, 4): 1, (8, 4): 1, (9, 4): 1}}, 'forward']] #displayControler: NUM_X: 10, NUM_Y: 5 (klasyczne - duże) CHANGE THIS IN DCON !!! bfsRoot2.reverse() + print_to_console("Traktor porusza sie obliczona sciezka BFS") traktor.move_by_root(bfsRoot2, pole, [traktor.irrigateSlot]) if(bfs3_flag): bfsRoot3 = BFS.BFS2({'x': 0, 'y': 0, 'direction': "E"}) #displayControler: NUM_X: 20, NUM_Y: 12 (skarb) CHANGE THIS IN DCON BY HAND!!!!!!!! bfsRoot3.reverse() + print_to_console("Traktor porusza sie obliczona sciezka BFS") traktor.move_by_root(bfsRoot3, pole, [traktor.irrigateSlot]) - # ui.render_text_to_console(string_to_print="traktor porusza się ścieżką bfs") + + start_flag=False # demo_move() @@ -71,7 +82,11 @@ def init(demo): init_demo() #TODO: Implement - +def print_to_console(text): + clock.tick(5) + ui.clear_console() + clock.tick(5) + ui.render_text_to_console(text) def demo_move(): current_slot = traktor.slot diff --git a/Ui.py b/Ui.py index c9755cd..e6f5ab7 100644 --- a/Ui.py +++ b/Ui.py @@ -7,7 +7,15 @@ class Ui: def __init__(self,screen): self.screen=screen self.font='freesansbold.ttf' #Feel free to change it :D - self.font_size=int(16) + if(dCon.NUM_Y<7): + self.font_size=int(15) + self.line=20 + self.first_line=20 + if(dCon.NUM_Y>=7): + self.font_size=int(30) + self.line=30 + self.first_line=30 + def render_text(self,string_to_print): font=pygame.font.Font(self.font,self.font_size) text=font.render(string_to_print,True,Colors.BLACK,Colors.WHITE) @@ -18,14 +26,16 @@ class Ui: def render_text_to_console(self,string_to_print): font=pygame.font.Font(self.font,self.font_size) self.break_string_to_console(string_to_print) - line=10 for string in self.to_print: text=font.render(string,True,Colors.BLACK,Colors.WHITE) textRect=text.get_rect() - textRect.center=(dCon.getGameWidth()+350/2,line) + textRect.center=(dCon.getGameWidth()+350/2,self.line) textRect.scale_by(x=350,y=100) self.screen.blit(text,textRect) - line=line+18 + self.line=self.line+self.first_line + def clear_console(self): + self.line=self.first_line + pygame.draw.rect(self.screen,(0,0,0) , pygame.Rect(dCon.returnConsoleCoordinate(), 0, dCon.getConsoleWidth(), dCon.getScreenHeihgt()), 0) def break_string_to_console(self,string_to_print): self.to_print=string_to_print.split(" ") diff --git a/displayControler.py b/displayControler.py index 1847af2..3d774d8 100644 --- a/displayControler.py +++ b/displayControler.py @@ -1,6 +1,6 @@ CUBE_SIZE = 64 -NUM_X = 10 -NUM_Y = 5 +NUM_X = 6 +NUM_Y = 3 #returns true if tractor can move to specified slot def isValidMove(x, y): @@ -14,6 +14,9 @@ def isValidMove(x, y): def getGameWidth(): return NUM_X * CUBE_SIZE +def returnConsoleCoordinate(): + return NUM_X * CUBE_SIZE +