checkpoint

This commit is contained in:
2024-11-16 12:37:56 -06:00
parent 13e79eb490
commit 460dfd608e
10 changed files with 139 additions and 49 deletions

View File

@@ -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>&lt;</button>
<button>&gt;</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)
{

View File

@@ -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 {

View File

@@ -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();
}