This commit is contained in:
2021-08-01 17:32:43 -05:00
parent 178cb00253
commit b10f61a489
76 changed files with 1655 additions and 1185 deletions

View File

@@ -1,7 +1,6 @@
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket
{
public class CreateGameRequest : IRequest
{
@@ -17,9 +16,9 @@ namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
public Game Game { get; set; }
public string PlayerName { get; set; }
public CreateGameResponse(ClientAction action)
public CreateGameResponse()
{
Action = action.ToString();
Action = ClientAction.CreateGame.ToString();
Error = string.Empty;
Game = new Game();
PlayerName = string.Empty;

View File

@@ -0,0 +1,9 @@
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket
{
public interface IRequest
{
ClientAction Action { get; }
}
}

View File

@@ -1,4 +1,4 @@
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket
{
public interface IResponse
{

View File

@@ -1,9 +0,0 @@
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces
{
public interface IRequest
{
ClientAction Action { get; }
}
}

View File

@@ -1,7 +1,6 @@
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket
{
public class JoinByCodeRequest : IRequest
{
@@ -17,17 +16,25 @@ namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
public class JoinGameResponse : IResponse
{
public string Action { get; }
public string Action { get; protected set; }
public string Error { get; set; }
public string GameName { get; set; }
public string PlayerName { get; set; }
public JoinGameResponse(ClientAction action)
public JoinGameResponse()
{
Action = action.ToString();
Action = ClientAction.JoinGame.ToString();
Error = "";
GameName = "";
PlayerName = "";
}
}
public class JoinByCodeResponse : JoinGameResponse, IResponse
{
public JoinByCodeResponse()
{
Action = ClientAction.JoinByCode.ToString();
}
}
}

View File

@@ -1,9 +1,8 @@
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket
{
public class ListGamesRequest : IRequest
{
@@ -16,9 +15,9 @@ namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
public string Error { get; set; }
public IReadOnlyList<Game> Games { get; set; }
public ListGamesResponse(ClientAction action)
public ListGamesResponse()
{
Action = action.ToString();
Action = ClientAction.ListGames.ToString();
Error = "";
Games = new Collection<Game>();
}

View File

@@ -1,8 +1,7 @@
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket
{
public class LoadGameRequest : IRequest
{
@@ -19,9 +18,9 @@ namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
public IList<Move> MoveHistory { get; set; }
public string Error { get; set; }
public LoadGameResponse(ClientAction action)
public LoadGameResponse()
{
Action = action.ToString();
Action = ClientAction.LoadGame.ToString();
}
}
}

View File

@@ -1,7 +1,6 @@
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket
{
public class MoveRequest : IRequest
{
@@ -15,16 +14,16 @@ namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
public string Action { get; }
public string Error { get; set; }
public string GameName { get; set; }
public BoardState BoardState { get; set; }
public string PlayerName { get; set; }
public Move Move { get; set; }
public MoveResponse(ClientAction action)
public MoveResponse()
{
Action = action.ToString();
Action = ClientAction.Move.ToString();
Error = string.Empty;
GameName = string.Empty;
BoardState = new BoardState();
PlayerName = string.Empty;
Move = new Move();
}
}
}

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types
{
public class BoardState
{
public Piece[,] Board { get; set; } = new Piece[0, 0];
public IReadOnlyCollection<Piece> Player1Hand { get; set; } = Array.Empty<Piece>();
public IReadOnlyCollection<Piece> Player2Hand { get; set; } = Array.Empty<Piece>();
public WhichPlayer? PlayerInCheck { get; set; }
public WhichPlayer WhoseTurn { get; set; }
}
}

View File

@@ -1,12 +0,0 @@
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types
{
public enum ClientAction
{
ListGames,
CreateGame,
JoinGame,
JoinByCode,
LoadGame,
Move
}
}

View File

@@ -1,33 +0,0 @@
using System.Collections.Generic;
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types
{
public class Game
{
public string Player1 { get; set; } = string.Empty;
public string? Player2 { get; set; } = string.Empty;
public string GameName { get; set; } = string.Empty;
/// <summary>
/// Players[0] is the session owner, Players[1] is the other person.
/// </summary>
public IReadOnlyList<string> Players
{
get
{
var list = new List<string>(2) { Player1 };
if (!string.IsNullOrEmpty(Player2)) list.Add(Player2);
return list;
}
}
public Game()
{
}
public Game(string gameName, string player1, string? player2 = null)
{
GameName = gameName;
Player1 = player1;
Player2 = player2;
}
}
}

View File

@@ -1,12 +0,0 @@
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.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; }
}
}

View File

@@ -1,9 +0,0 @@
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types
{
public class Piece
{
public bool IsPromoted { get; set; }
public WhichPiece WhichPiece { get; set; }
public WhichPlayer Owner { get; set; }
}
}

View File

@@ -1,14 +0,0 @@
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types
{
public enum WhichPiece
{
King,
GoldGeneral,
SilverGeneral,
Bishop,
Rook,
Knight,
Lance,
Pawn
}
}

View File

@@ -1,8 +0,0 @@
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types
{
public enum WhichPlayer
{
Player1,
Player2
}
}