From 485a0ebf13605b0a29454919807b2d8f0a474334 Mon Sep 17 00:00:00 2001 From: Andrzej Date: Fri, 2 Apr 2021 04:08:50 +0200 Subject: [PATCH] Small edit --- bin/Classess/Field.py | 65 ++++++------- bin/Classess/Player.py | 84 ++++++---------- bin/Classess/__pycache__/Field.cpython-37.pyc | Bin 2047 -> 2867 bytes .../__pycache__/Player.cpython-37.pyc | Bin 678 -> 1636 bytes bin/Main/main.py | 90 ++++-------------- 5 files changed, 76 insertions(+), 163 deletions(-) diff --git a/bin/Classess/Field.py b/bin/Classess/Field.py index fa3bb7c..f58bbb1 100644 --- a/bin/Classess/Field.py +++ b/bin/Classess/Field.py @@ -38,40 +38,33 @@ class Field(object): bg='gray') self.large_image_canvas.place(x=FRAME_WIDTH + 5, y=3) - # # Putting images - # 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 = 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) - # - # 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 self.state_of_cell_array: - # if el[0] != 0: - # self.small_field_canvas.create_rectangle(el[0], el[1], el[0] + step - 2, - # el[1] + step - 2, width=3, outline=el[2]) - # - # DrawingLargeImage() - # self.DrawingLargeImage() + # Clear Canvases + def Moving(self): + self.small_field_canvas.delete('all') + self.large_image_canvas.delete('all') - # def DrawingLargeImage(self): - # large_img_name = self.large_image_array[player.current_array_y][player.current_array_x] - # - # self.large_image_canvas.image = large_img_name - # self.large_image_canvas.create_image(0, 0, anchor=NW, image=large_img_name) + def PuttingSmallImages(self): + x = self.x_start + y = self.y_start + + row = 0 + column = 0 + + # Putting small images + for i in range(self.columns): + for j in range(self.rows): + 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) + + x += self.image_size + self.x_start + row += 1 + y += self.image_size + self.y_start + x = self.x_start + column += 1 + row = 0 + + def PuttingLargeImage(self, large_img_name): + self.large_image_canvas.image = large_img_name + self.large_image_canvas.create_image(0, 0, anchor=NW, image=large_img_name) diff --git a/bin/Classess/Player.py b/bin/Classess/Player.py index f5e6b85..e277d6c 100644 --- a/bin/Classess/Player.py +++ b/bin/Classess/Player.py @@ -19,60 +19,32 @@ class Player(object): self.current_array_x = 0 self.current_array_y = 0 - # def Moving(self, event): - # # Moving - # if event.keysym == "Right": - # if self.current_x + self.step < FRAME_WIDTH: - # self.current_x += self.step - # field.small_field_canvas.delete('all') - # field.large_image_canvas.delete('all') - # self.current_array_x += 1 - # field.Fill() - # self.Rectangle() - # elif self.current_y + self.step < FRAME_HEIGHT: - # self.current_x = self.x_start - # field.small_field_canvas.delete('all') - # field.large_image_canvas.delete('all') - # self.current_array_x = 0 - # self.current_array_y += 1 - # self.current_y += self.step - # field.Fill() - # self.Rectangle() - # elif event.keysym == "Left": - # if self.current_x - self.step >= self.x_start: - # self.current_x -= self.step - # field.small_field_canvas.delete('all') - # field.large_image_canvas.delete('all') - # self.current_array_x -= 1 - # field.Fill() - # self.Rectangle() - # elif self.current_y - self.step >= self.y_start: - # self.current_x = FRAME_WIDTH - self.step - # field.small_field_canvas.delete('all') - # field.large_image_canvas.delete('all') - # self.current_array_x = 9 - # self.current_array_y -= 1 - # self.current_y -= self.step - # field.Fill() - # self.Rectangle() - # elif event.keysym == "Up": - # if self.current_y - self.step >= self.y_start: - # self.current_y -= self.step - # field.small_field_canvas.delete('all') - # field.large_image_canvas.delete('all') - # self.current_array_y -= 1 - # field.Fill() - # self.Rectangle() - # elif event.keysym == "Down": - # if self.current_y + self.step < FRAME_HEIGHT: - # self.current_y += self.step - # field.small_field_canvas.delete('all') - # field.large_image_canvas.delete('all') - # self.current_array_y += 1 - # field.Fill() - # self.Rectangle() + def MovingRight(self): + if self.current_x + self.step < FRAME_WIDTH: + self.current_x += self.step + self.current_array_x += 1 + 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 - # # Drawing rectangle - # def Rectangle(self): - # field.small_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='blue2') + def MovingLeft(self): + if self.current_x - self.step >= self.x_start: + self.current_x -= self.step + self.current_array_x -= 1 + 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: + self.current_y -= self.step + self.current_array_y -= 1 + + def MovingDown(self): + if self.current_y + self.step < FRAME_HEIGHT: + self.current_y += self.step + self.current_array_y += 1 diff --git a/bin/Classess/__pycache__/Field.cpython-37.pyc b/bin/Classess/__pycache__/Field.cpython-37.pyc index b688a201993fdb335c3597de85465a2e4553c45a..b6a41b9fe41ef74198e8ee822e1858583b527ae4 100644 GIT binary patch delta 899 zcmZuv?`ji45Z}4o++F^9mC{%hO{rh5YLSX4e$-M>Gzcve0un>^3@MkyY_3|$9rr;$ z2?~-IP|ybupTif(8~7CZn@wz0T$ta??9S}Y{$_rj`L_zcI?aS6R zc#&w47A;4UcHW4V)KV*Gr3>1HE@)5t(5^1-im>$c`<|P3iLb$8Eg|>%~gcXTph(x5}E68LNZHG#y^3w4S76z*&p^cU{4f4P=$^w z`A$EI_2&HSq!vzPv9)}L!L?)rqzs?SBt#v(O&sjV*R(C3rdi==&-%*xJDH2KLaJ6p zDpy73r5=2@ZSlZQDRq)!>gn8hr|><#x&#q*aho3kbI@{pV_&5F2%nKXV~-=0jZj?7 zxUnxRDXM9h#n3U!P_sgR(CI}#>{i({uw~X5stlJI0+9pP*<>2cO~9c>_O1cLk}KLw zF{TKkNr_A`piI2Zd6?v1yjd1PWoOCS<`!x6K`|k&r7UezSDEq%{ uWG$u+pQxXHA^;DkVa?E+Uhy`{Tm0Z1hP%^;-de@ZBl&e-`76`0_x=}rGPZL7 delta 76 zcmdli_Me~6iI(^b diff --git a/bin/Classess/__pycache__/Player.cpython-37.pyc b/bin/Classess/__pycache__/Player.cpython-37.pyc index 580c7ef5a92af93ee8c7149fbbf211e5b2bb347a..ba2c398ca3ca2f9177367eb78095132d6b9a5345 100644 GIT binary patch literal 1636 zcma)+-A)rh6vt=3w;u@954iNwdVz$PNDMLZQK5-c0vNPuGA^A3TFSQ0E=mb^@&-PI zFW?*a5_{`aU%?ywpV{3~uo8E&XU?2GGv~~2&g{y>M4sXKdU5dKx5d~`8f1?N%V-t2E=`x zvB3h2P5P2OFeXu+Lh%_^XINbm`XxgI#6XWI!bWciN4V&1krR3Jjwm2fF}AllUf-8Z zEnSp)T6Yz1xCkM%3&s-(t<5mf(UaAPOtQ?7%@VM3TS-SStZmc=NS#SqvFygq84n{* zMzPaRm0a^wN0`AUa$s>rzTYI}LJ!uP6cyBo4VW|z#x#Jo|du5av0 zR4kK4h_WVW^NL&|Cds?7+5OZC4!2u}N6`Zq!YK%*O{L8RoIBciDaAA5Jf6@QCTE0Z zNz;!lxp2j3@fssFGJ+NOsa>lX7G^{d7_~JT-z25xjF3{}jFg;4{6P+)>|T*dAPfmf zTsJ05ByItdPxkuSKZqW}HRV!LTuQ2Fz-9Ux7xEpCg)Z)2SVl@`92Rx>dQEMqY^t+W z=bog0OXhBp`P<%O%9}RJG|GEe-5^UIHT+y~j|1<-=RD4He$o}E9ny=Oe?0X%$rnilEboz^dX_UJW=YVs9}!gk zlCCzP4CzMUZ;*5IXqK`go)PxL*xjqv*52&#cSG%cQax&WRBW-`-EaHNNKG3Fp(3hl V<}M}KzM!idQbbobHPsB$_ycn2Illk^ delta 112 zcmaFDvy7F`iIFs3lIFhnt@Fb6YevTQtN zz{u>U$uhZzRco>loABhjtXynNK;;~alfSYmNZ;ai3v%>zjSu&93Guka1L1hMdb)dr JOqOSJ1pv@08>;{S diff --git a/bin/Main/main.py b/bin/Main/main.py index 6919b92..6b62932 100644 --- a/bin/Main/main.py +++ b/bin/Main/main.py @@ -19,32 +19,13 @@ field = Field() # Putting images def Fill(): - x = field.x_start - y = field.y_start - - row = 0 - column = 0 - - # Drawing small images - for i in range(field.columns): - for j in range(field.rows): - small_image_name = field.small_image_array[column][row] - - field.small_field_canvas.image = small_image_name - field.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name) - - x += field.image_size + field.x_start - row += 1 - y += field.image_size + field.y_start - x = field.x_start - column += 1 - row = 0 + field.PuttingSmallImages() # Drawing red/green rectangles for el in field.state_of_cell_array: if el[0] != 0: field.small_field_canvas.create_rectangle(el[0], el[1], el[0] + player.step - 2, - el[1] + player.step - 2, width=3, outline=el[2]) + el[1] + player.step - 2, width=3, outline=el[2]) DrawingLargeImage() @@ -52,8 +33,7 @@ def Fill(): def DrawingLargeImage(): large_img_name = field.large_image_array[player.current_array_y][player.current_array_x] - field.large_image_canvas.image = large_img_name - field.large_image_canvas.create_image(0, 0, anchor=NW, image=large_img_name) + field.PuttingLargeImage(large_img_name) # Drawing rectangle @@ -65,55 +45,25 @@ def Rectangle(): def Moving(event): # Moving if event.keysym == "Right": - if player.current_x + player.step < FRAME_WIDTH: - player.current_x += player.step - field.small_field_canvas.delete('all') - field.large_image_canvas.delete('all') - player.current_array_x += 1 - Fill() - Rectangle() - elif player.current_y + player.step < FRAME_HEIGHT: - player.current_x = player.x_start - field.small_field_canvas.delete('all') - field.large_image_canvas.delete('all') - player.current_array_x = 0 - player.current_array_y += 1 - player.current_y += player.step - Fill() - Rectangle() + player.MovingRight() + field.Moving() + Fill() + Rectangle() elif event.keysym == "Left": - if player.current_x - player.step >= player.x_start: - player.current_x -= player.step - field.small_field_canvas.delete('all') - field.large_image_canvas.delete('all') - player.current_array_x -= 1 - Fill() - Rectangle() - elif player.current_y - player.step >= player.y_start: - player.current_x = FRAME_WIDTH - player.step - field.small_field_canvas.delete('all') - field.large_image_canvas.delete('all') - player.current_array_x = 9 - player.current_array_y -= 1 - player.current_y -= player.step - Fill() - Rectangle() + player.MovingLeft() + field.Moving() + Fill() + Rectangle() elif event.keysym == "Up": - if player.current_y - player.step >= player.y_start: - player.current_y -= player.step - field.small_field_canvas.delete('all') - field.large_image_canvas.delete('all') - player.current_array_y -= 1 - Fill() - Rectangle() + player.MovingUp() + field.Moving() + Fill() + Rectangle() elif event.keysym == "Down": - if player.current_y + player.step < FRAME_HEIGHT: - player.current_y += player.step - field.small_field_canvas.delete('all') - field.large_image_canvas.delete('all') - player.current_array_y += 1 - Fill() - Rectangle() + player.MovingDown() + field.Moving() + Fill() + Rectangle() def ImagesInArray(directory, array): @@ -156,8 +106,6 @@ def Action(event): def main(): # Creating the main window of an application win_size = f'{WINDOW_X}x{WINDOW_Y}' - # global win - # win = Tk() field.win.title("Sapper") field.win.configure(bg='gray') field.win.geometry(win_size)