From 35e046a4bbdf60e6644ed83a1f596b082bdf4335 Mon Sep 17 00:00:00 2001 From: mcmuzzle Date: Fri, 31 May 2024 22:40:36 +0200 Subject: [PATCH] ajout des la base des batiments --- src/LittleTown.Core.Tests/BuildingTesting.cs | 6 +- src/LittleTown.Core.Tests/MatchTesting.cs | 13 +- src/LittleTown.Core/Building.cs | 8 +- .../Enumerations/ResourceType.cs | 4 +- src/LittleTown.Core/MatchAggregate/Match.cs | 12 +- .../PortInterfaces/IStaticDataGetter.cs | 2 +- .../Data/Buildings.json | 172 +++++++++++++++++- .../StaticDataGetter.cs | 2 +- src/Readme.adoc | 12 ++ 9 files changed, 218 insertions(+), 13 deletions(-) create mode 100644 src/Readme.adoc diff --git a/src/LittleTown.Core.Tests/BuildingTesting.cs b/src/LittleTown.Core.Tests/BuildingTesting.cs index cf7806b..4ab2c85 100644 --- a/src/LittleTown.Core.Tests/BuildingTesting.cs +++ b/src/LittleTown.Core.Tests/BuildingTesting.cs @@ -5,7 +5,7 @@ namespace LittleTown.Core.Tests; public class BuildingTesting { - List _buildings; + ICollection _buildings; public BuildingTesting() { @@ -17,10 +17,14 @@ public class BuildingTesting public void TestCosts() { Building? b = _buildings.FirstOrDefault(b => b.Name.Equals("Atelier")); + Assert.NotNull(b); Assert.Equal(2, b.Price[Enums.ResourceType.Rock]); b = _buildings.FirstOrDefault(b => b.Name == "Bar"); + Assert.NotNull(b); Assert.Equal(2, b.Price[Enums.ResourceType.Cereal]); Assert.Equal(2, b.Price[Enums.ResourceType.Rock]); + + Assert.Equal(12, _buildings.Count(b => b.BeginnerBuilding)); } } \ No newline at end of file diff --git a/src/LittleTown.Core.Tests/MatchTesting.cs b/src/LittleTown.Core.Tests/MatchTesting.cs index 3a1fb9e..bb56907 100644 --- a/src/LittleTown.Core.Tests/MatchTesting.cs +++ b/src/LittleTown.Core.Tests/MatchTesting.cs @@ -1,3 +1,5 @@ +using LittleTown.StaticDataAcces; + namespace LittleTown.Core.Tests; public class MatchTesting @@ -5,15 +7,16 @@ public class MatchTesting [Fact] public void EnforcePlayerCountInMatchCreation() { - Assert.Throws(() => { new Match(1); }); + StaticDataGetter getter = new(); + Assert.Throws(() => { new Match(1, getter); }); - Match match2Player = new Match(2); + Match match2Player = new Match(2, getter); - Match match3Player = new Match(3); + Match match3Player = new Match(3, getter); - Match match4Player = new Match(4); + Match match4Player = new Match(4, getter); - Assert.Throws(() => { new Match(5); }); + Assert.Throws(() => { new Match(5, getter); }); } [Fact] diff --git a/src/LittleTown.Core/Building.cs b/src/LittleTown.Core/Building.cs index 685d1e8..6045e80 100644 --- a/src/LittleTown.Core/Building.cs +++ b/src/LittleTown.Core/Building.cs @@ -1,10 +1,16 @@ using LittleTown.Core.Enums; +namespace LittleTown.Core; + +/// Represente une batiment qui peut etre placé sur le plateau public class Building { /// le nom du batiment (attention, c'est une clé de conversion) - public string Name { get; init; } + public required string Name { get; init; } /// Le cout a payer pour construire ce batiment public IReadOnlyDictionary Price { get; init; } = new Dictionary(); + + /// Indique si ce batiment fait parti du jeu de batiment pour joueur débutant + public bool BeginnerBuilding { get; init; } } \ No newline at end of file diff --git a/src/LittleTown.Core/Enumerations/ResourceType.cs b/src/LittleTown.Core/Enumerations/ResourceType.cs index bb384c3..333c671 100644 --- a/src/LittleTown.Core/Enumerations/ResourceType.cs +++ b/src/LittleTown.Core/Enumerations/ResourceType.cs @@ -14,5 +14,7 @@ public enum ResourceType /// Poisson, présente sur le plateau, peut être utilisé comme nourriture Fish, /// Blé, non présente sur le plateau, peut être utilisé comme nourriture - Cereal + Cereal, + /// Piece, représente une piece de monnaie + Piece } \ No newline at end of file diff --git a/src/LittleTown.Core/MatchAggregate/Match.cs b/src/LittleTown.Core/MatchAggregate/Match.cs index 6a5406e..0cc6639 100644 --- a/src/LittleTown.Core/MatchAggregate/Match.cs +++ b/src/LittleTown.Core/MatchAggregate/Match.cs @@ -1,3 +1,5 @@ +using LittleTown.Core.Ports; + namespace LittleTown.Core; /// @@ -7,14 +9,22 @@ public class Match { private const int _minPlayerCount = 2; private const int _maxPlayerCount = 4; + private readonly Board _board; + private ICollection _buildings; /// /// Constructeur d'une nouvelle partie avec un nombre de joueurs données en parametres /// /// - public Match(int nbPlayer) + /// un objet permettant de récupérer les données statiques du jeu + public Match(int nbPlayer, IStaticDataGetter staticData) { + ArgumentNullException.ThrowIfNull(staticData); ArgumentOutOfRangeException.ThrowIfLessThan(nbPlayer, _minPlayerCount); ArgumentOutOfRangeException.ThrowIfGreaterThan(nbPlayer, _maxPlayerCount); + + _board = staticData.GetBoard(1); + + _buildings = staticData.GetBuildings(); } } \ No newline at end of file diff --git a/src/LittleTown.Core/PortInterfaces/IStaticDataGetter.cs b/src/LittleTown.Core/PortInterfaces/IStaticDataGetter.cs index 4f1800e..d580573 100644 --- a/src/LittleTown.Core/PortInterfaces/IStaticDataGetter.cs +++ b/src/LittleTown.Core/PortInterfaces/IStaticDataGetter.cs @@ -12,5 +12,5 @@ public interface IStaticDataGetter /// Recupérer la liste des batiments et leurs données statiques /// - public List GetBuildings(); + public ICollection GetBuildings(); } \ No newline at end of file diff --git a/src/LittleTown.StaticDataAccess/Data/Buildings.json b/src/LittleTown.StaticDataAccess/Data/Buildings.json index 8b60c5f..cf7dd73 100644 --- a/src/LittleTown.StaticDataAccess/Data/Buildings.json +++ b/src/LittleTown.StaticDataAccess/Data/Buildings.json @@ -3,13 +3,181 @@ "Name": "Atelier", "Price": { "Rock": 2 - } + }, + "BeginnerBuilding": true }, { "Name": "Bar", "Price": { "Rock": 2, "Cereal": 2 - } + }, + "BeginnerBuilding": false + }, + { + "Name": "Boulangerie", + "Price": { + "Wood": 2 + }, + "BeginnerBuilding": true + }, + { + "Name": "Brasserie", + "Price": { + "Wood": 2 + }, + "BeginnerBuilding": false + }, + { + "Name": "Carriere", + "Price": { + "Wood": 3 + }, + "BeginnerBuilding": true + }, + { + "Name": "Champsdeble", + "Price": { + "Wood": 1 + }, + "BeginnerBuilding": false + }, + { + "Name": "Charpentier", + "Price": { + "Wood": 2 + }, + "BeginnerBuilding": false + }, + { + "Name": "Epicerie", + "Price": { + "Wood": 2 + }, + "BeginnerBuilding": true + }, + { + "Name": "Entrepot", + "Price": { + "Rock": 4 + }, + "BeginnerBuilding": true + }, + { + "Name": "Eglise", + "Price": { + "Rock": 4 + }, + "BeginnerBuilding": true + }, + { + "Name": "Foire", + "Price": { + "Wood": 4 + }, + "BeginnerBuilding": false + }, + { + "Name": "Fontaine", + "Price": { + "Rock": 2 + }, + "BeginnerBuilding": false + }, + { + "Name": "Grenier", + "Price": { + "Wood": 4 + }, + "BeginnerBuilding": true + }, + { + "Name": "Librairie", + "Price": { + "Rock": 4 + }, + "BeginnerBuilding": false + }, + { + "Name": "minedor", + "Price": { + "Wood": 1, + "Rock": 1 + }, + "BeginnerBuilding": true + }, + { + "Name": "poissonnier", + "Price": { + "Wood": 1, + "Rock": 1 + }, + "BeginnerBuilding": false + }, + { + "Name": "Ponton", + "Price": { + "Wood": 3 + }, + "BeginnerBuilding": false + }, + { + "Name": "Preteursurgage", + "Price": { + "Wood": 3 + }, + "BeginnerBuilding": true + }, + { + "Name": "puits", + "Price": { + "Wood": 1, + "Rock": 1 + }, + "BeginnerBuilding": true + }, + { + "Name": "Restaurant", + "Price": { + "Wood": 2, + "Rock": 2 + }, + "BeginnerBuilding": false + }, + { + "Name": "Statue", + "Price": { + "Rock": 4 + }, + "BeginnerBuilding": true + }, + { + "Name": "Cathedrale", + "Price": { + "Rock": 6 + }, + "BeginnerBuilding": false + }, + { + "Name": "Residence", + "Price": { + "Piece": 6 + }, + "BeginnerBuilding": false + }, + { + "Name": "Chateau", + "Price": { + "Rock": 6 + }, + "BeginnerBuilding": true + }, + { + "Name": "Tourdegarde", + "Price": { + "Wood": 3, + "Rock": 3 + }, + "BeginnerBuilding": false } ] \ No newline at end of file diff --git a/src/LittleTown.StaticDataAccess/StaticDataGetter.cs b/src/LittleTown.StaticDataAccess/StaticDataGetter.cs index 9b66adc..5a3b7c8 100644 --- a/src/LittleTown.StaticDataAccess/StaticDataGetter.cs +++ b/src/LittleTown.StaticDataAccess/StaticDataGetter.cs @@ -21,7 +21,7 @@ public class StaticDataGetter : IStaticDataGetter } /// - public List GetBuildings() + public ICollection GetBuildings() { string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Buildings.json"); string data = System.IO.File.ReadAllText(path); diff --git a/src/Readme.adoc b/src/Readme.adoc new file mode 100644 index 0000000..6347891 --- /dev/null +++ b/src/Readme.adoc @@ -0,0 +1,12 @@ + +# Architecture + +LittleTown.Core est le projet contenant la logique métier du jeu + +LittleTown.Core.Tests est le projet qui contient les tests unitaires pour tester le projet Core + +LittleTown.StaticDataAccess est le projet permettant au core de récupérer les données statiques. Les données statique sont celles qui ne peuvent pas changer, les cases du plateaux, les attributs des batiments. + +# Données statiques + +Les données statiques sont stockées sous forme de json. En local, elle sont lue directement mais on peut envisager un envoie reseau si le besoin se fait sentir un jour \ No newline at end of file