yep
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
bool ShouldPromptForPromotion(string position)
|
||||
bool IsWithinPromoteArea(string position)
|
||||
{
|
||||
if (Perspective == WhichPlayer.Player1 && Regex.IsMatch(position, ".[7-9]"))
|
||||
{
|
||||
@@ -63,11 +63,11 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
async Task OnClickTile(Piece? pieceAtPosition, string position)
|
||||
async Task OnClickTile(string position)
|
||||
{
|
||||
if (!IsMyTurn) return;
|
||||
|
||||
if (!IsMyTurn || showPromotePrompt) return;
|
||||
|
||||
var pieceAtPosition = Session.BoardState.Board[position];
|
||||
if (selectedBoardPosition == position)
|
||||
{
|
||||
// Deselect the selected position.
|
||||
@@ -105,12 +105,13 @@
|
||||
|
||||
if (selectedBoardPosition != null)
|
||||
{
|
||||
Console.WriteLine("pieceAtPosition is null? {0}", pieceAtPosition == null);
|
||||
|
||||
if (pieceAtPosition == null || pieceAtPosition?.Owner != Perspective)
|
||||
{
|
||||
var pieceBeingMoved = Session.BoardState.Board[selectedBoardPosition];
|
||||
var isPromotedAlready = pieceBeingMoved != null && pieceBeingMoved.IsPromoted;
|
||||
Console.WriteLine("Is promoted? {0}", isPromotedAlready);
|
||||
// Moving to an empty space or capturing an opponent's piece.
|
||||
if (ShouldPromptForPromotion(position) || ShouldPromptForPromotion(selectedBoardPosition))
|
||||
if (!isPromotedAlready && (IsWithinPromoteArea(position) || IsWithinPromoteArea(selectedBoardPosition)))
|
||||
{
|
||||
Console.WriteLine("Prompt!");
|
||||
moveTo = position;
|
||||
@@ -118,11 +119,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Console.WriteLine("OnClick to move to {0}", position);
|
||||
var success = await ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedBoardPosition, position, false));
|
||||
|
||||
Console.WriteLine("Success? {0}", success);
|
||||
if (!success)
|
||||
{
|
||||
selectedBoardPosition = null;
|
||||
@@ -134,9 +131,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
async Task OnClickHand(Piece piece)
|
||||
void OnClickHand(Piece piece)
|
||||
{
|
||||
if (!IsMyTurn) return;
|
||||
if (!IsMyTurn || showPromotePrompt) return;
|
||||
|
||||
// Prevent selecting from both the hand and the board.
|
||||
selectedBoardPosition = null;
|
||||
@@ -149,11 +146,13 @@
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private Task OnClickPromotionChoice(bool shouldPromote)
|
||||
private async Task OnClickPromotionChoice(bool shouldPromote)
|
||||
{
|
||||
if (selectedBoardPosition == null && selectedPieceFromHand.HasValue && moveTo != null)
|
||||
if (selectedBoardPosition != null && moveTo != null)
|
||||
{
|
||||
return ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedPieceFromHand.Value, moveTo));
|
||||
await ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedBoardPosition, moveTo, shouldPromote));
|
||||
showPromotePrompt = false;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Unexpected scenario during OnClickPromotionChoice.");
|
||||
|
||||
Reference in New Issue
Block a user