загружаю задачу 1 из дз (что делали на уроке
This commit is contained in:
parent
f9e0d24478
commit
785392ed92
|
@ -42,7 +42,7 @@ def set_ship(row, col, size, direction):
|
||||||
return
|
return
|
||||||
for r in range(row, row + size):
|
for r in range(row, row + size):
|
||||||
index = r * field_size + col
|
index = r * field_size + col
|
||||||
my_field[index] = '1'
|
my_field[index] = "1"
|
||||||
if direction == 1:
|
if direction == 1:
|
||||||
if field_size - col < size:
|
if field_size - col < size:
|
||||||
return
|
return
|
||||||
|
@ -58,7 +58,7 @@ def shoot(field, row, col):
|
||||||
return ShootResult.UNDEFINED
|
return ShootResult.UNDEFINED
|
||||||
index = row * field_size + col
|
index = row * field_size + col
|
||||||
if (field[index]).strip() == "":
|
if (field[index]).strip() == "":
|
||||||
field[index] = '0'
|
field[index] = "0"
|
||||||
return ShootResult.EMPTY
|
return ShootResult.EMPTY
|
||||||
elif (field[index]).strip() == "1":
|
elif (field[index]).strip() == "1":
|
||||||
field[index] = "\\"
|
field[index] = "\\"
|
||||||
|
@ -72,22 +72,22 @@ def draw_field(window, field):
|
||||||
for c in range(0, field_size):
|
for c in range(0, field_size):
|
||||||
index = r * field_size + c
|
index = r * field_size + c
|
||||||
bg = 'white'
|
bg = 'white'
|
||||||
if field[index] == '1':
|
if field[index] == "1":
|
||||||
bg = 'pink'
|
bg = 'pink'
|
||||||
btn = Button(window, text='', bg=bg, width=5, height=2)
|
btn = Button(window, text='', bg=bg, width=5, height=2)
|
||||||
btn.grid(column=c, row=r)
|
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)
|
buttons.append(btn)
|
||||||
|
|
||||||
|
|
||||||
def colorize(field, buttons):
|
def colorize(field, buttons):
|
||||||
for i in range(len(field)):
|
for i in range(len(field)):
|
||||||
bg = "white"
|
bg = "white"
|
||||||
if field[i] == '1':
|
if field[i] == "1":
|
||||||
bg = 'pink'
|
bg = 'pink'
|
||||||
if field[i] == '\\':
|
if field[i] == "\\":
|
||||||
bg = 'red'
|
bg = 'red'
|
||||||
if field[i] == '0':
|
if field[i] == "0":
|
||||||
bg = 'black'
|
bg = 'black'
|
||||||
buttons[i].configure(bg=bg)
|
buttons[i].configure(bg=bg)
|
||||||
|
|
||||||
|
@ -107,5 +107,4 @@ set_ship(0, 0, 1, 0)
|
||||||
set_ship(9, 0, 1, 0)
|
set_ship(9, 0, 1, 0)
|
||||||
set_ship(9, 2, 4, 1)
|
set_ship(9, 2, 4, 1)
|
||||||
draw_field(window, my_field)
|
draw_field(window, my_field)
|
||||||
colorize(my_field, buttons)
|
|
||||||
window.mainloop()
|
window.mainloop()
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
[ViewState]
|
||||||
|
Mode=
|
||||||
|
Vid=
|
||||||
|
FolderType=Documents
|
Loading…
Reference in New Issue