diff --git a/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml b/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml index 084bbb2..112d8aa 100644 --- a/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml +++ b/HNS/Excercises/ShipCraft/Переделка/.idea/workspace.xml @@ -5,7 +5,6 @@ - @@ -187,7 +186,7 @@ file://$PROJECT_DIR$/main.py - 147 + 155 diff --git a/HNS/Excercises/ShipCraft/Переделка/ShipField.py b/HNS/Excercises/ShipCraft/Переделка/ShipField.py index 9ef9241..e356a59 100644 --- a/HNS/Excercises/ShipCraft/Переделка/ShipField.py +++ b/HNS/Excercises/ShipCraft/Переделка/ShipField.py @@ -186,6 +186,9 @@ class ShipField: # в противном случае фолс return self.field[row * ShipField.field_size + col].strip() == "1" + def check_end(self): + return "1" not in self.field + def check_possible(self, row, col): # Функция должна возвращать True, если можно поставить сюда корабль, # в противном случае - False diff --git a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipField.cpython-311.pyc b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipField.cpython-311.pyc index a7bfd38..03935f7 100644 Binary files a/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipField.cpython-311.pyc and b/HNS/Excercises/ShipCraft/Переделка/__pycache__/ShipField.cpython-311.pyc differ diff --git a/HNS/Excercises/ShipCraft/Переделка/main.py b/HNS/Excercises/ShipCraft/Переделка/main.py index 75a19e6..bb835ab 100644 --- a/HNS/Excercises/ShipCraft/Переделка/main.py +++ b/HNS/Excercises/ShipCraft/Переделка/main.py @@ -10,7 +10,6 @@ from ShipField import ShipField from GameMode import GameMode from ShootResult import ShootResult -active_view = {} def create_view(window, enemy): @@ -65,22 +64,31 @@ def colorize(view): def keypress_handler(e): if e.keysym.isnumeric(): if my_view.active: - my_view.ship_field.set_ship_size(e.keysym) + my_view.ship_field.set_ship_size(int(e.keysym)) elif enemy_view.active: - enemy_view.ship_field.set_ship_size(e.keysym) + enemy_view.ship_field.set_ship_size(int(e.keysym)) def left_button_click(view, row, col): - if view.ship_field.action(row, col) and view_enemy and game_mode == GameMode.Battle: - enemy_shoot_result = ShootResult.UNDEFINED - while enemy_shoot_result != ShootResult.EMPTY: + action_result = view.ship_field.action(row, col) + + if action_result and view_enemy and game_mode == GameMode.Battle: + enemy_shoot_result = ShootResult.UNDEFINED + # Ход соперника + while enemy_shoot_result != ShootResult.EMPTY: my_row = random.randint(0, ShipField.field_size) my_col = random.randint(0, ShipField.field_size - 1) - enemy_shoot_result= my_view.ship_field.shoot(my_row, my_col) - + enemy_shoot_result = my_view.ship_field.shoot(my_row, my_col) + if game_mode == GameMode.BATTLE and my_view.ship_field.check_end(): + next_game_mode() + return + colorize(my_view) + if game_mode == GameMode.BATTLE and view.ship_field.check_end(): + next_game_mode() + return colorize(view)