ajout des la base des batiments
All checks were successful
dotnet package / build (8.0.x) (push) Successful in 2m54s

This commit was merged in pull request #6.
This commit is contained in:
2024-05-31 22:40:36 +02:00
parent c223aed71f
commit 35e046a4bb
9 changed files with 218 additions and 13 deletions

View File

@@ -5,7 +5,7 @@ namespace LittleTown.Core.Tests;
public class BuildingTesting
{
List<Building> _buildings;
ICollection<Building> _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));
}
}

View File

@@ -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<ArgumentOutOfRangeException>(() => { new Match(1); });
StaticDataGetter getter = new();
Assert.Throws<ArgumentOutOfRangeException>(() => { 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<ArgumentOutOfRangeException>(() => { new Match(5); });
Assert.Throws<ArgumentOutOfRangeException>(() => { new Match(5, getter); });
}
[Fact]

View File

@@ -1,10 +1,16 @@
using LittleTown.Core.Enums;
namespace LittleTown.Core;
/// <summary> Represente une batiment qui peut etre placé sur le plateau </summary>
public class Building
{
/// <summary> le nom du batiment (attention, c'est une clé de conversion) </summary>
public string Name { get; init; }
public required 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>();
/// <summary> Indique si ce batiment fait parti du jeu de batiment pour joueur débutant </summary>
public bool BeginnerBuilding { get; init; }
}

View File

@@ -14,5 +14,7 @@ public enum ResourceType
/// <summary> Poisson, présente sur le plateau, peut être utilisé comme nourriture </summary>
Fish,
///<summary> Blé, non présente sur le plateau, peut être utilisé comme nourriture </summary>
Cereal
Cereal,
///<summary> Piece, représente une piece de monnaie</summary>
Piece
}

View File

@@ -1,3 +1,5 @@
using LittleTown.Core.Ports;
namespace LittleTown.Core;
/// <summary>
@@ -7,14 +9,22 @@ public class Match
{
private const int _minPlayerCount = 2;
private const int _maxPlayerCount = 4;
private readonly Board _board;
private ICollection<Building> _buildings;
/// <summary>
/// Constructeur d'une nouvelle partie avec un nombre de joueurs données en parametres
/// </summary>
/// <param name="nbPlayer"></param>
public Match(int nbPlayer)
/// <param name="staticData">un objet permettant de récupérer les données statiques du jeu</param>
public Match(int nbPlayer, IStaticDataGetter staticData)
{
ArgumentNullException.ThrowIfNull(staticData);
ArgumentOutOfRangeException.ThrowIfLessThan(nbPlayer, _minPlayerCount);
ArgumentOutOfRangeException.ThrowIfGreaterThan(nbPlayer, _maxPlayerCount);
_board = staticData.GetBoard(1);
_buildings = staticData.GetBuildings();
}
}

View File

@@ -12,5 +12,5 @@ public interface IStaticDataGetter
/// <summary> Recupérer la liste des batiments et leurs données statiques </summary>
/// <returns></returns>
public List<Building> GetBuildings();
public ICollection<Building> GetBuildings();
}

View File

@@ -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
}
]

View File

@@ -21,7 +21,7 @@ public class StaticDataGetter : IStaticDataGetter
}
/// <inheritdoc/>
public List<Building> GetBuildings()
public ICollection<Building> GetBuildings()
{
string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Buildings.json");
string data = System.IO.File.ReadAllText(path);

12
src/Readme.adoc Normal file
View File

@@ -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