fin de l'ajout de données au match
All checks were successful
dotnet package / build (8.0.x) (push) Successful in 1m53s

This commit is contained in:
2024-06-05 23:16:22 +02:00
parent cf7b311656
commit 33e5186159
8 changed files with 158 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ root = true
[*.cs]
dotnet_diagnostic.IDE1006.severity = warning
dotnet_diagnostic.IDE0005.severity = error
dotnet_diagnostic.CA5394.severity = none
# Exclude generated code
[src/**/Migrations/*.cs]

View File

@@ -10,6 +10,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">

View File

@@ -1,3 +1,4 @@
using LittleTown.Core.Enums;
using LittleTown.StaticDataAcces;
namespace LittleTown.Core.Tests;
@@ -20,8 +21,17 @@ public class MatchTesting
}
[Fact]
public void CheckBoardBoundaries()
public void TwoPlayerInitMatchTest()
{
StaticDataGetter getter = new();
Match match = new Match(2, getter);
PlayerZone player1 = match.GetPlayerZone(0);
PlayerZone player1_3 = match.GetPlayerZone(0);
Assert.Equal(3, player1.Ressources[Enums.ResourceType.Piece]);
player1.AddRessources(ResourceType.Piece, 1);
Assert.Equal(3, player1_3.Ressources[Enums.ResourceType.Piece]);
Assert.Equal(4, player1.Objectives.Count);
}
}

View File

@@ -25,6 +25,9 @@ public class Match
/// <summary> LE numero du tour en cours (Partant de 1) </summary>
public int CurrentTurn { get; private set; } = 1;
/// <summary>la liste indiquant l'ordre des joueurs, _playerTurnsOrder[0] donne l'index du 1er joueur, _playerTurnsOrder[1] du second..... </summary>
private List<int> _playerTurnsOrder = new List<int>();
/// <summary>
/// Constructeur d'une nouvelle partie avec un nombre de joueurs données en parametres
/// </summary>
@@ -72,6 +75,26 @@ public class Match
4 => 6,
_ => throw new MatchConfigException("Mauvais nombre de joueurs lors building")
};
// preparer l'ordre des joueurs
int index = _random.Next(nbPlayer);
for (int i = 0; i < nbPlayer; ++i)
{
_playerTurnsOrder.Add(index++);
if (index >= nbPlayer)
index = 0;
}
}
/// <summary> Permet de récuperer une player zone(une copie) </summary>
/// <param name="playerId"></param>
/// <returns></returns>
public PlayerZone GetPlayerZone(int playerId)
{
ArgumentOutOfRangeException.ThrowIfLessThan(playerId, 0);
ArgumentOutOfRangeException.ThrowIfGreaterThan(playerId, _playersZones.Count - 1);
return _playersZones[playerId].Clone() as PlayerZone ?? throw new ArgumentException("playerID is out of bound");
}
private List<Objective> GetRandomObjectives(int number, List<int> freeIndex)
@@ -79,9 +102,8 @@ public class Match
List<Objective> result = new List<Objective>();
for (int i = 0; i < number; i++)
{
#pragma warning disable CA5394
int randomIndex = freeIndex[_random.Next(freeIndex.Count)];
#pragma warning restore CA5394
int randomIndex = _random.Next(freeIndex.Count);
int cardIndex = freeIndex[randomIndex];
freeIndex.RemoveAt(randomIndex);
result.Add(_objectives.ElementAt(randomIndex));
}

View File

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

View File

@@ -2,7 +2,7 @@ using LittleTown.Core.Enums;
namespace LittleTown.Core;
/// <summary> Représente les données propre à un joueur </summary>
public class PlayerZone
public class PlayerZone : ICloneable
{
/// <summary> Les ressources que possede le joueur </summary>
public IDictionary<ResourceType, int> Ressources { get; init; } = new Dictionary<ResourceType, int>();
@@ -18,7 +18,7 @@ public class PlayerZone
/// <param name="qte">la quantité non nulle non négative</param>
public void AddRessources(ResourceType res, int qte)
{
ArgumentOutOfRangeException.ThrowIfLessThan(1, qte);
ArgumentOutOfRangeException.ThrowIfLessThan(qte, 1);
if (Ressources.ContainsKey(res))
{
Ressources[res] += qte;
@@ -28,4 +28,18 @@ public class PlayerZone
Ressources.Add(res, qte);
}
}
/// <summary> Cloner ce playerZone </summary>
/// <returns>Une copie de l'objet</returns>
public object Clone()
{
PlayerZone result = new PlayerZone()
{
Ressources = new Dictionary<ResourceType, int>(Ressources),
Objectives = new List<Objective>(Objectives),
ScoreMarker = ScoreMarker
};
return result;
}
}

View File

@@ -0,0 +1,92 @@
[
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 2
},
{
"Description": "desc",
"Formula": "formula",
"Points": 3
},
{
"Description": "desc",
"Formula": "formula",
"Points": 3
},
{
"Description": "desc",
"Formula": "formula",
"Points": 3
},
{
"Description": "desc",
"Formula": "formula",
"Points": 3
},
{
"Description": "desc",
"Formula": "formula",
"Points": 3
},
{
"Description": "desc",
"Formula": "formula",
"Points": 3
},
{
"Description": "desc",
"Formula": "formula",
"Points": 3
}
]

View File

@@ -29,4 +29,14 @@ public class StaticDataGetter : IStaticDataGetter
return buildings;
}
/// <inheritdoc/>
public ICollection<Objective> GetObjectives()
{
string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Objectives.json");
string data = System.IO.File.ReadAllText(path);
List<Objective> objectives = JsonSerializer.Deserialize<List<Objective>>(data) ?? throw new JsonException("Cannot deserialize Objectives");
return objectives;
}
}