change methode change_ship_size

This commit is contained in:
danii 2023-12-11 20:01:56 +01:00
parent 8ff9815604
commit 5f87177e78
1 changed files with 4 additions and 6 deletions

View File

@ -83,8 +83,6 @@ def draw_field(window, field):
btn.bind('<Button-1>', lambda e, x=r, y=c: left_button_click(field, x, y)) btn.bind('<Button-1>', lambda e, x=r, y=c: left_button_click(field, x, y))
btn.bind('<Button-3>', lambda e, x=r, y=c: right_button_click(field, x, y)) btn.bind('<Button-3>', lambda e, x=r, y=c: right_button_click(field, x, y))
btn.bind('<Enter>', lambda e, x=r, y=c: button_enter(field, x, y)) btn.bind('<Enter>', lambda e, x=r, y=c: button_enter(field, x, y))
for i in range(1, 5):
window.bind(str(i), lambda size=i: change_ship_size(size))
buttons.append(btn) buttons.append(btn)
@ -177,16 +175,16 @@ def button_enter(field, row, col):
colorize(field, buttons) colorize(field, buttons)
def change_ship_size(new_size): def keypress_handler(e):
global ship_size global ship_size
if 1 <= new_size <= 4: ship_size = int(e.keysym)
ship_size = new_size return ship_size
window = Tk() window = Tk()
window.title("Ship Craft!") window.title("Ship Craft!")
window.geometry('450x410') window.geometry('450x410')
window.bind_all('<KeyPress>', keypress_handler)
set_ship(1, 1, 4, 1) set_ship(1, 1, 4, 1)
set_ship(0, 6, 3, 0) set_ship(0, 6, 3, 0)