Turn and Check markers.
This commit is contained in:
@@ -70,13 +70,13 @@
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<p class="text-center">Opponent Hand</p>
|
||||
<p class="text-center">Opponent's Hand</p>
|
||||
</div>
|
||||
|
||||
<div class="place-self-center">
|
||||
<PlayerName Name="@opponentName" IsTurn="!IsMyTurn" />
|
||||
<PlayerName Name="@opponentName" IsTurn="!IsMyTurn" InCheck="IsOpponentInCheck" />
|
||||
<hr />
|
||||
<PlayerName Name="@userName" IsTurn="IsMyTurn" />
|
||||
<PlayerName Name="@userName" IsTurn="IsMyTurn" InCheck="IsPlayerInCheck" />
|
||||
</div>
|
||||
|
||||
<div class="player-area">
|
||||
@@ -88,7 +88,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-center">Hand</p>
|
||||
<p class="text-center">Your Hand</p>
|
||||
<div class="hand">
|
||||
@if (userHand.Any())
|
||||
{
|
||||
@@ -124,7 +124,6 @@
|
||||
[Parameter] public EventCallback<string> OnClickTile { get; set; }
|
||||
[Parameter] public EventCallback<Piece> OnClickHand { get; set; }
|
||||
[Parameter] public EventCallback OnClickJoinGame { get; set; }
|
||||
[Parameter] public bool IsMyTurn { get; set; }
|
||||
[Parameter] public bool UseSideboard { get; set; } = true;
|
||||
|
||||
private IReadOnlyCollection<Piece> opponentHand;
|
||||
@@ -167,9 +166,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
private Func<Task> OnClickTileInternal(string position) => () => OnClickTile.InvokeAsync(position);
|
||||
private bool IsMyTurn => Session?.BoardState.WhoseTurn == Perspective;
|
||||
|
||||
private Func<Task> OnClickHandInternal(Piece piece) => () => OnClickHand.InvokeAsync(piece);
|
||||
private bool IsPlayerInCheck => Session?.BoardState.PlayerInCheck == Perspective;
|
||||
|
||||
private bool IsOpponentInCheck => Session?.BoardState.PlayerInCheck != null && Session.BoardState.PlayerInCheck != Perspective;
|
||||
|
||||
private Func<Task> OnClickTileInternal(string position) => () =>
|
||||
{
|
||||
if (IsMyTurn)
|
||||
{
|
||||
return OnClickTile.InvokeAsync(position);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
private Func<Task> OnClickHandInternal(Piece piece) => () =>
|
||||
{
|
||||
if (IsMyTurn)
|
||||
{
|
||||
return OnClickHand.InvokeAsync(piece);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
private Task OnClickJoinGameInternal() => OnClickJoinGame.InvokeAsync();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
<p style="margin: 0">
|
||||
@if (IsTurn)
|
||||
{
|
||||
<span>* </span>
|
||||
<span class="turn-marker" title="Shows which player is next to move a piece.">Turn</span>
|
||||
<span> </span>
|
||||
}
|
||||
|
||||
@if (InCheck)
|
||||
{
|
||||
<span class="check-marker" title="King is in danger!">Check</span>
|
||||
<span> </span>
|
||||
}
|
||||
|
||||
@if (string.IsNullOrEmpty(Name))
|
||||
@@ -17,5 +24,6 @@
|
||||
|
||||
@code {
|
||||
[Parameter][EditorRequired] public bool IsTurn { get; set; }
|
||||
[Parameter][EditorRequired] public bool InCheck { get; set; }
|
||||
[Parameter][EditorRequired] public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
17
Shogi.UI/Pages/Play/GameBoard/PlayerName.razor.css
Normal file
17
Shogi.UI/Pages/Play/GameBoard/PlayerName.razor.css
Normal file
@@ -0,0 +1,17 @@
|
||||
.turn-marker {
|
||||
display: inline-block;
|
||||
padding: 3px 8px;
|
||||
background-color: #444;
|
||||
color: beige;
|
||||
font-weight: bold;
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
.check-marker {
|
||||
display: inline-block;
|
||||
padding: 3px 8px;
|
||||
background-color: darkred;
|
||||
color: beige;
|
||||
font-weight: bold;
|
||||
font-size: 80%;
|
||||
}
|
||||
@@ -10,8 +10,7 @@
|
||||
OnClickHand="OnClickHand"
|
||||
OnClickTile="OnClickTile"
|
||||
SelectedPosition="@selectedBoardPosition"
|
||||
SelectedPieceFromHand="@selectedPieceFromHand"
|
||||
IsMyTurn="IsMyTurn" />
|
||||
SelectedPieceFromHand="@selectedPieceFromHand" />
|
||||
|
||||
@if (showPromotePrompt)
|
||||
{
|
||||
@@ -33,7 +32,6 @@
|
||||
public WhichPlayer Perspective { get; set; }
|
||||
[Parameter, EditorRequired]
|
||||
public Session Session { get; set; } = default!;
|
||||
private bool IsMyTurn => Session?.BoardState.WhoseTurn == Perspective;
|
||||
private string? selectedBoardPosition;
|
||||
private WhichPiece? selectedPieceFromHand;
|
||||
private bool showPromotePrompt;
|
||||
@@ -65,7 +63,7 @@
|
||||
|
||||
async Task OnClickTile(string position)
|
||||
{
|
||||
if (!IsMyTurn || showPromotePrompt) return;
|
||||
if (showPromotePrompt) return;
|
||||
|
||||
var pieceAtPosition = Session.BoardState.Board[position];
|
||||
if (selectedBoardPosition == position)
|
||||
@@ -133,7 +131,7 @@
|
||||
|
||||
void OnClickHand(Piece piece)
|
||||
{
|
||||
if (!IsMyTurn || showPromotePrompt) return;
|
||||
if (showPromotePrompt) return;
|
||||
|
||||
// Prevent selecting from both the hand and the board.
|
||||
selectedBoardPosition = null;
|
||||
|
||||
Reference in New Issue
Block a user