ajout d'un texte affichant l'état de la partie

This commit is contained in:
Faraphel 2023-02-24 11:46:28 +01:00
parent c49971fe5a
commit 5dd5663ac6
4 changed files with 30 additions and 3 deletions

View file

@ -1,6 +1,4 @@
A faire :
- Ecran de victoire
- Etat de la partie (en attente de l'autre joueur, ...)
- Ecran de configuration de la partie
- Nom dans les options
- Faire marcher le tchat

View file

@ -58,6 +58,10 @@ class Game(Scene):
def board_ally_ready(widget):
self.boat_ready_ally = True
self.me_ready()
if self.boat_ready_enemy: self.refresh_turn_text()
PacketBoatPlaced().send_connection(connection)
self.grid_ally.add_listener("on_all_boats_placed", board_ally_ready)
@ -195,6 +199,19 @@ class Game(Scene):
label_batch=self.batch_label,
)
self.label_state = self.add_widget(
widget.Text,
x=0.5, y=0.15,
anchor_x="center",
text="Placer vos bateaux",
font_size=20,
batch=self.batch_label
)
self.board_ally = core.Board(rows=8, columns=8)
self.board_enemy = core.Board(rows=8, columns=8)
@ -212,6 +229,12 @@ class Game(Scene):
self._boat_broken_enemy += 1
self.score_enemy.text = str(self._boat_broken_enemy)
def me_ready(self):
self.label_state.text = "L'adversaire place ses bateaux"
def refresh_turn_text(self):
self.label_state.text = "Placer vos bombes" if self.my_turn else "L'adversaire place ses bombes"
def game_end(self, won: bool):
self.window.add_scene(Result, won=won)

View file

@ -20,6 +20,9 @@ class Result(Scene):
image=texture.Result.Style1.victory if won else texture.Result.Style1.defeat
)
# TODO: rendre l'image transparente
# TODO: empecher les intéractions
from source.gui.scene import MainMenu
pyglet.clock.schedule_once(lambda dt: self.window.set_scene(MainMenu), 5.0)

View file

@ -36,7 +36,8 @@ def game_network(thread: "StoppableThread", window: "Window", connection: socket
case packet.PacketBoatPlaced:
game_scene.boat_ready_enemy = True
print("adversaire à posé ses bateaux")
if game_scene.boat_ready_ally:
in_pyglet_context(game_scene.refresh_turn_text)
case packet.PacketBombPlaced:
try:
@ -55,6 +56,7 @@ def game_network(thread: "StoppableThread", window: "Window", connection: socket
in_pyglet_context(game_scene.boat_broken_enemy)
game_scene.my_turn = not (touched or (bomb_state is BombState.ERROR))
in_pyglet_context(game_scene.refresh_turn_text)
if bomb_state is BombState.WON:
in_pyglet_context(game_scene.game_end, won=False)
@ -68,6 +70,7 @@ def game_network(thread: "StoppableThread", window: "Window", connection: socket
touched = data.bomb_state in [BombState.TOUCHED, BombState.SUNKEN, BombState.WON]
game_scene.my_turn = touched
in_pyglet_context(game_scene.refresh_turn_text)
if touched:
in_pyglet_context(game_scene.boat_broken_ally)