diff --git a/src/LittleTown.Api/Program.cs b/src/LittleTown.Api/Program.cs
index c9ad401..08af276 100644
--- a/src/LittleTown.Api/Program.cs
+++ b/src/LittleTown.Api/Program.cs
@@ -23,4 +23,4 @@ app.MapGet("/helloWorld", () =>
.WithName("HelloWorld")
.WithOpenApi();
-app.Run();
+await app.RunAsync();
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/AvailibleBuildingTile.razor b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/AvailibleBuildingTile.razor
new file mode 100644
index 0000000..b798655
--- /dev/null
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/AvailibleBuildingTile.razor
@@ -0,0 +1,3 @@
+
+ @Building.Name
+
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/AvailibleBuildingTile.razor.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/AvailibleBuildingTile.razor.cs
new file mode 100644
index 0000000..fc6d4b8
--- /dev/null
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/AvailibleBuildingTile.razor.cs
@@ -0,0 +1,11 @@
+using LittleTown.Core;
+using Microsoft.AspNetCore.Components;
+
+namespace LittleTown.Blazor.Client.Components
+{
+ public partial class AvailibleBuildingTile
+ {
+ [Parameter, EditorRequired]
+ public Building Building { get; set; }
+ }
+}
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/AvailibleBuildingTile.razor.css b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/AvailibleBuildingTile.razor.css
new file mode 100644
index 0000000..95bb258
--- /dev/null
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/AvailibleBuildingTile.razor.css
@@ -0,0 +1,4 @@
+root {
+ width: 100%;
+ height: 100%;
+}
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor
index 4f2fe10..0338745 100644
--- a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor
@@ -1,11 +1,13 @@
- @foreach (var row in MatchViewModel.Rows)
+ @for(int y = Board.Height-1; y >= 0; y--)
{
- @foreach (var cell in row)
- {
- @cell
+ @for (int x = 0; x < Board.Width; x++)
+ {
+
+
+
}
}
@@ -35,7 +37,10 @@
@for (int i = 0; i < 6; i++)
{
-
building @i
+ @if (!Match.BuildingInfos.ElementAt(i).IsBuilt)
+ {
+
+ }
}
@@ -45,7 +50,10 @@
@for (int i = 0; i < 6; i++)
{
-
building @(i+6)
+ @if (!Match.BuildingInfos.ElementAt(i+6).IsBuilt)
+ {
+
+ }
}
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.cs
index 3e0b5e2..3a297bd 100644
--- a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.cs
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/MatchBoard.razor.cs
@@ -1,11 +1,23 @@
-using LittleTown.Blazor.Client.ViewModels;
+using LittleTown.Core;
+using LittleTown.Core.Ports;
using Microsoft.AspNetCore.Components;
namespace LittleTown.Blazor.Client.Components
{
public partial class MatchBoard
{
+ [Inject]
+ private IStaticDataGetter StaticDataGetter { get; set; } = default!;
+
[Parameter, EditorRequired]
- public MatchViewModel MatchViewModel { get; init; }
+ public Core.Match Match { get; init; }
+
+ public Board Board { get; private set; }
+
+ protected override void OnParametersSet()
+ {
+ Board = StaticDataGetter.GetBoard(1);
+ }
+
}
}
\ No newline at end of file
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/TerrainCell.razor b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/TerrainCell.razor
new file mode 100644
index 0000000..15ab222
--- /dev/null
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/TerrainCell.razor
@@ -0,0 +1,5 @@
+
+
@Tile.ResourceType
+
+
+
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/TerrainCell.razor.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/TerrainCell.razor.cs
new file mode 100644
index 0000000..90dc562
--- /dev/null
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/TerrainCell.razor.cs
@@ -0,0 +1,28 @@
+using LittleTown.Core;
+using LittleTown.Core.Enums;
+using Microsoft.AspNetCore.Components;
+
+namespace LittleTown.Blazor.Client.Components
+{
+ public partial class TerrainCell
+ {
+ [Parameter, EditorRequired]
+ public Tile Tile { get; init; }
+
+ private string CssTileType { get; set; } = string.Empty;
+
+ protected override void OnInitialized()
+ {
+ CssTileType = Tile.ResourceType switch
+ {
+ ResourceType.None => "",
+ ResourceType.Rock => "rock",
+ ResourceType.Wood => "forest",
+ ResourceType.Fish => "lake",
+ ResourceType.Cereal => "",
+ ResourceType.Piece => "",
+ _ => string.Empty
+ };
+ }
+ }
+}
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/TerrainCell.razor.css b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/TerrainCell.razor.css
new file mode 100644
index 0000000..2649063
--- /dev/null
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Components/TerrainCell.razor.css
@@ -0,0 +1,18 @@
+
+.cell-root {
+ width: 100%;
+ height: 100%;
+}
+
+.rock {
+ background-color: gray;
+}
+
+.lake {
+ background-color: blue;
+}
+
+.forest
+{
+ background-color: green;
+}
\ No newline at end of file
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor
index 748cb9c..0c243f4 100644
--- a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor
@@ -3,6 +3,6 @@
Match
-
+
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.cs
index 2a85ea7..31bb31d 100644
--- a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.cs
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Pages/Match.razor.cs
@@ -1,16 +1,21 @@
using LittleTown.Blazor.Client.Services;
-using LittleTown.Blazor.Client.ViewModels;
using Microsoft.AspNetCore.Components;
namespace LittleTown.Blazor.Client.Pages;
public partial class Match(IMatchService matchServices)
{
- public MatchViewModel MatchViewModel { get; private set; }
+ Core.Match match;
- public override Task SetParametersAsync(ParameterView parameters)
+ public async override Task SetParametersAsync(ParameterView parameters)
{
- MatchViewModel = new MatchViewModel(matchServices.GetMatch());
- return base.SetParametersAsync(parameters);
+ match = matchServices.GetMatch();
+ match.AddPlayer("Andre");
+ match.AddPlayer("Maelie");
+ match.AddPlayer("Liam");
+
+ await match.Init();
+
+ await base.SetParametersAsync(parameters);
}
}
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/WasmStaticDataGetter.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/WasmStaticDataGetter.cs
index de76970..e98752f 100644
--- a/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/WasmStaticDataGetter.cs
+++ b/src/LittleTown.Blazor/LittleTown.Blazor.Client/Services/WasmStaticDataGetter.cs
@@ -48,21 +48,33 @@ public class WasmStaticDataGetter : IStaticDataGetter
}
///
- public ICollection GetBuildings()
+ public async Task> GetBuildingsAsync()
{
- InitializeAsync().GetAwaiter().GetResult();
-
- List buildings = JsonSerializer.Deserialize>(_buildingData)
+ await InitializeAsync();
+
+ List buildings = JsonSerializer.Deserialize>(_buildingData)
?? throw new JsonException("Cannot deserialize Buildings");
return buildings;
}
+ ///
+ public ICollection GetBuildings()
+ {
+ throw new NotImplementedException("Use the asynchronous version of GetBuildings for WebAssembly.");
+ }
+
///
public ICollection GetObjectives()
{
- InitializeAsync().GetAwaiter().GetResult();
-
- List objectives = JsonSerializer.Deserialize>(_objectivesData)
+ throw new NotImplementedException("Use the asynchronous version of GetObjectives for WebAssembly.");
+ }
+
+ ///
+ public async Task> GetObjectivesAsync()
+ {
+ await InitializeAsync();
+
+ List objectives = JsonSerializer.Deserialize>(_objectivesData)
?? throw new JsonException("Cannot deserialize Objectives");
return objectives;
}
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor.Client/ViewModels/MatchViewModel.cs b/src/LittleTown.Blazor/LittleTown.Blazor.Client/ViewModels/MatchViewModel.cs
deleted file mode 100644
index bca9254..0000000
--- a/src/LittleTown.Blazor/LittleTown.Blazor.Client/ViewModels/MatchViewModel.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using LittleTown.Core;
-
-namespace LittleTown.Blazor.Client.ViewModels;
-
-public class MatchViewModel(Match match)
-{
- public List> Rows
- {
- get
- {
- List> rows = new List>();
- for(int i = 0; i < 6; i++)
- {
- rows.Add(Enumerable.Range(i * 6, 9).ToList());
- }
- return rows;
- }
- }
-}
\ No newline at end of file
diff --git a/src/LittleTown.Blazor/LittleTown.Blazor/Components/Layout/MainLayout.razor b/src/LittleTown.Blazor/LittleTown.Blazor/Components/Layout/MainLayout.razor
index 78624f3..f9d6549 100644
--- a/src/LittleTown.Blazor/LittleTown.Blazor/Components/Layout/MainLayout.razor
+++ b/src/LittleTown.Blazor/LittleTown.Blazor/Components/Layout/MainLayout.razor
@@ -1,4 +1,4 @@
-@inherits LayoutComponentBase
+@inherits LayoutComponentBase
diff --git a/src/LittleTown.Core.Tests/BoardTesting.cs b/src/LittleTown.Core.Tests/BoardTesting.cs
index 0062ea7..ffa08b2 100644
--- a/src/LittleTown.Core.Tests/BoardTesting.cs
+++ b/src/LittleTown.Core.Tests/BoardTesting.cs
@@ -17,7 +17,7 @@ public class BoardTesting
[Fact]
public void BoardGetTile()
{
- Assert.Equal(ResourceType.Fish, _board.GetTile(0, 3)?.ResourceType);
+ Assert.Equal(ResourceType.Fish, _board.GetTile(0, 3).ResourceType);
}
[Fact]
diff --git a/src/LittleTown.Core.Tests/MatchTesting.cs b/src/LittleTown.Core.Tests/MatchTesting.cs
index 824c7e4..1b71d6a 100644
--- a/src/LittleTown.Core.Tests/MatchTesting.cs
+++ b/src/LittleTown.Core.Tests/MatchTesting.cs
@@ -7,31 +7,31 @@ namespace LittleTown.Core.Tests;
public class MatchTesting
{
[Fact]
- public void EnforcePlayerCountInMatchCreation()
+ public async Task EnforcePlayerCountInMatchCreation()
{
StaticDataGetter getter = new();
var match = new Match(getter);
match.AddPlayer("Player1");
- Assert.Throws(() => { match.Init(); });
+ await Assert.ThrowsAsync(() => match.Init() );
Match match2 = new Match(getter);
match2.AddPlayer("Player1");
match2.AddPlayer("Player2");
Assert.Throws(() => match2.AddPlayer("Player2"));
- match2.Init();
+ await match2.Init();
Match match3 = new Match(getter);
match3.AddPlayer("Player1");
match3.AddPlayer("Player2");
match3.AddPlayer("Player3");
- match3.Init();
+ await match3.Init();
Match match4 = new Match(getter);
match4.AddPlayer("Player1");
match4.AddPlayer("Player2");
match4.AddPlayer("Player3");
match4.AddPlayer("Player4");
- match4.Init();
+ await match4.Init();
Match match5 = new Match(getter);
match5.AddPlayer("Player1");
@@ -42,13 +42,13 @@ public class MatchTesting
}
[Fact]
- public void TwoPlayerInitMatchTest()
+ public async Task TwoPlayerInitMatchTest()
{
StaticDataGetter getter = new();
Match match = new Match(getter);
match.AddPlayer("Player1");
match.AddPlayer("Player2");
- match.Init();
+ await match.Init();
PlayerZone player1 = match.GetPlayerZone("Player1");
PlayerZone player1_3 = match.GetPlayerZone("Player2");
diff --git a/src/LittleTown.Core/Aggregates/BoardAggregate/Board.cs b/src/LittleTown.Core/Aggregates/BoardAggregate/Board.cs
index d764a0c..3168edd 100644
--- a/src/LittleTown.Core/Aggregates/BoardAggregate/Board.cs
+++ b/src/LittleTown.Core/Aggregates/BoardAggregate/Board.cs
@@ -24,10 +24,10 @@ public class Board
/// la colonne de la tile partant de la gauche a 0
/// ligne de la tile partant du bas a 0
/// la tile
- public Tile? GetTile(int x, int y)
+ public Tile GetTile(int x, int y)
{
if (x < 0 || x >= Width || y < 0 || y >= Height)
- return null;
+ throw new ArgumentException($"Cannot get the cell at {x},{y}");
return Tiles[x + y * Width];
}
diff --git a/src/LittleTown.Core/Aggregates/MatchAggregate/BuildingInfos.cs b/src/LittleTown.Core/Aggregates/MatchAggregate/BuildingInfos.cs
new file mode 100644
index 0000000..df43566
--- /dev/null
+++ b/src/LittleTown.Core/Aggregates/MatchAggregate/BuildingInfos.cs
@@ -0,0 +1,19 @@
+namespace LittleTown.Core.Aggregates.MatchAggregate
+{
+ ///
+ /// Classe indiquant l'etat d'un batiment sélectionné pour une partie.
+ /// Au debut d'un match, 12 batiments sont sélectionnés aléatoirement parmi les 24 batiments du jeu, et sont disponibles pour tous les joueurs.
+ /// Cette classe indique l'etat de ces batiments (si ils sont encore disponibles ou si ils ont été construit par un joueur) et d'autres informations utiles pour le match.
+ ///
+ public class BuildingInfos
+ {
+ /// Le building concerné ///
+ required public Building Building { get; init; }
+
+ /// Indique si le batiment est dans la zone a construire ou sur le terrain construit
+ public bool IsBuilt { get; set; }
+ /// Le owner du batiment, null si le batiment n'est pas encore construit
+ public string? Owner { get; set; }
+ }
+
+}
diff --git a/src/LittleTown.Core/Aggregates/MatchAggregate/Match.cs b/src/LittleTown.Core/Aggregates/MatchAggregate/Match.cs
index 01c6a25..cb727db 100644
--- a/src/LittleTown.Core/Aggregates/MatchAggregate/Match.cs
+++ b/src/LittleTown.Core/Aggregates/MatchAggregate/Match.cs
@@ -1,4 +1,5 @@
using LittleTown.Core.Actions;
+using LittleTown.Core.Aggregates.MatchAggregate;
using LittleTown.Core.Exceptions;
using LittleTown.Core.Ports;
@@ -9,6 +10,8 @@ namespace LittleTown.Core;
///
public class Match
{
+ private IStaticDataGetter StaticData { get; set; }
+
/// LE numero du tour en cours (Partant de 1)
public int CurrentTurn { get; private set; } = 1;
@@ -19,7 +22,7 @@ public class Match
public bool IsDone { get; private set; }
/// la liste indiquant l'ordre des joueurs, _playerTurnsOrder[0] donne l'index du 1er joueur, _playerTurnsOrder[1] du second.....
- private List _playerTurnsOrder = new List();
+ private readonly List _playerTurnsOrder = new List();
private const int _minPlayerCount = 2;
private const int _maxPlayerCount = 4;
@@ -27,11 +30,18 @@ public class Match
private int _maxWorkerPerPlayer;
private int _maxBuidingPerPlayer;
- private readonly Board _board;
+ private Board _board;
private ICollection _buildings;
private ICollection _objectives;
- private Random _random = new Random();
+ List _buildingInfos = new List();
+ public IList BuildingInfos { get
+ {
+ return new List(_buildingInfos);
+ }
+ }
+
+ private Random _random = new Random(10);
private List _players = new();
private int _currentPlayerIndex;
@@ -43,10 +53,7 @@ public class Match
public Match(IStaticDataGetter staticData)
{
ArgumentNullException.ThrowIfNull(staticData);
-
- _board = staticData.GetBoardAsync(1).GetAwaiter().GetResult();
- _buildings = staticData.GetBuildings();
- _objectives = staticData.GetObjectives();
+ StaticData = staticData;
}
/// Ajouter un nouveau joueur a la partie
@@ -91,8 +98,12 @@ public class Match
/// Initialiser la partie, il faut avoir ajouté les joueurs au préalable
///
- public void Init()
+ public async Task Init()
{
+ _board = await StaticData.GetBoardAsync(1).ConfigureAwait(true);
+ _buildings = await StaticData.GetBuildingsAsync().ConfigureAwait(true); ;
+ _objectives = await StaticData.GetObjectivesAsync().ConfigureAwait(true); ;
+
int nbPlayer = _players.Count;
ArgumentOutOfRangeException.ThrowIfLessThan(nbPlayer, _minPlayerCount);
@@ -136,6 +147,9 @@ public class Match
index = 0;
}
+ // selectionner les batiments qui seront disponibles pour la partie
+ SelectBuildings();
+
_currentPlayerIndex = 0;
}
@@ -166,6 +180,42 @@ public class Match
}
return result;
}
+
+ private void SelectBuildings(bool beginerMode = false)
+ {
+
+ List? filteredBuildings = null;
+ if (beginerMode)
+ {
+ filteredBuildings = _buildings.Where(b => b.Name != "Champsdeble" && b.BeginnerBuilding).ToList();
+ }
+ else
+ {
+ filteredBuildings = _buildings.Where(b => b.Name != "Champsdeble").ToList();
+ }
+
+ if(null == filteredBuildings)
+ {
+ throw new MatchConfigException("Aucun batiment trouvé pour la partie");
+ }
+
+
+ List freeIndex = filteredBuildings. Select((b, i) => i).ToList();
+ for (int i = 0; i < 12; ++i)
+ {
+ int randomIndex = _random.Next(freeIndex.Count);
+ int itemIndex = freeIndex[randomIndex];
+ freeIndex.RemoveAt(randomIndex);
+ BuildingInfos infos = new BuildingInfos()
+ {
+ Building = filteredBuildings.ElementAt(itemIndex),
+ IsBuilt = false,
+ Owner = null
+ };
+ _buildingInfos.Add(infos);
+ }
+ }
+
/// Changer le joueur en cours pour passer au suivant
public void NextPlayer()
{
diff --git a/src/LittleTown.Core/PortInterfaces/Inputs/IStaticDataGetter.cs b/src/LittleTown.Core/PortInterfaces/Inputs/IStaticDataGetter.cs
index 6829b43..fd01851 100644
--- a/src/LittleTown.Core/PortInterfaces/Inputs/IStaticDataGetter.cs
+++ b/src/LittleTown.Core/PortInterfaces/Inputs/IStaticDataGetter.cs
@@ -19,8 +19,16 @@ public interface IStaticDataGetter
///
public ICollection GetBuildings();
+ /// Recupérer la liste des batiments et leurs données statiques
+ ///
+ public Task> GetBuildingsAsync();
+
/// Récupérer la liste des objectifs du jeu
///
public ICollection GetObjectives();
+
+ /// Récupérer la liste des objectifs du jeu
+ ///
+ public Task> GetObjectivesAsync();
}
diff --git a/src/LittleTown.StaticDataAccess/StaticDataGetter.cs b/src/LittleTown.StaticDataAccess/StaticDataGetter.cs
index 2013fa6..23dd324 100644
--- a/src/LittleTown.StaticDataAccess/StaticDataGetter.cs
+++ b/src/LittleTown.StaticDataAccess/StaticDataGetter.cs
@@ -53,9 +53,10 @@ public class StaticDataGetter : IStaticDataGetter
return board;
}
- public Task GetBoardAsync(int version)
+ ///
+ public async Task GetBoardAsync(int version)
{
- return Task.FromResult(GetBoard(version));
+ return GetBoard(version);
}
///
@@ -66,6 +67,12 @@ public class StaticDataGetter : IStaticDataGetter
return buildings;
}
+ ///
+ public async Task> GetBuildingsAsync()
+ {
+ return GetBuildings();
+ }
+
///
public ICollection GetObjectives()
{
@@ -73,4 +80,10 @@ public class StaticDataGetter : IStaticDataGetter
return objectives;
}
+
+ ///
+ public async Task> GetObjectivesAsync()
+ {
+ return GetObjectives();
+ }
}
\ No newline at end of file
diff --git a/src/LittleTown.sln b/src/LittleTown.sln
index e5918a7..e0355fe 100644
--- a/src/LittleTown.sln
+++ b/src/LittleTown.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 17
-VisualStudioVersion = 17.0.31903.59
+# Visual Studio Version 18
+VisualStudioVersion = 18.3.11512.155 d18.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LittleTown.Core", "LittleTown.Core\LittleTown.Core.csproj", "{E1A228C7-E008-47F4-9EBC-148D4A9071E0}"
EndProject
@@ -113,4 +113,7 @@ Global
{12579937-5A8E-44F9-AC45-B742B311102E} = {5142DF7A-0B25-DAC6-14FF-F9CE4E6A354A}
{83375A45-793A-462B-BAB8-AD432FA49350} = {5142DF7A-0B25-DAC6-14FF-F9CE4E6A354A}
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {35A15B53-B50E-40B5-A9F7-F47132A2EEE3}
+ EndGlobalSection
EndGlobal