загружаю задачу 1 из дз (что делали на уроке

This commit is contained in:
ehermakov 2023-11-16 21:41:24 +03:00
parent f9e0d24478
commit 785392ed92
2 changed files with 11 additions and 8 deletions

View File

@ -42,7 +42,7 @@ def set_ship(row, col, size, direction):
return
for r in range(row, row + size):
index = r * field_size + col
my_field[index] = '1'
my_field[index] = "1"
if direction == 1:
if field_size - col < size:
return
@ -58,7 +58,7 @@ def shoot(field, row, col):
return ShootResult.UNDEFINED
index = row * field_size + col
if (field[index]).strip() == "":
field[index] = '0'
field[index] = "0"
return ShootResult.EMPTY
elif (field[index]).strip() == "1":
field[index] = "\\"
@ -72,22 +72,22 @@ def draw_field(window, field):
for c in range(0, field_size):
index = r * field_size + c
bg = 'white'
if field[index] == '1':
if field[index] == "1":
bg = 'pink'
btn = Button(window, text='', bg=bg, width=5, height=2)
btn.grid(column=c, row=r)
btn.bind('<Button-1>', lambda e, x=r, y=c: shoot(field, x, y))
btn.bind('<Button-1>', lambda e, x=r, y=c: button_click(field, x, y))
buttons.append(btn)
def colorize(field, buttons):
for i in range(len(field)):
bg = "white"
if field[i] == '1':
if field[i] == "1":
bg = 'pink'
if field[i] == '\\':
if field[i] == "\\":
bg = 'red'
if field[i] == '0':
if field[i] == "0":
bg = 'black'
buttons[i].configure(bg=bg)
@ -107,5 +107,4 @@ set_ship(0, 0, 1, 0)
set_ship(9, 0, 1, 0)
set_ship(9, 2, 4, 1)
draw_field(window, my_field)
colorize(my_field, buttons)
window.mainloop()

4
desktop.ini Normal file
View File

@ -0,0 +1,4 @@
[ViewState]
Mode=
Vid=
FolderType=Documents