diff --git a/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/PlayerInfo.razor b/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/PlayerInfo.razor index c1cd989..e7441b3 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/PlayerInfo.razor +++ b/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/PlayerInfo.razor @@ -1,15 +1,9 @@ -@using Client.Pages.Gaming.Entities -@code { - [CascadingParameter] - public GamingPage Parent { get; set; } = default!; - private Player player => Parent?.Players.FirstOrDefault(); -} - +
- @player.Money + @Player.Money
- @player.GetTotalMoney + @Player.GetTotalMoney

diff --git a/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/PlayerInfo.razor.cs b/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/PlayerInfo.razor.cs index 67aeebc..23424a1 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/PlayerInfo.razor.cs +++ b/Clients/Monopoly.Clients.Web/Pages/Gaming/Components/PlayerInfo.razor.cs @@ -1,5 +1,9 @@ -namespace Client.Pages.Gaming.Components; +using Client.Pages.Gaming.Entities; +using Microsoft.AspNetCore.Components; + +namespace Client.Pages.Gaming.Components; public partial class PlayerInfo { + [EditorRequired][Parameter] public required Player Player { get; set; } } diff --git a/Clients/Monopoly.Clients.Web/Pages/Gaming/Entities/Player.cs b/Clients/Monopoly.Clients.Web/Pages/Gaming/Entities/Player.cs index a0ed1eb..75af1cc 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Gaming/Entities/Player.cs +++ b/Clients/Monopoly.Clients.Web/Pages/Gaming/Entities/Player.cs @@ -16,6 +16,7 @@ public class Player public GamingStatusEnum Status { get; set; } = GamingStatusEnum.None; public int GetTotalMoney => Money + LandContracts.Sum(x => x.Money + x.HouseMoney); + public int Order { get; set; } public Player() { diff --git a/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor b/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor index ac56dc0..3207686 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor +++ b/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor @@ -12,7 +12,7 @@ - + @if (IsYourTurn) { diff --git a/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor.cs b/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor.cs index c263f10..393752f 100644 --- a/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor.cs +++ b/Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor.cs @@ -1,5 +1,4 @@ using Client.Options; -using Client.Pages.Enums; using Client.Pages.Extensions; using Client.Pages.Gaming.Components; using Client.Pages.Gaming.Entities; @@ -49,55 +48,16 @@ public partial class GamingPage private GamingHubConnection Connection { get; set; } = default!; public IEnumerable Players { get; set; } = []; private string CurrentPlayerId { get; set; } = string.Empty; + + private Player _activePlayer = new(); - private string ActivePlayerId { get; set; } = string.Empty; - - private bool IsYourTurn => CurrentPlayerId == ActivePlayerId; + private bool IsYourTurn => CurrentPlayerId == _activePlayer.Id; private DiceBox DiceBox { get; set; } = default!; - protected override void OnInitialized() - { - Map = new Map("1", Blocks); - } - protected override async Task OnInitializedAsync() { - //玩家假資料 - Players = - [ - new Player - { - Name = "Player1", - Money = 1000, - Color = ColorEnum.Red, - Role = RoleEnum.Baby, - - IsHost = true - }, - new Player - { - Name = "Player2", - Money = 1000, - Color = ColorEnum.Blue, - Role = RoleEnum.Dai, - }, - new Player - { - Name = "Player3", - Money = 1000, - Color = ColorEnum.Green, - Role = RoleEnum.Mei, - }, - new Player - { - Name = "Player4", - Money = 1000, - Color = ColorEnum.Yellow, - Role = RoleEnum.OldMan, - } - ]; - + Map = new Map("1", Blocks); var baseUri = new Uri(BackendApiOptions.Value.BaseUrl); var url = new Uri(baseUri, $"/monopoly?gameid={GameId}"); var client = new HubConnectionBuilder() @@ -115,17 +75,18 @@ protected override async Task OnInitializedAsync() var monopolyInfos = await Connection.GetMonopolyInfos(); - Players = monopolyInfos.Players.Select(p => new Player + Players = monopolyInfos.Players.Select((p, index) => new Player { Id = p.Id, Name = p.Name, Money = 1000, Color = Enum.Parse(p.Color).ToColorEnum(), Role = Enum.Parse(p.Role), + Order = index + 1 }); CurrentPlayerId = monopolyInfos.CurrentPlayerId; - ActivePlayerId = monopolyInfos.WhoAmI; + _activePlayer = Players.First(x => x.Id == monopolyInfos.WhoAmI); } private async Task OnRolledDiceEvent(PlayerRolledDiceEventArgs e) @@ -140,8 +101,7 @@ private async Task OnRolledDice() private Task ChessMovedEvent(ChessMovedEventArgs e) { - //var player = Players.First(x => x.Id == e.PlayerId); - var player = Players.First(x => x.Order == 1); + var player = Players.First(x => x.Id == e.PlayerId); player.Chess.Move(); player.Chess.CurrentDirection = Enum.Parse(e.Direction); @@ -154,8 +114,7 @@ private Task ChessMovedEvent(ChessMovedEventArgs e) private Task ChooseDirectionEvent(PlayerNeedToChooseDirectionEventArgs e) { - //var player = Players.First(x => x.Id == e.PlayerId); - var player = Players.First(x => x.Order == 1); + var player = Players.First(x => x.Id == e.PlayerId); StateHasChanged(); return Task.CompletedTask;