Skip to content

Commit

Permalink
fix: 解決 rebase 後產生的問題
Browse files Browse the repository at this point in the history
  • Loading branch information
aa89227 committed Nov 10, 2024
1 parent 04fb9d0 commit 9806e1b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
@using Client.Pages.Gaming.Entities
@code {
[CascadingParameter]
public GamingPage Parent { get; set; } = default!;
private Player player => Parent?.Players.FirstOrDefault();
}
<dlv class="PlayerInfo">
<dlv class="PlayerInfo">
<div class="money">
<span>@player.Money</span>
<span>@Player.Money</span>
</div>
<div class="TotalMoney">
<span>@player.GetTotalMoney</span>
<span>@Player.GetTotalMoney</span>
</div>
<hr class="withBalls">
<div class="collapseBtn">
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ChatBox></ChatBox>

<Settings></Settings>
<PlayerInfo></PlayerInfo>
<PlayerInfo Player="_activePlayer"/>
@if (IsYourTurn)
{
<Go OnRolledDice="OnRolledDice"/>
Expand Down
59 changes: 9 additions & 50 deletions Clients/Monopoly.Clients.Web/Pages/Gaming/GamingPage.razor.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -49,55 +48,16 @@ public partial class GamingPage
private GamingHubConnection Connection { get; set; } = default!;
public IEnumerable<Player> 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()
Expand All @@ -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<LocationEnum>(p.Color).ToColorEnum(),
Role = Enum.Parse<RoleEnum>(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)
Expand All @@ -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<Map.Direction>(e.Direction);
Expand All @@ -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;
Expand Down

0 comments on commit 9806e1b

Please sign in to comment.