the score system is now working

This commit is contained in:
Faraphel 2023-02-23 17:22:20 +01:00
parent 75d7c407c1
commit 9c8e0f87ce
2 changed files with 25 additions and 8 deletions

View file

@ -18,10 +18,6 @@ class Game(Scene):
def __init__(self, window: "Window", connection: socket.socket, **kwargs):
super().__init__(window, **kwargs)
self.my_turn = False
self.boat_ready_ally = False
self.boat_ready_enemy = False
self.connection = connection
self.batch_label = pyglet.graphics.Batch()
@ -116,7 +112,7 @@ class Game(Scene):
x=0.44, y=0.995,
text="7",
text="0",
font_size=25,
anchor_x="center", anchor_y="center",
@ -128,7 +124,7 @@ class Game(Scene):
x=0.56, y=0.995,
text="5",
text="0",
font_size=25,
anchor_x="center", anchor_y="center",
@ -198,6 +194,20 @@ class Game(Scene):
self.board_ally = core.Board(rows=8, columns=8)
self.board_enemy = core.Board(rows=8, columns=8)
self.my_turn: bool = False # is it the player turn ?
self.boat_ready_ally: bool = False # does the player finished placing his boat ?
self.boat_ready_enemy: bool = False # does the opponent finished placing his boat ?
self._boat_broken_ally: int = 0
self._boat_broken_enemy: int = 0
def boat_broken_ally(self):
self._boat_broken_ally += 1
self.score_ally.text = str(self._boat_broken_ally)
def boat_broken_enemy(self):
self._boat_broken_enemy += 1
self.score_enemy.text = str(self._boat_broken_enemy)
def on_draw(self):
self.background.draw()

View file

@ -46,8 +46,12 @@ def game_network(thread: "StoppableThread", window: "Window", connection: socket
packet.PacketBombState(position=data.position, bomb_state=bomb_state).send_connection(connection)
touched = bomb_state in [BombState.TOUCHED, BombState.SUNKEN, BombState.WON, BombState.ERROR]
game_scene.my_turn = not touched
touched = bomb_state in [BombState.TOUCHED, BombState.SUNKEN, BombState.WON]
if touched:
in_pyglet_context(game_scene.boat_broken_enemy)
game_scene.my_turn = not (touched or (bomb_state is BombState.ERROR))
case packet.PacketBombState:
print(data.bomb_state)
@ -58,4 +62,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
if touched:
in_pyglet_context(game_scene.boat_broken_ally)
in_pyglet_context(game_scene.grid_enemy.place_bomb, data.position, touched)