From d733270048004ae45db7ac9eaf5c4699764986a7 Mon Sep 17 00:00:00 2001 From: Andrzej Date: Sat, 24 Apr 2021 17:32:07 +0200 Subject: [PATCH] New way to mowe V2 --- bin/Classess/Node.py | 11 +++ bin/Classess/__pycache__/Field.cpython-37.pyc | Bin 3171 -> 3223 bytes bin/Classess/__pycache__/Node.cpython-37.pyc | Bin 0 -> 689 bytes .../__pycache__/Player.cpython-37.pyc | Bin 1832 -> 1857 bytes bin/classess/Field.py | 9 ++- bin/classess/Player.py | 13 +--- bin/main/main.py | 67 +++++++++++++++--- 7 files changed, 75 insertions(+), 25 deletions(-) create mode 100644 bin/Classess/Node.py create mode 100644 bin/Classess/__pycache__/Node.cpython-37.pyc diff --git a/bin/Classess/Node.py b/bin/Classess/Node.py new file mode 100644 index 0000000..a99ab06 --- /dev/null +++ b/bin/Classess/Node.py @@ -0,0 +1,11 @@ +class Node: + def __init__(self): + self.state = State() + self.parent = None + self.action = None + + +class State: + def __init__(self): + self.coord = [] + self.direction = "" diff --git a/bin/Classess/__pycache__/Field.cpython-37.pyc b/bin/Classess/__pycache__/Field.cpython-37.pyc index 983225f31e4c1c66555b4f920b78340e3b7aa2c7..5a793515111e08d518d0d611adbfde4fd6681a53 100644 GIT binary patch delta 612 zcmXX?J#Q016x_FaKA-Q-my5si0ZtXg5KKS{2oa$OBE*N{6ckn@khyqQmQRiecdIBu zwkSwp3M0W5X`KRzf{ucMA3;TPEe$^aQS;XEN;9XKog2M==N^vevVN$LGc=%v8{; zOp51Zb`NraLxpf3F^^5TS#A+?i{X;Y@qC$ZgBQjW2>+I)e+*bw|4dcQw}bw15VzvP zpx0}44}*?~lT0MqGU#`DLXFa&VO`a&WrLYuswdXwRUcn8AR(CmhjW~elV_wx8wtaP z8jUvaIx)HE2`SVM>$13pMof_iym23PMUU5aUmbV*oi=C_kA={SdVq+(BI)`eAj6Py z7&3%$@<~#3*gM!EFHVQ4ljl=yOm#zTXO`|-lME)z&>p~mN@tMfbZqDmQIpU`kTSWg zn;B>LWv@4yWT0DJ^&ztjS@knhU9IB)(Jf7@NQoI79f>|q+;$`aDK2&tt*f*xs`{<* z3K9X_4mH4FKKS5K3w4R9_jbRmn`*{%Ef=kK(7^vaXA2&wr_Qc_QyZI_wlv*SU!1kn gC5u@V^~+f)UPm*rnvWYhd(GBHq)$ delta 576 zcmXw#&ubGw6vyYyPLkOl*>2M|KeVaBi}NN6;=Wqn|M01I(meudR^NOd;jQO$&;T1-_O% zJaVhBr{w4;2Y2V=Mw6xF=GhzfMZ?!CI8@&y6bZ|Oh;WZUU#1@+vfxO^9TT^E?>pUC z-?t4fzVi?d21^JAdB}4C!igY)kV}~7_J?;;p{sQ<`6m+_{RA6$d)wcF9ed{QM;p}G qBs2)mY%8ePU;b>aCWS0pH&|JqF_~<>JlK8JY#-`X(yiI&!QnrzJbC5- diff --git a/bin/Classess/__pycache__/Node.cpython-37.pyc b/bin/Classess/__pycache__/Node.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..17f72cde94c14676dd716e0d2958668633c3713b GIT binary patch literal 689 zcmb7CO-sW-5Z%p3o7Pr5c<|^+=%wIM5h)h&7KGkPV2#;T18EX>(?i8u`)B-13!eNJ zo_w>lrHCFJn72FGH`#eFx$5`33~_e4x_ig^LB%F~Y(_|P47g#ENxniZy(v|m^ilb! zxC|z25N2R)!^3WbG=~7iz+qEQa_Ozu)R#W^feqqHs*Hm`K`V8Qk>&`{uqAtC0-Zq5 zp)VOad5q?8(xi>Dp>a#APPHl<+e))0ugU?pflGS0JJh@$rpHe+bOj_4U zC--@oWJPL>GA5xxhV{ZmLgZ!M2tk9G7J%`HxA;rnF*c`kKd5CoQ$pCT5VK0o3)=UD zc%G-l`b2lo?*`a`h@O#FN<;TV+|~cJPgC#j?j7LdkzB*qT002Wyx0P4m{paQwj*<` zzP-{U^yi2)JEaK#j6B$Pjt_TC(Dd)4G1}akO$0SW8`CGo7~ORt0)1K zERuv1Qb5)%Zr}W}%)IoV%=C;B>B*MNC5$qY*D=c|U{lKlQR|bMR-!QZ6>~9AX&j4; z95$sK5T&67s*`81oOw+ko%NCggl6l0}`5yMcC|MgV>=z zS(VM-T^gnsqD=wB1)HJ_Vj(;YW`TTO!~`TjfnLl5B!Iysz`@GFI(avnqK+&`S`kF> X0*PB}`AJ!+$t7S77$!~TU{?SDXWUnk delta 455 zcmX@ew}Ow)iISQlQEk?e{rHp%dG#PKP6sP8-tz;;Y znC#DF!zeYmhe>wwYNj?taiG2;2{<7MWZmNS%`eN$OApFS&nS_a9K>8=D-9IZWGUhX zspA6?oFIZ9B+6KX%?K`t5k9GDC90E|S&FTpCh)*b0J*qG0JjMo5EDWR3?^@6$!C1rWgtByO?gCuOB3mw+{3m^4|DT>${S Ca8!E$ diff --git a/bin/classess/Field.py b/bin/classess/Field.py index 857c626..124ad03 100644 --- a/bin/classess/Field.py +++ b/bin/classess/Field.py @@ -27,6 +27,10 @@ class Field(object): self.small_image_array = [[0 for i in range(self.rows)] for j in range(self.columns)] self.large_image_array = [[0 for i in range(self.rows)] for j in range(self.columns)] + # Modified by Artem to search in the status area + self.canvas_small_images = [] + self.rectangle = 0 + self.main_frame = Frame(master, width=FRAME_WIDTH, height=FRAME_HEIGHT, bd=0) self.main_frame.pack(anchor=NW) self.small_field_canvas = Canvas(self.main_frame, width=FRAME_WIDTH, height=FRAME_HEIGHT, highlightthickness=0, @@ -39,7 +43,6 @@ class Field(object): # Clear Canvases def Moving(self): - self.small_field_canvas.delete('all') self.large_image_canvas.delete('all') def PuttingSmallImages(self): @@ -55,7 +58,9 @@ class Field(object): small_image_name = self.small_image_array[column][row] self.small_field_canvas.image = small_image_name - self.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name) + self.canvas_small_images.append( + self.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name)) + # self.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name) x += self.image_size + self.x_start row += 1 diff --git a/bin/classess/Player.py b/bin/classess/Player.py index 8076e16..00611fa 100644 --- a/bin/classess/Player.py +++ b/bin/classess/Player.py @@ -22,28 +22,17 @@ class Player(object): self.arrow_south_image = None self.arrow_west_image = None self.arrow_east_image = None + self.image_canvas_id = None def MovingRight(self): if self.current_x + self.step < FRAME_WIDTH: self.current_x += self.step self.current_array_x += 1 - # # Changes the line down - # elif self.current_y + self.step < FRAME_HEIGHT: - # self.current_x = self.x_start - # self.current_array_x = 0 - # self.current_array_y += 1 - # self.current_y += self.step def MovingLeft(self): if self.current_x - self.step >= self.x_start: self.current_x -= self.step self.current_array_x -= 1 - # # Changes the line up - # elif self.current_y - self.step >= self.y_start: - # self.current_x = FRAME_WIDTH - self.step - # self.current_array_x = 9 - # self.current_array_y -= 1 - # self.current_y -= self.step def MovingUp(self): if self.current_y - self.step >= self.y_start: diff --git a/bin/main/main.py b/bin/main/main.py index 05fe255..b1494dd 100644 --- a/bin/main/main.py +++ b/bin/main/main.py @@ -5,6 +5,7 @@ from tkinter import * from bin.classess.Field import Field from bin.classess.Mine import Mine from bin.classess.Player import Player +from bin.classess.Node import Node WINDOW_X = 533 + 1200 WINDOW_Y = 950 @@ -32,12 +33,13 @@ def Arrow(direction): elif direction == "east": image = player.arrow_east_image - field.small_field_canvas.create_image(player.current_x, player.current_y, anchor=NW, image=image) + field.small_field_canvas.itemconfig(player.image_canvas_id, image=image) # Putting images -def Fill(): - field.PuttingSmallImages() +def Fill(bool): + if bool: + field.PuttingSmallImages() # Drawing red/green rectangles for el in field.state_of_cell_array: @@ -55,9 +57,19 @@ def DrawingLargeImage(): # Drawing rectangle -def Rectangle(): - field.small_field_canvas.create_rectangle(player.current_x, player.current_y, player.current_x + player.step - 2, - player.current_y + player.step - 2, width=3, outline='blue2') +# def Rectangle(bool, direction): +# if bool: +# field.rectangle = field.small_field_canvas.create_rectangle(player.current_x, player.current_y, player.current_x + player.step - 2, +# player.current_y + player.step - 2, width=3, outline='blue2') +# else: +# if direction == "East" and field.small_field_canvas.coords(field.rectangle)[0] + player.step < FRAME_WIDTH: +# field.small_field_canvas.move(field.rectangle, player.step, 0) +# elif direction == "West" and field.small_field_canvas.coords(field.rectangle)[0] > player.x_start: +# field.small_field_canvas.move(field.rectangle, -player.step, 0) +# elif direction == "North" and field.small_field_canvas.coords(field.rectangle)[1] > player.y_start: +# field.small_field_canvas.move(field.rectangle, 0, -player.step) +# elif direction == "South" and field.small_field_canvas.coords(field.rectangle)[1] + player.step < FRAME_HEIGHT: +# field.small_field_canvas.move(field.rectangle, 0, player.step) def Next_direction(side): @@ -78,24 +90,36 @@ def Next_direction(side): return player.direction +def MovingForward(): + if player.direction == "east" and field.small_field_canvas.coords(player.image_canvas_id)[0] + player.step < FRAME_WIDTH: + field.small_field_canvas.move(player.image_canvas_id, player.step, 0) + elif player.direction == "west" and field.small_field_canvas.coords(player.image_canvas_id)[0] > player.x_start: + field.small_field_canvas.move(player.image_canvas_id, -player.step, 0) + elif player.direction == "north" and field.small_field_canvas.coords(player.image_canvas_id)[1] > player.y_start: + field.small_field_canvas.move(player.image_canvas_id, 0, -player.step) + elif player.direction == "south" and field.small_field_canvas.coords(player.image_canvas_id)[1] + player.step < FRAME_HEIGHT: + field.small_field_canvas.move(player.image_canvas_id, 0, player.step) + + def Moving(event): # Moving if event.keysym == "Right": # player.MovingRight() field.Moving() - Fill() + Fill(False) next_direction = Next_direction(event.keysym) Arrow(next_direction) elif event.keysym == "Left": # player.MovingLeft() field.Moving() - Fill() + Fill(False) next_direction = Next_direction(event.keysym) Arrow(next_direction) elif event.keysym == "Up": player.Moving() field.Moving() - Fill() + Fill(False) + MovingForward() Arrow(player.direction) # elif event.keysym == "space": # player.MovingDown() @@ -151,6 +175,22 @@ def Action(event): CellDesignation(field.state_of_cell_array, "green") +# Modified by Artem to search in the status area +def MouseClickEvent(event): + print(len(field.canvas_small_images), field.canvas_small_images) + for i in range(0, len(field.canvas_small_images)): + print(field.small_field_canvas.coords(field.canvas_small_images[i])) + print("Lewy przycisk myszy zostal nacisniety!") + node = Node() + print(node.state.coord, node.state.direction, node.action, node.parent) + node.state.coord = field.small_field_canvas.coords(field.canvas_small_images[5]) + node.state.direction = "N" + node.action = "l" + node.parent = 1 + print(node.state.coord, node.state.direction, node.parent, node.action) + print("Pozycje myszy: {} {}".format(event.x, event.y)) + + def PutMines(mines_array): counter = 0 @@ -246,12 +286,17 @@ def main(): player.arrow_west_image = images[3] # Filling window with images - Fill() + Fill(True) # Drawing arrow (player) - Arrow(player.direction) + image = player.arrow_east_image + player.image_canvas_id = field.small_field_canvas.create_image(player.current_x, player.current_y, anchor=NW, + image=image) + # Arrow(player.direction) + # Rectangle(True, "None") # Rectangle() # Binding keyboard press to function field.win.bind("", Action) + field.small_field_canvas.bind("", MouseClickEvent) # Starting mainloop for window field.win.mainloop()