2021-04-02 03:39:46 +02:00
|
|
|
from doctest import master
|
|
|
|
from tkinter import *
|
|
|
|
|
2021-04-30 23:52:55 +02:00
|
|
|
# WINDOW_X = 533 + 1200
|
|
|
|
# WINDOW_Y = 950
|
|
|
|
# FRAME_WIDTH = 533
|
|
|
|
# FRAME_HEIGHT = 533
|
|
|
|
#
|
|
|
|
# # Size of small image
|
|
|
|
# IMAGE_SIZE = 50
|
2021-04-02 03:39:46 +02:00
|
|
|
|
2021-04-30 23:52:55 +02:00
|
|
|
from resources.Globals import *
|
2021-04-02 03:39:46 +02:00
|
|
|
|
|
|
|
step = IMAGE_SIZE + 3
|
|
|
|
|
|
|
|
|
|
|
|
class Field(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.win = Tk()
|
2021-05-01 01:27:41 +02:00
|
|
|
self.width = 555
|
|
|
|
self.height = 555
|
2021-04-02 03:39:46 +02:00
|
|
|
self.image_size = 50
|
|
|
|
self.rows = 10
|
|
|
|
self.columns = 10
|
2021-05-01 01:24:35 +02:00
|
|
|
self.x_start = 5
|
|
|
|
self.y_start = 5
|
2021-05-30 00:25:54 +02:00
|
|
|
# For red and green rectangles
|
|
|
|
# self.state_of_cell_array = [[0 for i in range(3)] for j in range(200)]
|
|
|
|
# Is on this position mine (True, False)
|
2021-04-16 23:04:03 +02:00
|
|
|
self.field_state_array = [[False for i in range(self.rows)] for j in range(self.columns)]
|
2021-04-02 03:39:46 +02:00
|
|
|
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)]
|
2021-04-30 23:52:55 +02:00
|
|
|
self.cell_expense = [0 for i in range(self.rows * self.columns)]
|
2021-05-30 00:25:54 +02:00
|
|
|
# Array rows * columns, if on [x][y] mine, object mine will be in the array in this position
|
|
|
|
self.state_of_cell_array = [["None" for _ in range(self.rows)] for __ in range(self.columns)]
|
|
|
|
# self.visited_mines = []
|
2021-04-02 03:39:46 +02:00
|
|
|
|
2021-04-24 17:32:07 +02:00
|
|
|
# Modified by Artem to search in the status area
|
|
|
|
self.canvas_small_images = []
|
|
|
|
self.rectangle = 0
|
|
|
|
|
2021-05-23 22:32:00 +02:00
|
|
|
self.mines_coord = []
|
|
|
|
|
2021-04-02 03:39:46 +02:00
|
|
|
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,
|
2021-04-30 23:52:55 +02:00
|
|
|
bg='black')
|
2021-04-16 23:04:03 +02:00
|
|
|
|
2021-04-02 03:39:46 +02:00
|
|
|
self.small_field_canvas.pack()
|
|
|
|
self.large_image_canvas = Canvas(self.win, width=WINDOW_X - 533 - 20, height=900, highlightthickness=0,
|
|
|
|
bg='gray')
|
|
|
|
self.large_image_canvas.place(x=FRAME_WIDTH + 5, y=3)
|
|
|
|
|
2021-05-30 00:25:54 +02:00
|
|
|
self.flag_img = PhotoImage(master=self.small_field_canvas, file="../../files/flag/FlagRed.png")
|
|
|
|
self.flag_green_img = PhotoImage(master=self.small_field_canvas, file="../../files/flag/FlagGreen.png")
|
|
|
|
self.flag_yellow_img = PhotoImage(master=self.small_field_canvas, file="../../files/flag/FlagYellow.png")
|
|
|
|
self.flag_red_img = PhotoImage(master=self.small_field_canvas, file="../../files/flag/FlagRed.png")
|
|
|
|
self.flag_bleu_img = PhotoImage(master=self.small_field_canvas, file="../../files/flag/FlagBlue.png")
|
2021-05-23 22:32:00 +02:00
|
|
|
|
2021-04-02 04:08:50 +02:00
|
|
|
# Clear Canvases
|
|
|
|
def Moving(self):
|
|
|
|
self.large_image_canvas.delete('all')
|
2021-04-02 03:39:46 +02:00
|
|
|
|
2021-04-02 04:08:50 +02:00
|
|
|
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):
|
2021-05-23 22:32:00 +02:00
|
|
|
|
2021-04-02 04:08:50 +02:00
|
|
|
small_image_name = self.small_image_array[column][row]
|
|
|
|
|
|
|
|
self.small_field_canvas.image = small_image_name
|
2021-04-24 17:32:07 +02:00
|
|
|
self.canvas_small_images.append(
|
|
|
|
self.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name))
|
|
|
|
# self.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name)
|
2021-04-02 04:08:50 +02:00
|
|
|
|
2021-05-23 22:32:00 +02:00
|
|
|
for k in range(0, len(self.mines_coord)):
|
|
|
|
if self.mines_coord[k][0] == i and self.mines_coord[k][1] == j:
|
|
|
|
new_mine_coord = self.small_field_canvas.coords(self.canvas_small_images[len(self.canvas_small_images) - 1])
|
|
|
|
self.mines_coord[k] = new_mine_coord
|
|
|
|
|
2021-04-02 04:08:50 +02:00
|
|
|
x += self.image_size + self.x_start
|
|
|
|
row += 1
|
|
|
|
y += self.image_size + self.y_start
|
|
|
|
x = self.x_start
|
|
|
|
column += 1
|
|
|
|
row = 0
|
2021-05-23 22:32:00 +02:00
|
|
|
# print(self.mines_coord)
|
2021-04-02 04:08:50 +02:00
|
|
|
|
|
|
|
def PuttingLargeImage(self, large_img_name):
|
|
|
|
self.large_image_canvas.image = large_img_name
|
2021-05-09 15:25:53 +02:00
|
|
|
self.large_image_canvas.create_image(0, 0, anchor=NW, image=large_img_name)
|