ajout d'un texte affichant l'état de la partie
This commit is contained in:
parent
c49971fe5a
commit
5dd5663ac6
4 changed files with 30 additions and 3 deletions
2
NOTE.md
2
NOTE.md
|
@ -1,6 +1,4 @@
|
||||||
A faire :
|
A faire :
|
||||||
- Ecran de victoire
|
|
||||||
- Etat de la partie (en attente de l'autre joueur, ...)
|
|
||||||
- Ecran de configuration de la partie
|
- Ecran de configuration de la partie
|
||||||
- Nom dans les options
|
- Nom dans les options
|
||||||
- Faire marcher le tchat
|
- Faire marcher le tchat
|
||||||
|
|
|
@ -58,6 +58,10 @@ class Game(Scene):
|
||||||
|
|
||||||
def board_ally_ready(widget):
|
def board_ally_ready(widget):
|
||||||
self.boat_ready_ally = True
|
self.boat_ready_ally = True
|
||||||
|
|
||||||
|
self.me_ready()
|
||||||
|
if self.boat_ready_enemy: self.refresh_turn_text()
|
||||||
|
|
||||||
PacketBoatPlaced().send_connection(connection)
|
PacketBoatPlaced().send_connection(connection)
|
||||||
|
|
||||||
self.grid_ally.add_listener("on_all_boats_placed", board_ally_ready)
|
self.grid_ally.add_listener("on_all_boats_placed", board_ally_ready)
|
||||||
|
@ -195,6 +199,19 @@ class Game(Scene):
|
||||||
label_batch=self.batch_label,
|
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_ally = core.Board(rows=8, columns=8)
|
||||||
self.board_enemy = 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._boat_broken_enemy += 1
|
||||||
self.score_enemy.text = str(self._boat_broken_enemy)
|
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):
|
def game_end(self, won: bool):
|
||||||
self.window.add_scene(Result, won=won)
|
self.window.add_scene(Result, won=won)
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,9 @@ class Result(Scene):
|
||||||
image=texture.Result.Style1.victory if won else texture.Result.Style1.defeat
|
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
|
from source.gui.scene import MainMenu
|
||||||
pyglet.clock.schedule_once(lambda dt: self.window.set_scene(MainMenu), 5.0)
|
pyglet.clock.schedule_once(lambda dt: self.window.set_scene(MainMenu), 5.0)
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,8 @@ def game_network(thread: "StoppableThread", window: "Window", connection: socket
|
||||||
|
|
||||||
case packet.PacketBoatPlaced:
|
case packet.PacketBoatPlaced:
|
||||||
game_scene.boat_ready_enemy = True
|
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:
|
case packet.PacketBombPlaced:
|
||||||
try:
|
try:
|
||||||
|
@ -55,6 +56,7 @@ def game_network(thread: "StoppableThread", window: "Window", connection: socket
|
||||||
in_pyglet_context(game_scene.boat_broken_enemy)
|
in_pyglet_context(game_scene.boat_broken_enemy)
|
||||||
|
|
||||||
game_scene.my_turn = not (touched or (bomb_state is BombState.ERROR))
|
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:
|
if bomb_state is BombState.WON:
|
||||||
in_pyglet_context(game_scene.game_end, won=False)
|
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]
|
touched = data.bomb_state in [BombState.TOUCHED, BombState.SUNKEN, BombState.WON]
|
||||||
game_scene.my_turn = touched
|
game_scene.my_turn = touched
|
||||||
|
in_pyglet_context(game_scene.refresh_turn_text)
|
||||||
|
|
||||||
if touched:
|
if touched:
|
||||||
in_pyglet_context(game_scene.boat_broken_ally)
|
in_pyglet_context(game_scene.boat_broken_ally)
|
||||||
|
|
Loading…
Reference in a new issue