From fcfc312c1402eb5d2ed8133fc1133f78ddecdd24 Mon Sep 17 00:00:00 2001 From: aa89227 Date: Sun, 13 Oct 2024 15:33:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=87=E9=AA=B0=E5=AD=90?= =?UTF-8?q?=E9=A1=AF=E7=A4=BA=E7=9A=84=E9=82=8F=E8=BC=AF=E6=90=AC=E9=80=B2?= =?UTF-8?q?=20DiceBox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/Gaming/Components/DiceBox.razor | 4 ++-- .../Pages/Gaming/Components/DiceBox.razor.cs | 19 ++++++++++--------- .../Pages/Gaming/GamingPage.razor | 2 +- .../Pages/Gaming/GamingPage.razor.cs | 17 +++-------------- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/DiceBox.razor b/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/DiceBox.razor index b352e74..230df40 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/DiceBox.razor +++ b/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/DiceBox.razor @@ -1,6 +1,6 @@  - @foreach (var Dice in GetShowDices()) + @foreach (var dice in Dices) { - @($ + @($ } \ No newline at end of file diff --git a/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/DiceBox.razor.cs b/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/DiceBox.razor.cs index 4586c37..7b131f4 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/DiceBox.razor.cs +++ b/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/DiceBox.razor.cs @@ -1,15 +1,16 @@ -using Microsoft.AspNetCore.Components; - -namespace Client.Pages.Gaming.Components; +namespace Client.Pages.Gaming.Components; public partial class DiceBox { - [CascadingParameter] public GamingPage Parent { get; set; } = default!; - - public List ShowDice => Parent.ShowDice; + private IEnumerable Dices { get; set; } = []; - public List GetShowDices() + public async Task ShowDices(IEnumerable dices) { - return ShowDice.TrueForAll(x => x > 0) ? ShowDice : []; + Console.WriteLine("ShowDices"); + Dices = dices; + StateHasChanged(); + await Task.Delay(3000); + Dices = []; + StateHasChanged(); } -} +} \ No newline at end of file diff --git a/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor b/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor index 9d88bb9..54bcab5 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor +++ b/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor @@ -12,6 +12,6 @@ - + \ No newline at end of file diff --git a/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor.cs b/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor.cs index e0eeee1..9d7a892 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor.cs +++ b/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor.cs @@ -1,5 +1,6 @@ using Client.Options; using Client.Pages.Enums; +using Client.Pages.Gaming.Components; using Client.Pages.Gaming.Entities; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.SignalR.Client; @@ -40,7 +41,7 @@ public partial class GamingPage private GamingHubConnection Connection { get; set; } = default!; public IEnumerable Players { get; set; } = []; - public List ShowDice { get; set; } = []; + private DiceBox DiceBox { get; set; } = default!; protected override void OnInitialized() { @@ -106,19 +107,7 @@ protected override async Task OnInitializedAsync() private async Task OnRolledDiceEvent(PlayerRolledDiceEventArgs e) { - // 顯示骰子點數 - ShowDice = [.. e.DicePoints]; - StateHasChanged(); - - await Task.Delay(3000); - - // TODO 角色移動 - - // 關閉骰子點數 - ShowDice = []; - StateHasChanged(); - - await Task.CompletedTask; + await DiceBox.ShowDices(e.DicePoints); } private async Task OnRolledDice()