From 5f9560362672981a8e9920c116cbf0dfdc55afcd Mon Sep 17 00:00:00 2001 From: Andrzej Date: Mon, 29 Mar 2021 06:26:14 +0200 Subject: [PATCH] Added flags --- bin/__pycache__/main.cpython-37.pyc | Bin 0 -> 3251 bytes bin/main.py | 54 +++++++++++++++++++++------- 2 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 bin/__pycache__/main.cpython-37.pyc diff --git a/bin/__pycache__/main.cpython-37.pyc b/bin/__pycache__/main.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ff1d4c3b2f5ce66940941429db919333b069200d GIT binary patch literal 3251 zcmcguPjef$6$f^)%Oyopq)gdT9LI9pe@r`)CzrIT>WN~@wwhY;#GWeUINh#^6}9y8 zkFc;UYRHpx)uHE1XQY{4`UUz8`XzA9NngRI{vOtnDNQ?_$)V)n?ZX4`0Q}xRd|9cK z7=CNpTYuS^W$Xv)oc#otFVM0vh-8wdtjAlN6Yr$XGy1xz+Y>EeWg_)jp7dJ2^jig4 zXa#6R8MI3A%mItavM5W3tW|l)BUR*z5 z&?}y@=G-Yxz?$6ny(rVM0>?k0?vpec#cDJ8m(N)8PZwm~VeIr%%x=>X`f)T2vwLXS zuRt`@yz49ybr;!$jhPmqr$yJ7Tyk9)<9bK-O4!=nRHUHk7(eQ_cLvIMNiXWe&A`;t zNOj`ScEd=iXk`4MJ&>7gzfvmh>s%a;E(`X|-1Oph)PEgis(_75xvk52k9E`u4{9=g*&v?(IaX_dJV+!&p6kk@TPUqNKk(9GUuk6}?INoj=eq zH|Wq;uqq=g7_SMRt2uDzIFT6O92mxxt`ztR=>Zqtcn^{|m2EFJrZCDGKqs;|-L`P$qzjq;!c64!E$bAnz)-93tYwR=H0kGlg?%vsAW71Az z+>TL?W(Ye&&?$D8wwOlHQCI?6apuE{Y;WD{)H-!pT_*t<+juJKcVhJc2^L9E&w5ds zUU2X7Hkmw}a#vNM`GlZaAVMD13>4vN_@3b-Z79?_14|VYw5s{O>1X zEGFKVeUE%H_P%F-b76Z&yJKIvM-JJZY)+oAiY5iw7hey_uR&HEJ67iGHnws*`net7 z@|C8e=rBfXCuyv1f>jNWrZCO`agZjNmWeW@Cp!Z@u%WNYG#;2DYou=0Xd5=!s(13MtaA3%_W>n#j4IW`fHT^euw259fOGg#u2;;=8*o$p&=YI-xo4@yE2gjobN6bsHcV|EW#x=UIr*BmaAfW+SA7 zJoMed1ld}0+}+l<9FM;`yHr4(3v1o8wdDJDZ9r?^&E>Y>SyQ9xIm>qxMdBsXzb&nj zleGuE;oU#eF>;IU-?qhPH6660G`qX}e$o`%bk!1;7|&)Cn{43EzoAWjLF9cz+F<+~ zvgs`r{@WH8?)ZPgCqMRo07%iXL$n`(jQTCXKuP$2;WD*>%>sb-Dy_W+Vw@MU$!*F< z4c$p}d}*|kKb9zBlSBB#DPe{k$>-EhK=yAgFRxIB$yTN^cD7E-+0>R0jTZu7PYwl+5Jf4vocd(QpI1kVP;G=3eY#>d-5qIP&X(P?ag zPCV$vT8(Tj&LN`otcpaIh}hb7i#W>Ac%Ue%EjCfkJoskq@p`zmasSyPQ_ee&);AtL zdS=8hYQMB4%=q{6huFuYgA%6k@StnQwnC~;N#G{Ej+xD`d7esbax=5}E#FJ2zL?@S zNVh1hxPrjzOd9|3;5A-lCLljf2ZJG^Y$m^JXkRrY8VI-T;V;I55j6A|YBPFaF{kSI zyu?c$3Zd8F4VTJejR#_ZH$=%37(;VQP8l=RAL%$Kj#hoxykZJ+(AIILbBGH1Wzxsv z+PFBTve4ea3bjV$OCpbmY=D^3#^bez>*3Rl*1GzNq!uwM{>C4?=;Fq?l_=@kebq0C qdw(0tz71V-X2mIgA>(puh literal 0 HcmV?d00001 diff --git a/bin/main.py b/bin/main.py index 7d62a52..fd804d5 100644 --- a/bin/main.py +++ b/bin/main.py @@ -80,13 +80,11 @@ class Player(object): # Drawing rectangle def Rectangle(self): field_canvas.create_rectangle(self.current_x, self.current_y, self.current_x + self.step - 2, - self.current_y + self.step - 2, width=3, outline='red') + self.current_y + self.step - 2, width=3, outline='blue2') def DrawingLargeImage(): large_img_name = large_image_array[player.current_array_y][player.current_array_x] - # large_img_path = f"{large_directory}/{large_img_name}" - # large_img = PhotoImage(file=large_img_path) large_image_canvas.image = large_img_name large_image_canvas.create_image(0, 0, anchor=NW, image=large_img_name) @@ -106,22 +104,31 @@ class Field(object): def Fill(self): x = self.x_start y = self.y_start + row = 0 column = 0 + + # Drawing small images for i in range(self.columns): for j in range(self.rows): small_image_name = small_image_array[column][row] - # small_image_path = f"{small_directory}/{small_image_name}" - # small_img = PhotoImage(file=small_image_path) field_canvas.image = small_image_name field_canvas.create_image(x, y, anchor=NW, image=small_image_name) + x += self.image_size + self.x_start row += 1 y += self.image_size + self.y_start x = self.x_start column += 1 row = 0 + + # Drawing red/green rectangles + for el in state_of_cell_array: + if el[0] != 0: + field_canvas.create_rectangle(el[0], el[1], el[0] + player.step - 2, + el[1] + player.step - 2, width=3, outline=el[2]) + DrawingLargeImage() @@ -140,14 +147,39 @@ def ImagesInArray(directory, array): row += 1 +def CellDesignation(array, color): + for element in array: + if element[0] == 0: + element[0] = player.current_x + element[1] = player.current_y + element[2] = color + break + + +def Action(event): + global state_of_cell_array + + if event.keysym in ["Right", "Left", "Up", "Down"]: + player.Moving(event) + elif event.keysym in ["1", "2"]: + if event.keysym == "1": + CellDesignation(state_of_cell_array, "red") + else: + CellDesignation(state_of_cell_array, "green") + + def main(): # Creating the main window of an application window_size = f'{WINDOW_X}x{WINDOW_Y}' global window window = Tk() window.title("Sapper") + window.configure(bg='gray') window.geometry(window_size) + global state_of_cell_array + state_of_cell_array = [[0 for i in range(3)] for j in range(200)] + # Creating objects global player global field @@ -169,29 +201,25 @@ def main(): ImagesInArray(small_directory, small_image_array) # Creating the frames - main_frame = Frame(master, width=FRAME_WIDTH, height=FRAME_HEIGHT, bd=1) + main_frame = Frame(master, width=FRAME_WIDTH, height=FRAME_HEIGHT, bd=0) main_frame.pack(anchor=NW) # Creating the canvas global field_canvas - field_canvas = Canvas(main_frame, width=FRAME_WIDTH, height=FRAME_HEIGHT, bg='white') + field_canvas = Canvas(main_frame, width=FRAME_WIDTH, height=FRAME_HEIGHT, highlightthickness=0, bg='light gray') field_canvas.pack() # Creating the canvas for large image global large_image_canvas - large_image_canvas = Canvas(window, width=WINDOW_X - 533 - 20, height=900, bg='white') + large_image_canvas = Canvas(window, width=WINDOW_X - 533 - 20, height=900, highlightthickness=0, bg='gray') large_image_canvas.place(x=FRAME_WIDTH + 5, y=player.y_start) - # Loading image - global img - img = PhotoImage(file="../files/small_images/image.png") - # Filling window with images Field.Fill(field) # Drawing rectangle (player) Player.Rectangle(player) # Binding keyboard press to function - window.bind("", player.Moving) + window.bind("", Action) # Starting mainloop for window window.mainloop()