yep
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
@using Shogi.Contracts.Types;
|
||||
@using Shogi.Contracts.Api
|
||||
@using Shogi.Contracts.Types;
|
||||
@using System.Text.RegularExpressions;
|
||||
@inject IShogiApi ShogiApi
|
||||
@inject AccountState Account;
|
||||
@inject PromotePrompt PromotePrompt;
|
||||
|
||||
<article class="game-board">
|
||||
<!-- Game board -->
|
||||
@@ -42,6 +45,15 @@
|
||||
<span>H</span>
|
||||
<span>I</span>
|
||||
</div>
|
||||
<!-- Promote prompt -->
|
||||
<div class="promote-prompt">
|
||||
<p>Do you wish to promote?</p>
|
||||
<div>
|
||||
<button type="button">Yes</button>
|
||||
<button type="button">No</button>
|
||||
<button type="button">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Side board -->
|
||||
@if (session != null)
|
||||
@@ -67,15 +79,15 @@
|
||||
}
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
}
|
||||
</article>
|
||||
|
||||
@code {
|
||||
static readonly string[] Files = new[] { "A", "B", "C", "D", "E", "F", "G", "H", "I" };
|
||||
|
||||
[Parameter]
|
||||
public string? SessionName { get; set; }
|
||||
|
||||
static readonly string[] Files = new[] { "A", "B", "C", "D", "E", "F", "G", "H", "I" };
|
||||
WhichPlayer Perspective => Account.User?.Id == session?.Player1
|
||||
? WhichPlayer.Player1
|
||||
: WhichPlayer.Player2;
|
||||
@@ -114,8 +126,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
void OnClickTile(Piece? piece, string position)
|
||||
bool ShouldPromptForPromotion(string position)
|
||||
{
|
||||
if (Perspective == WhichPlayer.Player1 && Regex.IsMatch(position, ".[7-9]"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (Perspective == WhichPlayer.Player2 && Regex.IsMatch(position, ".[1-3]"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
async void OnClickTile(Piece? piece, string position)
|
||||
{
|
||||
if (SessionName == null) return;
|
||||
|
||||
if (selectedPosition == null)
|
||||
{
|
||||
selectedPosition = position;
|
||||
@@ -128,12 +154,23 @@
|
||||
}
|
||||
else if (piece != null)
|
||||
{
|
||||
ShogiApi.PostMove(SessionName!, new Contracts.Api.MovePieceCommand
|
||||
if (ShouldPromptForPromotion(position) || ShouldPromptForPromotion(selectedPosition))
|
||||
{
|
||||
From = selectedPosition,
|
||||
To = position,
|
||||
IsP
|
||||
});
|
||||
PromotePrompt.Show(SessionName, new MovePieceCommand
|
||||
{
|
||||
From = selectedPosition,
|
||||
To = position
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await ShogiApi.PostMove(SessionName, new MovePieceCommand
|
||||
{
|
||||
From = selectedPosition,
|
||||
IsPromotion = false,
|
||||
To = position
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
void OnClickHand(Piece piece)
|
||||
|
||||
Reference in New Issue
Block a user