This commit is contained in:
danii 2023-11-27 19:33:48 +01:00
parent ade5101030
commit 26f2cee30f
1 changed files with 27 additions and 21 deletions

View File

@ -2,7 +2,8 @@ from tkinter import *
from enum import Enum from enum import Enum
field_size = 10 field_size = 10
ship_size = [] ship_size = 4
ship_direction = 1
buttons = [] buttons = []
@ -99,15 +100,17 @@ def check_possible(field, row, col):
if ship_direction == 0: if ship_direction == 0:
if field_size - row >= ship_size: if field_size - row >= ship_size:
for r in range(col, col + ship_size): for r in range(row, row + ship_size + 1):
if check_blocked(field, row, col): if not check_blocked(field, r, col):
return True return False
return True
if ship_direction == 1: if ship_direction == 1:
if field_size - col >= ship_size: if field_size - col >= ship_size:
for c in range(row, row + ship_size): for c in range(col, col + ship_size + 1):
if check_blocked(field, row, col): if not check_blocked(field, row, c):
return True return False
return True
return False return False
@ -146,20 +149,23 @@ colorize(my_field, buttons)
#window.mainloop() #window.mainloop()
# for r in range(0, field_size): for r in range(0, field_size):
# blocked_string = '' blocked_string = ''
# ship_string = '' ship_string = ''
# for c in range(0, field_size): for c in range(0, field_size):
# blocked_string += str(check_blocked(my_field, r, c))[0] + ', ' blocked_string += str(check_blocked(my_field, r, c))[0] + ', '
# ship_string += my_field[r * field_size + c] + ', ' ship_string += my_field[r * field_size + c] + ', '
# print(blocked_string[:-2] + ' ' + ship_string[:-2]) print(blocked_string[:-2] + ' ' + ship_string[:-2])
# for r in range(0, field_size): print("#########################################################################")
# blocked_string = ''
# ship_string = ''
# for c in range(0, field_size):
# blocked_string += str(check_possible(my_field, r, c))[0] + ', '
# ship_string += my_field[r * field_size + c] + ', '
# print(blocked_string[:-2] + ' ' + ship_string[:-2])
for r in range(0, field_size):
possible_string = ''
impossible_string = ''
for c in range(0, field_size):
possible_string += str(check_possible(my_field, r, c))[0] + ', '
impossible_string += my_field[r * field_size + c] + ', '
print(possible_string[:-2] + ' ' + impossible_string[:-2])