ajout projet backend vide
All checks were successful
Main Build Process / Build & Test (pull_request) Successful in 1m39s
check main state / build (8.0.x) (push) Successful in 2m10s
Main Build Process / Build & Test (push) Successful in 1m28s

This commit was merged in pull request #8.
This commit is contained in:
2024-08-25 00:24:54 +02:00
parent b77185fdc8
commit 3cb1973fd1
11 changed files with 194 additions and 30 deletions

View File

@@ -20,7 +20,7 @@ public class Match
private Random _random = new Random();
private Dictionary<int, PlayerZone> _playersZones = new Dictionary<int, PlayerZone>();
private Dictionary<string, PlayerZone> _players = new();
/// <summary> LE numero du tour en cours (Partant de 1) </summary>
public int CurrentTurn { get; private set; } = 1;
@@ -33,31 +33,52 @@ public class Match
/// </summary>
/// <param name="nbPlayer"></param>
/// <param name="staticData">un objet permettant de récupérer les données statiques du jeu</param>
public Match(int nbPlayer, IStaticDataGetter staticData)
public Match(IStaticDataGetter staticData)
{
ArgumentNullException.ThrowIfNull(staticData);
ArgumentOutOfRangeException.ThrowIfLessThan(nbPlayer, _minPlayerCount);
ArgumentOutOfRangeException.ThrowIfGreaterThan(nbPlayer, _maxPlayerCount);
_board = staticData.GetBoard(1);
_buildings = staticData.GetBuildings();
_objectives = staticData.GetObjectives();
}
/// <summary> Ajouter un nouveau joueur a la partie </summary>
/// <param name="playerName">le nom du joueur</param>
public void AddPlayer(string playerName)
{
if (_players.Count < _maxPlayerCount)
{
if (_players.ContainsKey(playerName))
{
throw new MatchConfigException("Un joueur existe déjà avec ce nom");
}
_players.Add(playerName, new PlayerZone());
}
else
{
throw new MatchConfigException("Impossible d'ajouter de nouveau joueur, la partie est pleine");
}
}
/// <summary> Initialiser la partie, il faut avoir ajouté les joueurs au préalable </summary>
/// <exception cref="MatchConfigException"></exception>
public void Init()
{
int nbPlayer = _players.Count;
ArgumentOutOfRangeException.ThrowIfLessThan(nbPlayer, _minPlayerCount);
ArgumentOutOfRangeException.ThrowIfGreaterThan(nbPlayer, _maxPlayerCount);
List<int> freeObjectiveIndexs = Enumerable.Range(0, _objectives.Count).ToList();
for (int i = 0; i < nbPlayer; i++)
foreach (PlayerZone zone in _players.Values)
{
PlayerZone zone = new PlayerZone()
zone.AddObjectives(GetRandomObjectives(nbPlayer switch
{
Objectives = GetRandomObjectives(nbPlayer switch
{
2 => 4,
3 => 3,
4 => 2,
_ => throw new MatchConfigException("Mauvais nombre de joueurs lors des objectifs")
}, freeObjectiveIndexs)
};
2 => 4,
3 => 3,
4 => 2,
}, freeObjectiveIndexs));
zone.AddRessources(Enums.ResourceType.Piece, 3);
_playersZones.Add(i, zone);
}
_maxWorkerPerPlayer = nbPlayer switch
@@ -84,17 +105,18 @@ public class Match
if (index >= nbPlayer)
index = 0;
}
}
/// <summary> Permet de récuperer une player zone(une copie) </summary>
/// <param name="playerId"></param>
/// <param name="playerName">le nom ou ID du joueur</param>
/// <returns></returns>
public PlayerZone GetPlayerZone(int playerId)
public PlayerZone GetPlayerZone(string playerName)
{
ArgumentOutOfRangeException.ThrowIfLessThan(playerId, 0);
ArgumentOutOfRangeException.ThrowIfGreaterThan(playerId, _playersZones.Count - 1);
if (!_players.TryGetValue(playerName, out PlayerZone? value))
throw new ArgumentException("playerID is out of bound");
return _playersZones[playerId].Clone() as PlayerZone ?? throw new ArgumentException("playerID is out of bound");
return value.Clone() as PlayerZone ?? throw new ArgumentException("Cast exception in GetPlayerZone"); ;
}
private List<Objective> GetRandomObjectives(int number, List<int> freeIndex)

View File

@@ -6,7 +6,7 @@ namespace LittleTown.Core;
public class Objective
{
/// <summary> la description, une clé pour la traduction </summary>
public string Description { get; init; }
public required string Description { get; init; }
/// <summary> la condition de l'objectif sous forme de formule </summary>
public string Formula { get; init; } = string.Empty;

View File

@@ -7,8 +7,11 @@ public class PlayerZone : ICloneable
/// <summary> Les ressources que possede le joueur </summary>
public IDictionary<ResourceType, int> Ressources { get; init; } = new Dictionary<ResourceType, int>();
/// <summary> La liste des objectifs que le joueur possede/// </summary>
public IReadOnlyCollection<Objective> Objectives { get; init; } = new List<Objective>();
public IReadOnlyCollection<Objective> Objectives { get => _objectives.AsReadOnly(); init => _objectives = new List<Objective>(value); }
private List<Objective> _objectives = new List<Objective>();
/// <summary> Le marqueur de score pendant le match </summary>
public int ScoreMarker { get; init; }
@@ -29,6 +32,11 @@ public class PlayerZone : ICloneable
}
}
public void AddObjectives(ICollection<Objective> objectives)
{
_objectives.AddRange(objectives);
}
/// <summary> Cloner ce playerZone </summary>
/// <returns>Une copie de l'objet</returns>
public object Clone()