From 214d7323978d32c8332226e62e20fa93c821cbd9 Mon Sep 17 00:00:00 2001 From: Andrzej Date: Fri, 30 Apr 2021 23:52:55 +0200 Subject: [PATCH] Add costs of cells --- bin/Classess/Field.py | 17 +++-- bin/Classess/Node.py | 2 +- bin/Classess/Player.py | 14 ++-- bin/Classess/__pycache__/Field.cpython-37.pyc | Bin 3223 -> 3313 bytes bin/Classess/__pycache__/Node.cpython-37.pyc | Bin 2736 -> 2709 bytes .../__pycache__/Player.cpython-37.pyc | Bin 1857 -> 1811 bytes bin/main/main.py | 70 +++++++++++++++--- resources/Globals.py | 23 ++++++ resources/__init__.py | 0 resources/__pycache__/Globals.cpython-37.pyc | Bin 0 -> 479 bytes resources/__pycache__/__init__.cpython-37.pyc | Bin 0 -> 126 bytes 11 files changed, 101 insertions(+), 25 deletions(-) create mode 100644 resources/Globals.py create mode 100644 resources/__init__.py create mode 100644 resources/__pycache__/Globals.cpython-37.pyc create mode 100644 resources/__pycache__/__init__.cpython-37.pyc diff --git a/bin/Classess/Field.py b/bin/Classess/Field.py index 124ad03..1e6bc98 100644 --- a/bin/Classess/Field.py +++ b/bin/Classess/Field.py @@ -1,13 +1,15 @@ from doctest import master from tkinter import * -WINDOW_X = 533 + 1200 -WINDOW_Y = 950 -FRAME_WIDTH = 533 -FRAME_HEIGHT = 533 +# WINDOW_X = 533 + 1200 +# WINDOW_Y = 950 +# FRAME_WIDTH = 533 +# FRAME_HEIGHT = 533 +# +# # Size of small image +# IMAGE_SIZE = 50 -# Size of small image -IMAGE_SIZE = 50 +from resources.Globals import * step = IMAGE_SIZE + 3 @@ -26,6 +28,7 @@ class Field(object): self.field_state_array = [[False for i in range(self.rows)] for j in range(self.columns)] 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)] + self.cell_expense = [0 for i in range(self.rows * self.columns)] # Modified by Artem to search in the status area self.canvas_small_images = [] @@ -34,7 +37,7 @@ class Field(object): 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, - bg='light gray') + bg='black') self.small_field_canvas.pack() self.large_image_canvas = Canvas(self.win, width=WINDOW_X - 533 - 20, height=900, highlightthickness=0, diff --git a/bin/Classess/Node.py b/bin/Classess/Node.py index adba2af..b592b51 100644 --- a/bin/Classess/Node.py +++ b/bin/Classess/Node.py @@ -1,4 +1,4 @@ -from bin.Classess.Player import FRAME_WIDTH, FRAME_HEIGHT +from resources.Globals import * class Node: diff --git a/bin/Classess/Player.py b/bin/Classess/Player.py index 00611fa..9c9ac5f 100644 --- a/bin/Classess/Player.py +++ b/bin/Classess/Player.py @@ -1,10 +1,12 @@ -WINDOW_X = 533 + 1200 -WINDOW_Y = 950 -FRAME_WIDTH = 533 -FRAME_HEIGHT = 533 +# WINDOW_X = 533 + 1200 +# WINDOW_Y = 950 +# FRAME_WIDTH = 533 +# FRAME_HEIGHT = 533 +# +# # Size of small image +# IMAGE_SIZE = 50 -# Size of small image -IMAGE_SIZE = 50 +from resources.Globals import * class Player(object): diff --git a/bin/Classess/__pycache__/Field.cpython-37.pyc b/bin/Classess/__pycache__/Field.cpython-37.pyc index 5a793515111e08d518d0d611adbfde4fd6681a53..da8182a637b5d0c3c531f2087aedbb3773a45cef 100644 GIT binary patch delta 593 zcmX|7O=}cE5bf&uYIkOmo&B1f-F3Z)VTG(o7SxDeS%n~CK+Hi0!kTOk;yRizGm7A0 zg+vIFJ**`}P*9JaJ$Td~AbJ%12RVB5X0-`vs8?05Ul*@>H~15{UDwSqI-j2H-2F9n zgNtXWkxW9&9zqD9Y990D{j4psNSB(=LSvChT^d_V8j-oFg_bmLv6eO7D2?9?U=B6d z9ZFl8TP!=W%?1XASz?=Tm13LqChjr9N$C*gGcPM-#jGS9>5g<_%A_t2Dw!`QMr0wY zs{TMRDf1(m)(eOWK2$!kgL}wo5~@sk6a|`8l%0KHorLv4BP+_1uRNDWTx~^eD@*sw zoUy$*T6s_XLZagge+yUeJ8wW8J$;@NbzD1%L&L^9+81n?3wTp+QMU1=@d}QT=rXRD zQ&c@S-a+%QZ&L5$5B(Y(!xv`T3XQdRwf_LWnqAUz3tgul#c?lsx)D7}BYbUrGYjM) zZDS}J92)pU+=f~FDOxb|`LC#feM(t8qhJb~xf)F4d@h0xzR&IWif-x2?4jhGs;04P zpNH!>v~T1)ia4#{f`Uu9;`q(PpxUEI1%Uw36q>01XO~(6J;yKp_L3-Ff1LEAw7nRw XudT)@E;w~CXut_aJ##?h1Q*&rZ>EFm delta 685 zcmX|9&ubGw6rS0g>`wMalcq^Gi4l5`$cCs@s8T3GOG}N?c&JdjAaR>n;>M&6ley@n zh%FQ}LYPAjUhLJYpvUS#@NdY$iw6mK@$AJnA#|4a@xE`rnR##D{wbO`Sw_y>*JBp4f`VEkl{-F-9RY*tOMjUgvPhPG6sg4$_#6G`~=Srf1Mt-&(qdL*#2mAkGa#U3Pf$DC&WU;E4xmQiDL!?~u+$&{o;+yz54kfmeUC+f;XGn# zh*>x(GxZh0S8QJr88+u3Mp$;BLDwFF7IO7Tm7G9fWA&MMLRPi+xG8^VC0vj$S=K;W z&?`V5=-+S=q!{p(;mLR8Sl-tinI}tf*SHF~E#DaKM0d#QM01EO{}@-CmsTfkJrfHp z9=?#CxrR$JFs1xwo*QYnwqKQBX-WR1kMW|sll1YmPhql%%hy#&w-uBDMn>4{Mf+^z zGZ6F%!**2X}|T9*C%}OV&AgLs`8_~g73-S_EuUAgfA&rQE*qDJ6@Z^ z&`=7ZPXQ>Vm#I$k6SeN!fyoYh8o`rCCmPlN0~@}bWB>pF diff --git a/bin/Classess/__pycache__/Node.cpython-37.pyc b/bin/Classess/__pycache__/Node.cpython-37.pyc index 47feab5c0513adda382f78024cdc05d772d03569..80a170ce7527d83be320e9231eca8c7851466a8c 100644 GIT binary patch delta 537 zcmZ{g!AiqG5QejxY??GpwTFUU>_w0i6a@uE5h~WE2R&#&DTub+pv9P!jXm|)9z9rA zAHthZ&-wy_XBS^UpTeCKu?hzAg@0!F|Cv1G@ACGRZKoCa+;^`}djosgU6q0=6a|W> zR1}J-+E=LB!!;z8Mu}8JDok~n>MJ#s8q}0ujiwJ2$NB&-2MJWG^2uR!+jB)`B;0bf;(9_2 z{Ls;u&fmzo^>eAk3;Hc83?KC)yfP&{95cCjx0Y-_S#a4h+$xm$)&~+G&&fKQ51neW0XY0qR2JUSXy$`!8pp~B&m+- z}H>GC>JZGay58C`R+p#>4AbSrwv}t^ijk?N*wU}m_tQO3ZBtCBEct`&C7g? z_mCT&$7rZgn^}!B+jC9CV5T9z$jS%`cxo{LCu4vl;NQlCpF*I&#-#U%zi}S2uoM6a zm;x9FXaESwM2=8&EZ3Bn61>Sv`e3klkR-P#+j}Ahcp<|JO)VO+Z=}LaQg62{m$FIl zimbD+Ewj3NVzE>(r`?PgerTum46oQWm2l$Nc5~}a-S;iu&+Rz%3yTdx^*cqm!IHtP ep+|~R!b^qfa?7LVjq%fs0w=kqIr!qD(M=_Ok05f4L{Qv*} delta 270 zcmbQtcaV?QiI= zQGc=qTcaP)Oa_qqig|zp2P2072P*^?fn@wN*>7=#d-}QfhsQ_2S&>DuK)E7C5Wx#1 lZn5PjWu+#U6fsSn$R)WG)LM7&5ak0|1U~JtqJF diff --git a/bin/main/main.py b/bin/main/main.py index 2999ef7..99d7aa1 100644 --- a/bin/main/main.py +++ b/bin/main/main.py @@ -7,18 +7,19 @@ from bin.Classess.Field import Field from bin.Classess.Mine import Mine from bin.Classess.Player import Player import bin.Classess.Node as nd +from resources.Globals import * -WINDOW_X = 533 + 1200 -WINDOW_Y = 950 -FRAME_WIDTH = 533 -FRAME_HEIGHT = 533 - -# Size of small image -IMAGE_SIZE = 50 - -AMOUNT_OF_MINES = 10 - -DELAY_TIME = 0.5 +# WINDOW_X = 533 + 1200 +# WINDOW_Y = 950 +# FRAME_WIDTH = 533 +# FRAME_HEIGHT = 533 +# +# # Size of small image +# IMAGE_SIZE = 50 +# +# AMOUNT_OF_MINES = 10 +# +# DELAY_TIME = 0.5 # Creating objects player = Player() @@ -183,6 +184,7 @@ def MouseClickEvent(event): end_position = [] # print("Pierwsza pozycja: {} {}".format(start_position[0], start_position[1])) + print(field.canvas_small_images) for i in range(0, len(field.canvas_small_images)): img_coords = field.small_field_canvas.coords(field.canvas_small_images[i]) @@ -303,6 +305,50 @@ def AutoMove(): field.win.update() +# Draws rectangles that indicate type of cells +def DrawRectangle(): + x = player.x_start + y = player.y_start + + color = None + + # Chose color for rectangle + for i in range(len(field.cell_expense)): + if field.cell_expense[i] == 10: + color = "None" + elif field.cell_expense[i] == 20: + color = "yellow" + elif field.cell_expense[i] == 30: + color = "dodger blue" + elif field.cell_expense[i] == 40: + color = "green4" + if color != "None": + field.small_field_canvas.create_rectangle(x, y, x + IMAGE_SIZE, y + IMAGE_SIZE, width=3, outline=color) + x += player.step + if i > 0 and i % 10 == 0: + x = player.x_start + y += player.step + + +def AddCostCellsToArray(amount, cost): + counter = 0 + while counter < amount: + r = random.randint(0, 99) + if field.cell_expense[r] == 0: + field.cell_expense[r] = cost + counter += 1 + + +def CostingOfCells(): + AddCostCellsToArray(amount_of_sand_cells, sand_cell_cost) + AddCostCellsToArray(amount_of_water_cells, water_cell_cost) + AddCostCellsToArray(amount_of_swamp_cells, swamp_cell_cost) + AddCostCellsToArray(field.rows * field.columns - (amount_of_sand_cells + amount_of_water_cells + amount_of_swamp_cells), standard_cell_cost) + + # Draw rectangles + DrawRectangle() + + def main(): # Creating the main window of an application win_size = f'{WINDOW_X}x{WINDOW_Y}' @@ -324,6 +370,8 @@ def main(): large_directory = "../../files/large_images" ImagesInArray(large_directory, field.large_image_array) + CostingOfCells() + # Add arrow image to Player class images = [] for file in os.listdir("../../files/arrow"): diff --git a/resources/Globals.py b/resources/Globals.py new file mode 100644 index 0000000..86dc1db --- /dev/null +++ b/resources/Globals.py @@ -0,0 +1,23 @@ +WINDOW_X = 533 + 1200 +WINDOW_Y = 950 +FRAME_WIDTH = 533 +FRAME_HEIGHT = 533 + +# Size of small image +IMAGE_SIZE = 50 + +AMOUNT_OF_MINES = 10 + +DELAY_TIME = 0.5 + + +standard_cell_cost = 10 + +amount_of_sand_cells = 10 +sand_cell_cost = 20 + +amount_of_water_cells = 10 +water_cell_cost = 30 + +amount_of_swamp_cells = 10 +swamp_cell_cost = 40 diff --git a/resources/__init__.py b/resources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/resources/__pycache__/Globals.cpython-37.pyc b/resources/__pycache__/Globals.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ad2a2f18733d051587bd738a47f26cc13fadb2a9 GIT binary patch literal 479 zcmZWm%TB^T6rDbRQeKIHjSH7XHZEKmqE;!;#1S824F29iZG%A7O03t zfJ7xMQyJ%I4(CA&0EOmp5mcoGTmmgq1y^WsfST&$BahJJT>@%|2rZA`#ASN(69DS# zbXf;k?xl19WHqZ?85&l*KP0!CX~avNYt7Wj&}iE|US64=ZghJ#R}E9^>SSPGo!2z8 ze`DFC-yx=9=>x8|^-FC;Y{S&~4oloAbz@4#p6`=!$P!+6gK#!YNccz?EVB*c)y=$0 zHMXg_n|SeGthP1(a%}Df(K@#^S?&$R>8msP+1HPqtHs5$8wU<^qsWV$*kj==9(&B` i`r(7?v%_e?l~xeaneUyX-@|r+WFc!w7NJuX*7ybSg`kf}HrC1Q7igM8E(ekl_Ht#VkM~g&~+hlhJP_LlH