From 08f8d7df8af1fc57de43e715a1158a2b99e8bd4d Mon Sep 17 00:00:00 2001 From: ehermakov Date: Sun, 19 Nov 2023 22:44:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B6=D0=B0?= =?UTF-8?q?=D1=8E=20=D0=B4=D0=B7=20=D1=81=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=D0=BC=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B8=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HNS/Excercises/ShipCraft/main.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/HNS/Excercises/ShipCraft/main.py b/HNS/Excercises/ShipCraft/main.py index d51f3b3..005e6dd 100644 --- a/HNS/Excercises/ShipCraft/main.py +++ b/HNS/Excercises/ShipCraft/main.py @@ -1,6 +1,6 @@ from tkinter import * from enum import Enum - +import math buttons = [] @@ -140,18 +140,25 @@ def check_possible(field, row, col): def check_blocked(field, row, col): # Функция возвращает True, если все клетки вокруг клетки с координатами row, col # либо находятся за пределами поля, либо в них нет корабля/они пустые + index = row + col * 10 + if abs(row - field_size) > 1 or abs(col - field_size) > 1: + return True + elif index <= field_size**2 and field(index).strip == "": + return True # Во всех других случаях, функция возвращает False - pass + else: + return False window = Tk() window.title("Ship Craft!") window.geometry('450x410') -set_ship(1, 1, 4, 1) -set_ship(0, 6, 3, 0) -set_ship(9, 9, 1, 0) -set_ship(0, 0, 1, 0) -set_ship(9, 0, 1, 0) -set_ship(9, 2, 4, 1) -draw_field(window, my_field) -window.mainloop() +#set_ship(1, 1, 4, 1) +#set_ship(0, 6, 3, 0) +#set_ship(9, 9, 1, 0) +#set_ship(0, 0, 1, 0) +#set_ship(9, 0, 1, 0) +#set_ship(9, 2, 4, 1) +#draw_field(window, my_field) +#window.mainloop() +print(check_blocked(my_field, 10, 12))