Add mine's class and replacing mines on the field

This commit is contained in:
Andrzej 2021-04-16 23:04:03 +02:00
parent 485a0ebf13
commit 23f793a79f
38 changed files with 97 additions and 33 deletions

Binary file not shown.

View File

@ -1,23 +0,0 @@
# from bin.test_1 import fun as pl
#
# print(pl())
from bin.Main.main import ex
from bin.Main.main import t
print(ex.ret(t))
# class exmp:
# def __init__(self):
# self.width = 533
# self.height = 533
# self.image_size = 50
# self.rows = 10
# self.columns = 10
# self.x_start = 3
# self.y_start = 3
# self.state_of_cell_array = [[0 for i in range(3)] for j in range(200)]
# 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)]

View File

@ -1,9 +1,6 @@
from doctest import master
from tkinter import *
# from bin.main import PlayerReturn as player
# from bin.main import DrawingLargeImage
WINDOW_X = 533 + 1200
WINDOW_Y = 950
FRAME_WIDTH = 533
@ -26,6 +23,7 @@ class Field(object):
self.x_start = 3
self.y_start = 3
self.state_of_cell_array = [[0 for i in range(3)] for j in range(200)]
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)]
@ -33,6 +31,7 @@ class Field(object):
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')
self.small_field_canvas.pack()
self.large_image_canvas = Canvas(self.win, width=WINDOW_X - 533 - 20, height=900, highlightthickness=0,
bg='gray')

7
bin/classess/Mine.py Normal file
View File

@ -0,0 +1,7 @@
class Mine:
def __init__(self, x, y):
self.array_x = x
self.array_y = y
self.status = True
self.small_img = None
self.large_img = None

View File

@ -1,5 +1,3 @@
import sys
WINDOW_X = 533 + 1200
WINDOW_Y = 950
FRAME_WIDTH = 533

View File

@ -1,8 +1,10 @@
import random
from tkinter import *
import os
from bin.Classess.Player import Player
from bin.Classess.Field import Field
from bin.classess.Player import Player
from bin.classess.Field import Field
from bin.classess.Mine import Mine
WINDOW_X = 533 + 1200
WINDOW_Y = 950
@ -12,6 +14,8 @@ FRAME_HEIGHT = 533
# Size of small image
IMAGE_SIZE = 50
AMOUNT_OF_MINES = 10
# Creating objects
player = Player()
field = Field()
@ -77,7 +81,17 @@ def ImagesInArray(directory, array):
else:
image = PhotoImage(master=field.small_field_canvas, file=image_path)
is_done = False
while not is_done:
if array[row][column] == 0:
array[row][column] = image
is_done = True
else:
column += 1
if column == 10:
column = 0
row += 1
column += 1
if column == 10:
column = 0
@ -103,6 +117,67 @@ def Action(event):
CellDesignation(field.state_of_cell_array, "green")
def PutMines(mines_array):
counter = 0
while counter < AMOUNT_OF_MINES:
x = random.randint(0, 9)
y = random.randint(0, 9)
is_equal = False
for mine in mines_array:
if mine.array_x == x and mine.array_y == y:
is_equal = True
if not is_equal:
mine = Mine(x, y)
mines_array.append(mine)
field.field_state_array[x][y] = True
counter += 1
def MinesInArrays(mines_array, directory, imgs_array):
counter = 0
temp_array = []
if directory == "../../files/small_mines_images":
for file in os.listdir(directory):
if counter < AMOUNT_OF_MINES:
image_name = file
image_path = f"{directory}/{image_name}"
image = PhotoImage(master=field.small_field_canvas, file=image_path)
temp_array.append(image)
counter += 1
for i in range(AMOUNT_OF_MINES):
mines_array[i].small_img = temp_array[i]
# Add images in image array
imgs_array[mines_array[i].array_x][mines_array[i].array_y] = temp_array[i]
elif directory == "../../files/large_mines_images":
for file in os.listdir(directory):
if counter < AMOUNT_OF_MINES:
image_name = file
image_path = f"{directory}/{image_name}"
image = PhotoImage(master=field.large_image_canvas, file=image_path)
temp_array.append(image)
counter += 1
for i in range(AMOUNT_OF_MINES):
mines_array[i].large_img = temp_array[i]
# Add images in image array
imgs_array[mines_array[i].array_x][mines_array[i].array_y] = temp_array[i]
def main():
# Creating the main window of an application
win_size = f'{WINDOW_X}x{WINDOW_Y}'
@ -110,11 +185,19 @@ def main():
field.win.configure(bg='gray')
field.win.geometry(win_size)
# Create array with mines objects
mines_array = []
# Put mines on coordinates
PutMines(mines_array)
MinesInArrays(mines_array, "../../files/small_mines_images", field.small_image_array)
MinesInArrays(mines_array, "../../files/large_mines_images", field.large_image_array)
# Filling image arrays
large_directory = "../../files/large_images"
ImagesInArray(large_directory, field.large_image_array)
small_directory = "../../files/small_images"
ImagesInArray(small_directory, field.small_image_array)
large_directory = "../../files/large_images"
ImagesInArray(large_directory, field.large_image_array)
# Filling window with images
Fill()

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

Before

Width:  |  Height:  |  Size: 238 KiB

After

Width:  |  Height:  |  Size: 238 KiB

View File

Before

Width:  |  Height:  |  Size: 198 KiB

After

Width:  |  Height:  |  Size: 198 KiB

View File

Before

Width:  |  Height:  |  Size: 361 KiB

After

Width:  |  Height:  |  Size: 361 KiB

View File

Before

Width:  |  Height:  |  Size: 240 KiB

After

Width:  |  Height:  |  Size: 240 KiB

View File

Before

Width:  |  Height:  |  Size: 699 KiB

After

Width:  |  Height:  |  Size: 699 KiB

View File

Before

Width:  |  Height:  |  Size: 321 KiB

After

Width:  |  Height:  |  Size: 321 KiB

View File

Before

Width:  |  Height:  |  Size: 226 KiB

After

Width:  |  Height:  |  Size: 226 KiB

View File

Before

Width:  |  Height:  |  Size: 189 KiB

After

Width:  |  Height:  |  Size: 189 KiB

View File

Before

Width:  |  Height:  |  Size: 189 KiB

After

Width:  |  Height:  |  Size: 189 KiB

View File

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 97 KiB

View File

Before

Width:  |  Height:  |  Size: 313 KiB

After

Width:  |  Height:  |  Size: 313 KiB

View File

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB