Ajout de la base de PrepareMatchCommand avec un test
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m26s
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m26s
This commit was merged in pull request #24.
This commit is contained in:
@@ -1,41 +1,58 @@
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Giants.Core.Enums;
|
||||
using Giants.Core.Exceptions;
|
||||
|
||||
namespace Giants.Core.Commands;
|
||||
|
||||
public class PrepareMatchCommand : BaseMatchCommand<PrepareMatchResult>
|
||||
{
|
||||
public required int NbPlayer { get; init; }
|
||||
public required IList<int> PlayerIDs { get; init; }
|
||||
|
||||
protected override PrepareMatchResult LocalMatchExecute(Match match)
|
||||
{
|
||||
if (NbPlayer < 3 || NbPlayer > 5)
|
||||
if (PlayerIDs.Count < 3 || PlayerIDs.Count > 5 || null == match)
|
||||
return new PrepareMatchResult();
|
||||
|
||||
|
||||
//Gestion des assets des joueurs
|
||||
for (int i = 0; i < NbPlayer; i++)
|
||||
for (int i = 0; i < PlayerIDs.Count; i++)
|
||||
{
|
||||
match.SetPlayer(i, PlayerIDs[i]);
|
||||
//marqueurs tribaux
|
||||
int nbMarker = NbMarkerPerPlayer(NbPlayer);
|
||||
for (int t = 0; t < nbMarker; t++)
|
||||
int nbMarker = NbMarkerPerPlayer(PlayerIDs.Count);
|
||||
for (int t = 0; t < Match.MaxTribalMarker; t++)
|
||||
{
|
||||
if (t < nbMarker)
|
||||
{
|
||||
match.AddTribalMarkerToPlayer(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
var piece = match.GetPlayerTribalTokenFromBox(i);
|
||||
match.AssignPiece(piece, PiecePosition.Urne);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return new PrepareMatchResult();
|
||||
return new PrepareMatchResult()
|
||||
{
|
||||
Success = true,
|
||||
Match = match
|
||||
};
|
||||
}
|
||||
|
||||
private int NbMarkerPerPlayer(int nbTotalPlayer)
|
||||
private static int NbMarkerPerPlayer(int nbTotalPlayer)
|
||||
{
|
||||
return nbTotalPlayer switch
|
||||
{
|
||||
3 => 7,
|
||||
4 => 6,
|
||||
5 => 5,
|
||||
_ => throw new Exception("Wrong player count for NbMarkerPerPlayer")
|
||||
_ => throw new DataConversionException("Wrong player count for NbMarkerPerPlayer")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class PrepareMatchResult : BaseCommandResult { }
|
||||
public class PrepareMatchResult : BaseCommandResult
|
||||
{
|
||||
public Match? Match { get; init; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user