загружаю мейн с учетом проведенного урока 05022024
This commit is contained in:
parent
f20203bdd9
commit
3cb6dc31e1
|
@ -113,16 +113,19 @@ def keypress_handler(e):
|
||||||
global field_mode_right
|
global field_mode_right
|
||||||
|
|
||||||
if e.keysym.isnumeric():
|
if e.keysym.isnumeric():
|
||||||
|
number = int(e.keysym)
|
||||||
|
if 1 <= number <= 4:
|
||||||
if active_field == 0:
|
if active_field == 0:
|
||||||
ship_size_left = int(e.keysym)
|
ship_size_left = number
|
||||||
else:
|
else:
|
||||||
ship_size_right = int(e.keysym)
|
ship_size_right = number
|
||||||
else:
|
else:
|
||||||
if e.keysym == 'm':
|
if e.keysym == 'm':
|
||||||
if active_field == 0:
|
if active_field == 0:
|
||||||
field_mode = field_mode_left
|
field_mode = field_mode_left
|
||||||
else:
|
else:
|
||||||
field_mode = field_mode_right
|
field_mode = field_mode_right
|
||||||
|
|
||||||
if field_mode == 0:
|
if field_mode == 0:
|
||||||
field_mode = 1
|
field_mode = 1
|
||||||
else:
|
else:
|
||||||
|
@ -135,17 +138,25 @@ def keypress_handler(e):
|
||||||
|
|
||||||
|
|
||||||
def left_button_click(field, buttons, row, col):
|
def left_button_click(field, buttons, row, col):
|
||||||
|
global ship_size_left
|
||||||
|
global ship_direction_left
|
||||||
|
|
||||||
|
global ship_size_right
|
||||||
|
global ship_direction_right
|
||||||
|
|
||||||
if active_field == 0:
|
if active_field == 0:
|
||||||
field_mode = field_mode_left
|
field_mode = field_mode_left
|
||||||
|
ship_size = ship_size_left
|
||||||
|
ship_direction = ship_direction_left
|
||||||
else:
|
else:
|
||||||
field_mode = field_mode_right
|
field_mode = field_mode_right
|
||||||
|
ship_size = ship_size_right
|
||||||
|
ship_direction = ship_direction_right
|
||||||
|
|
||||||
if field_mode == 0:
|
if field_mode == 0:
|
||||||
if check_possible(field, row, col):
|
if check_possible(field, row, col, ship_size, ship_direction):
|
||||||
if active_field == 0:
|
set_ship(field, row, col, ship_size, ship_direction)
|
||||||
set_ship(field, row, col, ship_size_left, ship_direction_left)
|
|
||||||
else:
|
|
||||||
set_ship(field, row, col, ship_size_right, ship_direction_right)
|
|
||||||
elif field_mode == 1:
|
elif field_mode == 1:
|
||||||
shoot(field, row, col)
|
shoot(field, row, col)
|
||||||
colorize(field, buttons)
|
colorize(field, buttons)
|
||||||
|
@ -165,7 +176,6 @@ def right_button_click(d):
|
||||||
field_mode = field_mode_right
|
field_mode = field_mode_right
|
||||||
ship_direction = ship_direction_right
|
ship_direction = ship_direction_right
|
||||||
|
|
||||||
|
|
||||||
if field_mode == 0:
|
if field_mode == 0:
|
||||||
if ship_direction == 0:
|
if ship_direction == 0:
|
||||||
ship_direction = 1
|
ship_direction = 1
|
||||||
|
@ -177,6 +187,7 @@ def right_button_click(d):
|
||||||
else:
|
else:
|
||||||
ship_direction_right = ship_direction
|
ship_direction_right = ship_direction
|
||||||
|
|
||||||
|
|
||||||
def button_enter(field, buttons, row, col):
|
def button_enter(field, buttons, row, col):
|
||||||
global active_field
|
global active_field
|
||||||
global ship_direction_left
|
global ship_direction_left
|
||||||
|
@ -188,7 +199,6 @@ def button_enter(field, buttons, row, col):
|
||||||
global field_mode_left
|
global field_mode_left
|
||||||
global field_mode_right
|
global field_mode_right
|
||||||
|
|
||||||
|
|
||||||
if buttons == my_buttons:
|
if buttons == my_buttons:
|
||||||
active_field = 0
|
active_field = 0
|
||||||
elif buttons == enemy_buttons:
|
elif buttons == enemy_buttons:
|
||||||
|
@ -207,21 +217,17 @@ def button_enter(field, buttons, row, col):
|
||||||
other_field = my_field
|
other_field = my_field
|
||||||
other_buttons = my_buttons
|
other_buttons = my_buttons
|
||||||
|
|
||||||
|
|
||||||
for i in range(0, len(other_field)):
|
for i in range(0, len(other_field)):
|
||||||
if other_field[i] == "p":
|
if other_field[i] == "p":
|
||||||
other_field[i] = ''
|
other_field[i] = ''
|
||||||
|
|
||||||
colorize(other_field, other_buttons)
|
colorize(other_field, other_buttons)
|
||||||
|
|
||||||
|
|
||||||
if field_mode == 0:
|
if field_mode == 0:
|
||||||
for i in range(0, len(field)):
|
for i in range(0, len(field)):
|
||||||
if field[i] == "p":
|
if field[i] == "p":
|
||||||
field[i] = ''
|
field[i] = ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if check_possible(field, row, col,ship_size, ship_direction):
|
if check_possible(field, row, col,ship_size, ship_direction):
|
||||||
if ship_direction == 0:
|
if ship_direction == 0:
|
||||||
for r in range(row, row + ship_size):
|
for r in range(row, row + ship_size):
|
||||||
|
@ -271,7 +277,7 @@ def check_blocked(field, row, col):
|
||||||
|
|
||||||
window = Tk()
|
window = Tk()
|
||||||
window.title("Ship Craft!")
|
window.title("Ship Craft!")
|
||||||
window.geometry('900x410')
|
window.geometry('940x410')
|
||||||
window.bind_all('<KeyPress>', keypress_handler)
|
window.bind_all('<KeyPress>', keypress_handler)
|
||||||
set_ship(my_field, 1, 1, 4, 1)
|
set_ship(my_field, 1, 1, 4, 1)
|
||||||
set_ship(my_field,0, 6, 3, 0)
|
set_ship(my_field,0, 6, 3, 0)
|
||||||
|
|
Loading…
Reference in New Issue