started working on player moves.

This commit is contained in:
2022-11-09 18:50:51 -06:00
parent da76917490
commit f7f752b694
13 changed files with 232 additions and 271 deletions

View File

@@ -2,12 +2,9 @@
namespace Shogi.Contracts.Api;
public class CreateTokenResponse
{
public Guid OneTimeToken { get; }
public CreateTokenResponse(Guid token)
{
OneTimeToken = token;
}
}
public class CreateTokenResponse
{
public string UserId { get; set; }
public string DisplayName { get; set; }
public Guid OneTimeToken { get; set; }
}

View File

@@ -1,10 +1,46 @@
using Shogi.Contracts.Types;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
namespace Shogi.Contracts.Api;
public class MovePieceCommand
{
[Required]
public Move Move { get; set; }
}
public class MovePieceCommand : IValidatableObject
{
/// <summary>
/// Mutually exclusive with <see cref="From"/>.
/// Set this property to indicate moving a piece from the hand onto the board.
/// </summary>
public WhichPiece? PieceFromHand { get; set; }
/// <summary>
/// Board position notation, like A3 or G1
/// Mutually exclusive with <see cref="PieceFromHand"/>.
/// Set this property to indicate moving a piece from the board to another position on the board.
/// </summary>
public string? From { get; set; }
/// <summary>
/// Board position notation, like A3 or G1
/// </summary>
[Required]
public string To { get; set; }
public bool IsPromotion { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (PieceFromHand.HasValue && !string.IsNullOrWhiteSpace(From))
{
yield return new ValidationResult($"{nameof(PieceFromHand)} and {nameof(From)} are mutually exclusive properties.");
}
if (!Regex.IsMatch(To, "[A-I][1-9]"))
{
yield return new ValidationResult($"{nameof(To)} must be a valid board position, between A1 and I9");
}
if (!string.IsNullOrEmpty(From) && !Regex.IsMatch(From, "[A-I][1-9]"))
{
yield return new ValidationResult($"{nameof(From)} must be a valid board position, between A1 and I9");
}
}
}

View File

@@ -2,16 +2,16 @@
namespace Shogi.Contracts.Socket;
public class MoveResponse : ISocketResponse
public class PlayerHasMovedMessage : ISocketResponse
{
public SocketAction Action { get; }
public string SessionName { get; set; } = string.Empty;
public string SessionName { get; set; }
/// <summary>
/// The player that made the move.
/// </summary>
public string PlayerName { get; set; } = string.Empty;
public string PlayerName { get; set; }
public MoveResponse()
public PlayerHasMovedMessage()
{
Action = SocketAction.PieceMoved;
}

View File

@@ -1,12 +0,0 @@
namespace Shogi.Contracts.Types
{
public class Move
{
public WhichPiece? PieceFromCaptured { get; set; }
/// <summary>Board position notation, like A3 or G1</summary>
public string? From { get; set; }
/// <summary>Board position notation, like A3 or G1</summary>
public string To { get; set; } = string.Empty;
public bool IsPromotion { get; set; }
}
}