checkpoint
This commit is contained in:
@@ -2,6 +2,16 @@
|
||||
@using System.Text.Json;
|
||||
|
||||
<article class="game-board">
|
||||
<!-- Controls -->
|
||||
<header class="controls">
|
||||
<form @onsubmit:preventDefault>
|
||||
<fieldset class="history" disabled=@Yep>
|
||||
<legend>Replay</legend>
|
||||
<button disabled=@Yep><</button>
|
||||
<button>></button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</header>
|
||||
<!-- Game board -->
|
||||
<section class="board" data-perspective="@Perspective">
|
||||
@for (var rank = 1; rank < 10; rank++)
|
||||
@@ -17,7 +27,7 @@
|
||||
style="grid-area: @position">
|
||||
@if (piece != null)
|
||||
{
|
||||
<GamePiece Piece="piece" Perspective="Perspective" />
|
||||
<GamePiece Piece="piece.WhichPiece" RenderUpsideDown="@(piece.Owner != Perspective)" IsPromoted="piece.IsPromoted" />
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@@ -57,7 +67,7 @@
|
||||
@foreach (var piece in opponentHand)
|
||||
{
|
||||
<div class="tile">
|
||||
<GamePiece Piece="piece" Perspective="Perspective" />
|
||||
<GamePiece Piece="piece" RenderUpsideDown="true" />
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -86,12 +96,12 @@
|
||||
<div class="hand">
|
||||
@if (userHand.Any())
|
||||
{
|
||||
@foreach (var piece in userHand)
|
||||
@foreach (var whichPiece in userHand)
|
||||
{
|
||||
<div @onclick="OnClickHandInternal(piece)"
|
||||
<div @onclick="OnClickHandInternal(whichPiece)"
|
||||
class="tile"
|
||||
data-selected="@(piece.WhichPiece == SelectedPieceFromHand)">
|
||||
<GamePiece Piece="piece" Perspective="Perspective" />
|
||||
data-selected="@(whichPiece == SelectedPieceFromHand)">
|
||||
<GamePiece Piece="whichPiece" RenderUpsideDown="false" />
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -104,6 +114,7 @@
|
||||
</article>
|
||||
|
||||
@code {
|
||||
|
||||
static readonly string[] Files = new[] { "A", "B", "C", "D", "E", "F", "G", "H", "I" };
|
||||
|
||||
/// <summary>
|
||||
@@ -116,21 +127,26 @@
|
||||
[Parameter] public WhichPiece? SelectedPieceFromHand { get; set; }
|
||||
// TODO: Exchange these OnClick actions for events like "SelectionChangedEvent" and "MoveFromBoardEvent" and "MoveFromHandEvent".
|
||||
[Parameter] public EventCallback<string> OnClickTile { get; set; }
|
||||
[Parameter] public EventCallback<Piece> OnClickHand { get; set; }
|
||||
[Parameter] public EventCallback<WhichPiece> OnClickHand { get; set; }
|
||||
[Parameter] public EventCallback OnClickJoinGame { get; set; }
|
||||
[Parameter] public bool UseSideboard { get; set; } = true;
|
||||
[Parameter] public IList<BoardState> History { get; set; }
|
||||
|
||||
private IReadOnlyCollection<Piece> opponentHand;
|
||||
private IReadOnlyCollection<Piece> userHand;
|
||||
private bool Yep => History.Count == 0;
|
||||
|
||||
private IReadOnlyCollection<WhichPiece> opponentHand;
|
||||
private IReadOnlyCollection<WhichPiece> userHand;
|
||||
private string? userName;
|
||||
private string? opponentName;
|
||||
private int historyIndex;
|
||||
|
||||
public GameBoardPresentation()
|
||||
{
|
||||
opponentHand = Array.Empty<Piece>();
|
||||
userHand = Array.Empty<Piece>();
|
||||
opponentHand = [];
|
||||
userHand = [];
|
||||
userName = string.Empty;
|
||||
opponentName = string.Empty;
|
||||
History = [];
|
||||
}
|
||||
|
||||
protected override void OnParametersSet()
|
||||
@@ -138,8 +154,8 @@
|
||||
base.OnParametersSet();
|
||||
if (Session == null)
|
||||
{
|
||||
opponentHand = Array.Empty<Piece>();
|
||||
userHand = Array.Empty<Piece>();
|
||||
opponentHand = [];
|
||||
userHand = [];
|
||||
userName = string.Empty;
|
||||
opponentName = string.Empty;
|
||||
}
|
||||
@@ -158,17 +174,16 @@
|
||||
? this.Session.Player2 ?? "Empty Seat"
|
||||
: this.Session.Player1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Console.WriteLine("Count: {0}", History.Count);
|
||||
}
|
||||
|
||||
private bool IsMyTurn => Session?.BoardState.WhoseTurn == Perspective;
|
||||
|
||||
private bool IsPlayerInCheck => Session?.BoardState.PlayerInCheck == Perspective;
|
||||
|
||||
private bool IsOpponentInCheck => Session?.BoardState.PlayerInCheck != null && Session.BoardState.PlayerInCheck != Perspective;
|
||||
|
||||
private bool IsPlayerVictor => Session?.BoardState.Victor == Perspective;
|
||||
|
||||
|
||||
private bool IsOpponentVictor => Session?.BoardState.Victor != null && Session.BoardState.Victor != Perspective;
|
||||
|
||||
private Func<Task> OnClickTileInternal(string position) => () =>
|
||||
@@ -180,7 +195,7 @@
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
private Func<Task> OnClickHandInternal(Piece piece) => () =>
|
||||
private Func<Task> OnClickHandInternal(WhichPiece piece) => () =>
|
||||
{
|
||||
if (IsMyTurn)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
--ratio: 0.9;
|
||||
display: grid;
|
||||
grid-template-columns: min-content repeat(9, minmax(2rem, 4rem)) max-content;
|
||||
grid-template-rows: repeat(9, 1fr) auto;
|
||||
grid-template-rows: auto repeat(9, 1fr) auto;
|
||||
background-color: #444;
|
||||
gap: 3px;
|
||||
place-self: center;
|
||||
@@ -98,6 +98,15 @@
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.controls {
|
||||
grid-column: span 11;
|
||||
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.controls .history {
|
||||
|
||||
}
|
||||
|
||||
@media all and (max-width: 1000px) {
|
||||
.game-board {
|
||||
|
||||
@@ -136,17 +136,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
void OnClickHand(Piece piece)
|
||||
void OnClickHand(WhichPiece piece)
|
||||
{
|
||||
if (showPromotePrompt) return;
|
||||
|
||||
// Prevent selecting from both the hand and the board.
|
||||
selectedBoardPosition = null;
|
||||
|
||||
selectedPieceFromHand = piece.WhichPiece == selectedPieceFromHand
|
||||
selectedPieceFromHand = piece== selectedPieceFromHand
|
||||
// Deselecting the already-selected piece
|
||||
? selectedPieceFromHand = null
|
||||
: selectedPieceFromHand = piece.WhichPiece;
|
||||
: selectedPieceFromHand = piece;
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
@@ -1,32 +1,41 @@
|
||||
@using Shogi.Contracts.Types
|
||||
|
||||
<div class="game-piece" title="@HtmlTitle" data-upsidedown="@(Piece?.Owner != Perspective)" data-owner="@Piece?.Owner.ToString()">
|
||||
@switch (Piece?.WhichPiece)
|
||||
<div class="game-piece" title="@HtmlTitle" data-upsidedown="@RenderUpsideDown">
|
||||
@switch (Piece)
|
||||
{
|
||||
|
||||
case WhichPiece.Bishop:
|
||||
<Bishop IsPromoted="@IsPromoted" />
|
||||
break;
|
||||
|
||||
case WhichPiece.GoldGeneral:
|
||||
<GoldGeneral />
|
||||
break;
|
||||
|
||||
case WhichPiece.King:
|
||||
<ChallengingKing />
|
||||
break;
|
||||
|
||||
case WhichPiece.Knight:
|
||||
<Knight IsPromoted="@IsPromoted" />
|
||||
break;
|
||||
|
||||
case WhichPiece.Lance:
|
||||
<Lance IsPromoted="@IsPromoted" />
|
||||
break;
|
||||
|
||||
case WhichPiece.Pawn:
|
||||
<Pawn IsPromoted="@IsPromoted" />
|
||||
break;
|
||||
|
||||
case WhichPiece.Rook:
|
||||
<Rook IsPromoted="@IsPromoted" />
|
||||
break;
|
||||
|
||||
case WhichPiece.SilverGeneral:
|
||||
<SilverGeneral IsPromoted="@IsPromoted" />
|
||||
break;
|
||||
|
||||
default:
|
||||
@*render nothing*@
|
||||
break;
|
||||
@@ -34,15 +43,11 @@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public Contracts.Types.Piece? Piece { get; set; }
|
||||
[Parameter][EditorRequired] public WhichPiece? Piece { get; set; }
|
||||
[Parameter] public bool IsPromoted { get; set; } = false;
|
||||
[Parameter] public bool RenderUpsideDown { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public WhichPlayer Perspective { get; set; }
|
||||
|
||||
private bool IsPromoted => Piece != null && Piece.IsPromoted;
|
||||
|
||||
private string HtmlTitle => Piece?.WhichPiece switch
|
||||
private string HtmlTitle => this.Piece switch
|
||||
{
|
||||
WhichPiece.Bishop => "Bishop",
|
||||
WhichPiece.GoldGeneral => "Gold General",
|
||||
|
||||
Reference in New Issue
Block a user