@using Shogi.Contracts.Types; @using System.Text.Json;
Replay
@for (var rank = 1; rank < 10; rank++) { foreach (var file in Files) { var position = $"{file}{rank}"; var piece = Session?.BoardState.Board[position]; var isSelected = piece != null && SelectedPosition == position;
@if (piece != null) { }
} }
9 8 7 6 5 4 3 2 1
A B C D E F G H I
@if (Session != null && UseSideboard == true) { }
@code { static readonly string[] Files = new[] { "A", "B", "C", "D", "E", "F", "G", "H", "I" }; /// /// When true, an icon is displayed indicating that the user is spectating. /// [Parameter] public bool IsSpectating { get; set; } = false; [Parameter] public WhichPlayer Perspective { get; set; } [Parameter] public Session? Session { get; set; } [Parameter] public string? SelectedPosition { get; set; } [Parameter] public WhichPiece? SelectedPieceFromHand { get; set; } // TODO: Exchange these OnClick actions for events like "SelectionChangedEvent" and "MoveFromBoardEvent" and "MoveFromHandEvent". [Parameter] public EventCallback OnClickTile { get; set; } [Parameter] public EventCallback OnClickHand { get; set; } [Parameter] public EventCallback OnClickJoinGame { get; set; } [Parameter] public bool UseSideboard { get; set; } = true; [Parameter] public IList History { get; set; } private bool Yep => History.Count == 0; private IReadOnlyCollection opponentHand; private IReadOnlyCollection userHand; private string? userName; private string? opponentName; private int historyIndex; public GameBoardPresentation() { opponentHand = []; userHand = []; userName = string.Empty; opponentName = string.Empty; History = []; } protected override void OnParametersSet() { base.OnParametersSet(); if (Session == null) { opponentHand = []; userHand = []; userName = string.Empty; opponentName = string.Empty; } else { opponentHand = Perspective == WhichPlayer.Player1 ? this.Session.BoardState.Player2Hand : this.Session.BoardState.Player1Hand; userHand = Perspective == WhichPlayer.Player1 ? this.Session.BoardState.Player1Hand : this.Session.BoardState.Player2Hand; userName = Perspective == WhichPlayer.Player1 ? this.Session.Player1 : this.Session.Player2 ?? "Empty Seat"; opponentName = Perspective == WhichPlayer.Player1 ? 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 OnClickTileInternal(string position) => () => { if (IsMyTurn) { return OnClickTile.InvokeAsync(position); } return Task.CompletedTask; }; private Func OnClickHandInternal(WhichPiece piece) => () => { if (IsMyTurn) { return OnClickHand.InvokeAsync(piece); } return Task.CompletedTask; }; private Task OnClickJoinGameInternal() => OnClickJoinGame.InvokeAsync(); }