diff --git a/PongGame/Hubs/PongGameState.cs b/PongGame/Hubs/PongGameState.cs index 8929926..ef1de6e 100644 --- a/PongGame/Hubs/PongGameState.cs +++ b/PongGame/Hubs/PongGameState.cs @@ -1,4 +1,6 @@ using System.Drawing; +using System.Reflection; +using MessagePack; namespace PongGame.Hubs; @@ -107,7 +109,7 @@ public struct PongGameState { } public struct PongPaddleState { - public const float PADDLE_LENGTH = HEIGHT / 10; + public const float PADDLE_LENGTH = HEIGHT / 6; public const float PADDLE_HALF_LENGTH = PADDLE_LENGTH / 2; public const float PADDLE_WIDTH = PADDLE_LENGTH / 5; public const float PADDLE_SPEED = 8; @@ -121,7 +123,17 @@ public struct PongGameState { public float Height; public PongPaddleDirection Direction; - public int Score; + [IgnoreMember] private int _score; + public int Score { + get => _score; set { + if (_score != value) { + _score = value; + _ = Task.Run(() => ScoreChanged.Invoke(this, value)); + } + } + } + + public event EventHandler ScoreChanged; public static void Update(ref PongPaddleState state) => state.Height = Math.Clamp(state.Height + ((int)state.Direction) * PADDLE_SPEED, PADDLE_HALF_LENGTH, HEIGHT - PADDLE_HALF_LENGTH);