forked from s452716/Test
Add costs of cells
This commit is contained in:
parent
a170012828
commit
214d732397
@ -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,
|
||||
|
@ -1,4 +1,4 @@
|
||||
from bin.Classess.Player import FRAME_WIDTH, FRAME_HEIGHT
|
||||
from resources.Globals import *
|
||||
|
||||
|
||||
class Node:
|
||||
|
@ -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):
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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"):
|
||||
|
23
resources/Globals.py
Normal file
23
resources/Globals.py
Normal file
@ -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
|
0
resources/__init__.py
Normal file
0
resources/__init__.py
Normal file
BIN
resources/__pycache__/Globals.cpython-37.pyc
Normal file
BIN
resources/__pycache__/Globals.cpython-37.pyc
Normal file
Binary file not shown.
BIN
resources/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
resources/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user