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 5a79351..da8182a 100644 Binary files a/bin/Classess/__pycache__/Field.cpython-37.pyc and b/bin/Classess/__pycache__/Field.cpython-37.pyc differ diff --git a/bin/Classess/__pycache__/Node.cpython-37.pyc b/bin/Classess/__pycache__/Node.cpython-37.pyc index 47feab5..80a170c 100644 Binary files a/bin/Classess/__pycache__/Node.cpython-37.pyc and b/bin/Classess/__pycache__/Node.cpython-37.pyc differ diff --git a/bin/Classess/__pycache__/Player.cpython-37.pyc b/bin/Classess/__pycache__/Player.cpython-37.pyc index 01b51a7..033b057 100644 Binary files a/bin/Classess/__pycache__/Player.cpython-37.pyc and b/bin/Classess/__pycache__/Player.cpython-37.pyc differ 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 0000000..ad2a2f1 Binary files /dev/null and b/resources/__pycache__/Globals.cpython-37.pyc differ diff --git a/resources/__pycache__/__init__.cpython-37.pyc b/resources/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..15b69fe Binary files /dev/null and b/resources/__pycache__/__init__.cpython-37.pyc differ