diff --git a/NOTE.md b/NOTE.md index bf62086..cdde04a 100644 --- a/NOTE.md +++ b/NOTE.md @@ -10,7 +10,6 @@ A faire : - Ecran de victoire - Affichage des coups de l'opposant -- Faire marcher le score - Faire marcher le tchat - Sauvegarde / Quitter diff --git a/assets/image/grid/boat/broken.png b/assets/image/grid/boat/broken.png deleted file mode 100644 index 41fcb17..0000000 Binary files a/assets/image/grid/boat/broken.png and /dev/null differ diff --git a/source/gui/scene/Game.py b/source/gui/scene/Game.py index 4aeb205..bc75f36 100644 --- a/source/gui/scene/Game.py +++ b/source/gui/scene/Game.py @@ -46,12 +46,14 @@ class Game(Scene): grid_style=texture.Grid.Style1, boat_style=texture.Grid.Boat.Style1, + bomb_style=texture.Grid.Bomb.Style1, rows=8, columns=8, background_batch=self.batch_grid_background, line_batch=self.batch_grid_line, cursor_batch=self.batch_grid_cursor, boat_batch=self.batch_grid_boat, + bomb_batch=self.batch_grid_bomb ) def board_ally_ready(): diff --git a/source/gui/texture/Grid.py b/source/gui/texture/Grid.py index 7ea380e..b064e10 100644 --- a/source/gui/texture/Grid.py +++ b/source/gui/texture/Grid.py @@ -14,7 +14,6 @@ class Grid: class Style1(Style): body = path_boat / "body.png" edge = path_boat / "edge.png" - broken = path_boat / "broken.png" solo = path_boat / "solo.png" class Bomb: diff --git a/source/gui/widget/grid/GameGridAlly.py b/source/gui/widget/grid/GameGridAlly.py index 03c8629..7b5fb3f 100644 --- a/source/gui/widget/grid/GameGridAlly.py +++ b/source/gui/widget/grid/GameGridAlly.py @@ -29,6 +29,7 @@ class GameGridAlly(GameGrid): grid_style: Type[Style], boat_style: Type[Style], + bomb_style: Type[Style], boats_length: list[int], preview_color: ColorRGB = (150, 255, 150), @@ -45,7 +46,9 @@ class GameGridAlly(GameGrid): self.orientation: Orientation = Orientation.HORIZONTAL self._boat_kwargs = dict_filter_prefix("boat_", kwargs) + self._bomb_kwargs = dict_filter_prefix("bomb_", kwargs) self.boat_style = boat_style + self.bomb_style = bomb_style self.add_listener("on_click_release", self.on_click_release) self.add_listener("on_hover", lambda rel_x, rel_y: self.preview_boat(self.get_cell_from_rel(rel_x, rel_y))) @@ -147,6 +150,15 @@ class GameGridAlly(GameGrid): except InvalidBoatPosition: self.display_board(self.board) # if the boat can't be placed, ignore else: self.display_board(preview_board, preview=True) + def place_bomb(self, cell: Point2D, touched: bool): + + self.cell_sprites[cell] = Sprite( + img=self.bomb_style.get("touched" if touched else "missed"), + **self._bomb_kwargs + ) + + self._refresh_size() + def on_click_release(self, rel_x: int, rel_y: int, button: int, modifiers: int): cell = self.get_cell_from_rel(rel_x, rel_y) diff --git a/source/network/game_network.py b/source/network/game_network.py index 79dbbd6..8035efb 100644 --- a/source/network/game_network.py +++ b/source/network/game_network.py @@ -48,6 +48,8 @@ def game_network(thread: "StoppableThread", window: "Window", connection: socket touched = bomb_state in [BombState.TOUCHED, BombState.SUNKEN, BombState.WON] + in_pyglet_context(game_scene.grid_ally.place_bomb, data.position, touched) + if touched: in_pyglet_context(game_scene.boat_broken_enemy)