This commit is contained in:
2022-11-14 20:01:06 -06:00
parent 716470f24d
commit 03c02cceae
2 changed files with 148 additions and 135 deletions

View File

@@ -4,28 +4,29 @@ namespace Shogi.Domain;
public class Session
{
public Session(
string name,
string player1Name)
{
Name = name;
Player1 = player1Name;
Board = new(BoardState.StandardStarting);
}
public Session(
string name,
string player1Name)
{
Name = name;
Player1 = player1Name;
Board = new(BoardState.StandardStarting);
}
public string Name { get; }
public ShogiBoard Board { get; }
public string Player1 { get; }
public string? Player2 { get; private set; }
public string Name { get; }
public ShogiBoard Board { get; }
public string Player1 { get; }
public string? Player2 { get; private set; }
public void AddPlayer2(string player2Name)
{
if (Player2 != null) throw new InvalidOperationException("Player 2 already exists while trying to add a second player.");
Player2 = player2Name;
}
public void AddPlayer2(string player2Name)
{
if (Player2 != null) throw new InvalidOperationException("Player 2 already exists while trying to add a second player.");
if (Player1.Equals(player2Name, StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException("Player 2 must be different from Player 1");
Player2 = player2Name;
}
public bool IsSeated(string playerName)
{
return Player1 == playerName || Player2 == playerName;
}
public bool IsSeated(string playerName)
{
return Player1 == playerName || Player2 == playerName;
}
}