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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user