mise en place dataStatic
This commit was merged in pull request #4.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using LittleTown.Core.Enums;
|
||||
using LittleTown.StaticDataAcces;
|
||||
|
||||
namespace LittleTown.Core.Tests;
|
||||
|
||||
@@ -10,9 +10,8 @@ public class BoardTesting
|
||||
|
||||
public BoardTesting()
|
||||
{
|
||||
string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.Core/Data/Board1.json");
|
||||
string data = System.IO.File.ReadAllText(path);
|
||||
_board = JsonSerializer.Deserialize<Board>(data) ?? throw new JsonException("Cannot deserialize Board");
|
||||
StaticDataGetter getter = new StaticDataGetter();
|
||||
_board = getter.GetBoard(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
26
src/LittleTown.Core.Tests/BuildingTesting.cs
Normal file
26
src/LittleTown.Core.Tests/BuildingTesting.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
using LittleTown.StaticDataAcces;
|
||||
|
||||
namespace LittleTown.Core.Tests;
|
||||
|
||||
public class BuildingTesting
|
||||
{
|
||||
List<Building> _buildings;
|
||||
|
||||
public BuildingTesting()
|
||||
{
|
||||
StaticDataGetter getter = new StaticDataGetter();
|
||||
_buildings = getter.GetBuildings();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestCosts()
|
||||
{
|
||||
Building? b = _buildings.FirstOrDefault(b => b.Name.Equals("Atelier"));
|
||||
Assert.Equal(2, b.Price[Enums.ResourceType.Rock]);
|
||||
|
||||
b = _buildings.FirstOrDefault(b => b.Name == "Bar");
|
||||
Assert.Equal(2, b.Price[Enums.ResourceType.Cereal]);
|
||||
Assert.Equal(2, b.Price[Enums.ResourceType.Rock]);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LittleTown.Core\LittleTown.Core.csproj" />
|
||||
<ProjectReference Include="..\LittleTown.StaticDataAccess\LittleTown.StaticDataAccess.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
10
src/LittleTown.Core/Building.cs
Normal file
10
src/LittleTown.Core/Building.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using LittleTown.Core.Enums;
|
||||
|
||||
public class Building
|
||||
{
|
||||
/// <summary> le nom du batiment (attention, c'est une clé de conversion) </summary>
|
||||
public string Name { get; init; }
|
||||
|
||||
/// <summary> Le cout a payer pour construire ce batiment </summary>
|
||||
public IReadOnlyDictionary<ResourceType, int> Price { get; init; } = new Dictionary<ResourceType, int>();
|
||||
}
|
||||
16
src/LittleTown.Core/PortInterfaces/IStaticDataGetter.cs
Normal file
16
src/LittleTown.Core/PortInterfaces/IStaticDataGetter.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace LittleTown.Core.Ports;
|
||||
|
||||
/// <summary>
|
||||
/// Interface d'un port permettan de récupérer les données statique du jeu
|
||||
/// </summary>
|
||||
public interface IStaticDataGetter
|
||||
{
|
||||
/// <summary> Recuperer un plateau de jeu </summary>
|
||||
/// <param name="version">la version du plateau (1 ou 2)</param>
|
||||
/// <returns> une instance du plateau avec les données statique</returns>
|
||||
public Board GetBoard(int version);
|
||||
|
||||
/// <summary> Recupérer la liste des batiments et leurs données statiques </summary>
|
||||
/// <returns></returns>
|
||||
public List<Building> GetBuildings();
|
||||
}
|
||||
15
src/LittleTown.StaticDataAccess/Data/Buildings.json
Normal file
15
src/LittleTown.StaticDataAccess/Data/Buildings.json
Normal file
@@ -0,0 +1,15 @@
|
||||
[
|
||||
{
|
||||
"Name": "Atelier",
|
||||
"Price": {
|
||||
"Rock": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Bar",
|
||||
"Price": {
|
||||
"Rock": 2,
|
||||
"Cereal": 2
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<EnableNETAnalyzers>true</EnableNETAnalyzers>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
<AnalysisMode>All</AnalysisMode>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LittleTown.Core\LittleTown.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
32
src/LittleTown.StaticDataAccess/StaticDataGetter.cs
Normal file
32
src/LittleTown.StaticDataAccess/StaticDataGetter.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Text.Json;
|
||||
using LittleTown.Core;
|
||||
using LittleTown.Core.Ports;
|
||||
|
||||
namespace LittleTown.StaticDataAcces;
|
||||
|
||||
/// <summary>
|
||||
/// Implementation du getter de données static en fichier local
|
||||
/// </summary>
|
||||
public class StaticDataGetter : IStaticDataGetter
|
||||
{
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Board GetBoard(int version)
|
||||
{
|
||||
|
||||
string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Board1.json");
|
||||
string data = File.ReadAllText(path);
|
||||
Board board = JsonSerializer.Deserialize<Board>(data) ?? throw new JsonException("Cannot deserialize Board");
|
||||
return board;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public List<Building> GetBuildings()
|
||||
{
|
||||
string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Buildings.json");
|
||||
string data = System.IO.File.ReadAllText(path);
|
||||
List<Building> buildings = JsonSerializer.Deserialize<List<Building>>(data) ?? throw new JsonException("Cannot deserialize Buildings");
|
||||
|
||||
return buildings;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LittleTown.Core", "LittleTo
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LittleTown.Core.Tests", "LittleTown.Core.Tests\LittleTown.Core.Tests.csproj", "{32D41FF2-0674-4750-A171-010AB228AF18}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LittleTown.StaticDataAccess", "LittleTown.StaticDataAccess\LittleTown.StaticDataAccess.csproj", "{FA0DE9D0-F788-4734-BDA3-F89F71D757BA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -24,5 +26,9 @@ Global
|
||||
{32D41FF2-0674-4750-A171-010AB228AF18}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{32D41FF2-0674-4750-A171-010AB228AF18}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{32D41FF2-0674-4750-A171-010AB228AF18}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FA0DE9D0-F788-4734-BDA3-F89F71D757BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FA0DE9D0-F788-4734-BDA3-F89F71D757BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FA0DE9D0-F788-4734-BDA3-F89F71D757BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FA0DE9D0-F788-4734-BDA3-F89F71D757BA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Reference in New Issue
Block a user