tmp
Some checks failed
Main Build Process / Build & Test (pull_request) Failing after 1m15s

This commit is contained in:
2026-02-23 22:58:44 +01:00
parent 5ef3be8cc8
commit c2b9d0b3c2
22 changed files with 245 additions and 71 deletions

View File

@@ -23,4 +23,4 @@ app.MapGet("/helloWorld", () =>
.WithName("HelloWorld") .WithName("HelloWorld")
.WithOpenApi(); .WithOpenApi();
app.Run(); await app.RunAsync();

View File

@@ -0,0 +1,3 @@
<div class="rootTile">
@Building.Name
</div>

View File

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

View File

@@ -0,0 +1,4 @@
root {
width: 100%;
height: 100%;
}

View File

@@ -1,11 +1,13 @@
<div class="board"> <div class="board">
<div class="terrain"> <div class="terrain">
@foreach (var row in MatchViewModel.Rows) @for(int y = Board.Height-1; y >= 0; y--)
{ {
<div class="terrain-row"> <div class="terrain-row">
@foreach (var cell in row) @for (int x = 0; x < Board.Width; x++)
{ {
<span class="terrain-cell">@cell</span> <span class="terrain-cell">
<TerrainCell Tile="Board.GetTile(x,y)" />
</span>
} }
</div> </div>
} }
@@ -35,7 +37,10 @@
@for (int i = 0; i < 6; i++) @for (int i = 0; i < 6; i++)
{ {
<div class="building"> <div class="building">
<div>building @i</div> @if (!Match.BuildingInfos.ElementAt(i).IsBuilt)
{
<AvailibleBuildingTile Building="Match.BuildingInfos.ElementAt(i).Building"></AvailibleBuildingTile>
}
</div> </div>
} }
</div> </div>
@@ -45,7 +50,10 @@
@for (int i = 0; i < 6; i++) @for (int i = 0; i < 6; i++)
{ {
<div class="building"> <div class="building">
<div>building @(i+6)</div> @if (!Match.BuildingInfos.ElementAt(i+6).IsBuilt)
{
<AvailibleBuildingTile Building="Match.BuildingInfos.ElementAt(i+6).Building"></AvailibleBuildingTile>
}
</div> </div>
} }
</div> </div>

View File

@@ -1,11 +1,23 @@
using LittleTown.Blazor.Client.ViewModels; using LittleTown.Core;
using LittleTown.Core.Ports;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
namespace LittleTown.Blazor.Client.Components namespace LittleTown.Blazor.Client.Components
{ {
public partial class MatchBoard public partial class MatchBoard
{ {
[Inject]
private IStaticDataGetter StaticDataGetter { get; set; } = default!;
[Parameter, EditorRequired] [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);
}
} }
} }

View File

@@ -0,0 +1,5 @@
<div class="cell-root @CssTileType">
<h3>@Tile.ResourceType</h3>
</div>

View File

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

View File

@@ -0,0 +1,18 @@
.cell-root {
width: 100%;
height: 100%;
}
.rock {
background-color: gray;
}
.lake {
background-color: blue;
}
.forest
{
background-color: green;
}

View File

@@ -3,6 +3,6 @@
<PageTitle>Match</PageTitle> <PageTitle>Match</PageTitle>
<div class="board"> <div class="board">
<MatchBoard MatchViewModel="MatchViewModel" /> <MatchBoard Match="match"/>
</div> </div>

View File

@@ -1,16 +1,21 @@
using LittleTown.Blazor.Client.Services; using LittleTown.Blazor.Client.Services;
using LittleTown.Blazor.Client.ViewModels;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
namespace LittleTown.Blazor.Client.Pages; namespace LittleTown.Blazor.Client.Pages;
public partial class Match(IMatchService matchServices) 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()); match = matchServices.GetMatch();
return base.SetParametersAsync(parameters); match.AddPlayer("Andre");
match.AddPlayer("Maelie");
match.AddPlayer("Liam");
await match.Init();
await base.SetParametersAsync(parameters);
} }
} }

View File

@@ -48,21 +48,33 @@ public class WasmStaticDataGetter : IStaticDataGetter
} }
/// <inheritdoc/> /// <inheritdoc/>
public ICollection<Building> GetBuildings() public async Task<ICollection<Building>> GetBuildingsAsync()
{ {
InitializeAsync().GetAwaiter().GetResult(); await InitializeAsync();
List<Building> buildings = JsonSerializer.Deserialize<List<Building>>(_buildingData) List<Building> buildings = JsonSerializer.Deserialize<List<Building>>(_buildingData)
?? throw new JsonException("Cannot deserialize Buildings"); ?? throw new JsonException("Cannot deserialize Buildings");
return buildings; return buildings;
} }
/// <inheritdoc/>
public ICollection<Building> GetBuildings()
{
throw new NotImplementedException("Use the asynchronous version of GetBuildings for WebAssembly.");
}
/// <inheritdoc/> /// <inheritdoc/>
public ICollection<Objective> GetObjectives() public ICollection<Objective> GetObjectives()
{ {
InitializeAsync().GetAwaiter().GetResult(); throw new NotImplementedException("Use the asynchronous version of GetObjectives for WebAssembly.");
}
List<Objective> objectives = JsonSerializer.Deserialize<List<Objective>>(_objectivesData)
/// <inheritdoc/>
public async Task<ICollection<Objective>> GetObjectivesAsync()
{
await InitializeAsync();
List<Objective> objectives = JsonSerializer.Deserialize<List<Objective>>(_objectivesData)
?? throw new JsonException("Cannot deserialize Objectives"); ?? throw new JsonException("Cannot deserialize Objectives");
return objectives; return objectives;
} }

View File

@@ -1,19 +0,0 @@
using LittleTown.Core;
namespace LittleTown.Blazor.Client.ViewModels;
public class MatchViewModel(Match match)
{
public List<List<int>> Rows
{
get
{
List<List<int>> rows = new List<List<int>>();
for(int i = 0; i < 6; i++)
{
rows.Add(Enumerable.Range(i * 6, 9).ToList());
}
return rows;
}
}
}

View File

@@ -1,4 +1,4 @@
@inherits LayoutComponentBase @inherits LayoutComponentBase
<div class="page"> <div class="page">
<div class="sidebar"> <div class="sidebar">
@@ -6,13 +6,7 @@
</div> </div>
<main> <main>
<div class="top-row px-4"> @Body
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>
<article class="content px-4">
@Body
</article>
</main> </main>
</div> </div>

View File

@@ -17,7 +17,7 @@ public class BoardTesting
[Fact] [Fact]
public void BoardGetTile() public void BoardGetTile()
{ {
Assert.Equal(ResourceType.Fish, _board.GetTile(0, 3)?.ResourceType); Assert.Equal(ResourceType.Fish, _board.GetTile(0, 3).ResourceType);
} }
[Fact] [Fact]

View File

@@ -7,31 +7,31 @@ namespace LittleTown.Core.Tests;
public class MatchTesting public class MatchTesting
{ {
[Fact] [Fact]
public void EnforcePlayerCountInMatchCreation() public async Task EnforcePlayerCountInMatchCreation()
{ {
StaticDataGetter getter = new(); StaticDataGetter getter = new();
var match = new Match(getter); var match = new Match(getter);
match.AddPlayer("Player1"); match.AddPlayer("Player1");
Assert.Throws<ArgumentOutOfRangeException>(() => { match.Init(); }); await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => match.Init() );
Match match2 = new Match(getter); Match match2 = new Match(getter);
match2.AddPlayer("Player1"); match2.AddPlayer("Player1");
match2.AddPlayer("Player2"); match2.AddPlayer("Player2");
Assert.Throws<MatchConfigException>(() => match2.AddPlayer("Player2")); Assert.Throws<MatchConfigException>(() => match2.AddPlayer("Player2"));
match2.Init(); await match2.Init();
Match match3 = new Match(getter); Match match3 = new Match(getter);
match3.AddPlayer("Player1"); match3.AddPlayer("Player1");
match3.AddPlayer("Player2"); match3.AddPlayer("Player2");
match3.AddPlayer("Player3"); match3.AddPlayer("Player3");
match3.Init(); await match3.Init();
Match match4 = new Match(getter); Match match4 = new Match(getter);
match4.AddPlayer("Player1"); match4.AddPlayer("Player1");
match4.AddPlayer("Player2"); match4.AddPlayer("Player2");
match4.AddPlayer("Player3"); match4.AddPlayer("Player3");
match4.AddPlayer("Player4"); match4.AddPlayer("Player4");
match4.Init(); await match4.Init();
Match match5 = new Match(getter); Match match5 = new Match(getter);
match5.AddPlayer("Player1"); match5.AddPlayer("Player1");
@@ -42,13 +42,13 @@ public class MatchTesting
} }
[Fact] [Fact]
public void TwoPlayerInitMatchTest() public async Task TwoPlayerInitMatchTest()
{ {
StaticDataGetter getter = new(); StaticDataGetter getter = new();
Match match = new Match(getter); Match match = new Match(getter);
match.AddPlayer("Player1"); match.AddPlayer("Player1");
match.AddPlayer("Player2"); match.AddPlayer("Player2");
match.Init(); await match.Init();
PlayerZone player1 = match.GetPlayerZone("Player1"); PlayerZone player1 = match.GetPlayerZone("Player1");
PlayerZone player1_3 = match.GetPlayerZone("Player2"); PlayerZone player1_3 = match.GetPlayerZone("Player2");

View File

@@ -24,10 +24,10 @@ public class Board
/// <param name="x">la colonne de la tile partant de la gauche a 0</param> /// <param name="x">la colonne de la tile partant de la gauche a 0</param>
/// <param name="y">ligne de la tile partant du bas a 0</param> /// <param name="y">ligne de la tile partant du bas a 0</param>
/// <returns>la tile</returns> /// <returns>la tile</returns>
public Tile? GetTile(int x, int y) public Tile GetTile(int x, int y)
{ {
if (x < 0 || x >= Width || y < 0 || y >= Height) 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]; return Tiles[x + y * Width];
} }

View File

@@ -0,0 +1,19 @@
namespace LittleTown.Core.Aggregates.MatchAggregate
{
/// <summary>
/// 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.
/// </summary>
public class BuildingInfos
{
/// <summary> Le building concerné /// </summary>
required public Building Building { get; init; }
/// <summary> Indique si le batiment est dans la zone a construire ou sur le terrain construit </summary>
public bool IsBuilt { get; set; }
/// <summary> Le owner du batiment, null si le batiment n'est pas encore construit </summary>
public string? Owner { get; set; }
}
}

View File

@@ -1,4 +1,5 @@
using LittleTown.Core.Actions; using LittleTown.Core.Actions;
using LittleTown.Core.Aggregates.MatchAggregate;
using LittleTown.Core.Exceptions; using LittleTown.Core.Exceptions;
using LittleTown.Core.Ports; using LittleTown.Core.Ports;
@@ -9,6 +10,8 @@ namespace LittleTown.Core;
/// </summary> /// </summary>
public class Match public class Match
{ {
private IStaticDataGetter StaticData { get; set; }
/// <summary> LE numero du tour en cours (Partant de 1) </summary> /// <summary> LE numero du tour en cours (Partant de 1) </summary>
public int CurrentTurn { get; private set; } = 1; public int CurrentTurn { get; private set; } = 1;
@@ -19,7 +22,7 @@ public class Match
public bool IsDone { get; private set; } public bool IsDone { get; private set; }
/// <summary>la liste indiquant l'ordre des joueurs, _playerTurnsOrder[0] donne l'index du 1er joueur, _playerTurnsOrder[1] du second..... </summary> /// <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>(); private readonly List<int> _playerTurnsOrder = new List<int>();
private const int _minPlayerCount = 2; private const int _minPlayerCount = 2;
private const int _maxPlayerCount = 4; private const int _maxPlayerCount = 4;
@@ -27,11 +30,18 @@ public class Match
private int _maxWorkerPerPlayer; private int _maxWorkerPerPlayer;
private int _maxBuidingPerPlayer; private int _maxBuidingPerPlayer;
private readonly Board _board; private Board _board;
private ICollection<Building> _buildings; private ICollection<Building> _buildings;
private ICollection<Objective> _objectives; private ICollection<Objective> _objectives;
private Random _random = new Random(); List<BuildingInfos> _buildingInfos = new List<BuildingInfos>();
public IList<BuildingInfos> BuildingInfos { get
{
return new List<BuildingInfos>(_buildingInfos);
}
}
private Random _random = new Random(10);
private List<PlayerZone> _players = new(); private List<PlayerZone> _players = new();
private int _currentPlayerIndex; private int _currentPlayerIndex;
@@ -43,10 +53,7 @@ public class Match
public Match(IStaticDataGetter staticData) public Match(IStaticDataGetter staticData)
{ {
ArgumentNullException.ThrowIfNull(staticData); ArgumentNullException.ThrowIfNull(staticData);
StaticData = staticData;
_board = staticData.GetBoardAsync(1).GetAwaiter().GetResult();
_buildings = staticData.GetBuildings();
_objectives = staticData.GetObjectives();
} }
/// <summary> Ajouter un nouveau joueur a la partie </summary> /// <summary> Ajouter un nouveau joueur a la partie </summary>
@@ -91,8 +98,12 @@ public class Match
/// <summary> Initialiser la partie, il faut avoir ajouté les joueurs au préalable </summary> /// <summary> Initialiser la partie, il faut avoir ajouté les joueurs au préalable </summary>
/// <exception cref="MatchConfigException"></exception> /// <exception cref="MatchConfigException"></exception>
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; int nbPlayer = _players.Count;
ArgumentOutOfRangeException.ThrowIfLessThan(nbPlayer, _minPlayerCount); ArgumentOutOfRangeException.ThrowIfLessThan(nbPlayer, _minPlayerCount);
@@ -136,6 +147,9 @@ public class Match
index = 0; index = 0;
} }
// selectionner les batiments qui seront disponibles pour la partie
SelectBuildings();
_currentPlayerIndex = 0; _currentPlayerIndex = 0;
} }
@@ -166,6 +180,42 @@ public class Match
} }
return result; return result;
} }
private void SelectBuildings(bool beginerMode = false)
{
List<Building>? 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<int> 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);
}
}
/// <summary> Changer le joueur en cours pour passer au suivant </summary> /// <summary> Changer le joueur en cours pour passer au suivant </summary>
public void NextPlayer() public void NextPlayer()
{ {

View File

@@ -19,8 +19,16 @@ public interface IStaticDataGetter
/// <returns></returns> /// <returns></returns>
public ICollection<Building> GetBuildings(); public ICollection<Building> GetBuildings();
/// <summary> Recupérer la liste des batiments et leurs données statiques </summary>
/// <returns></returns>
public Task<ICollection<Building>> GetBuildingsAsync();
/// <summary> Récupérer la liste des objectifs du jeu </summary> /// <summary> Récupérer la liste des objectifs du jeu </summary>
/// <returns></returns> /// <returns></returns>
public ICollection<Objective> GetObjectives(); public ICollection<Objective> GetObjectives();
/// <summary> Récupérer la liste des objectifs du jeu </summary>
/// <returns></returns>
public Task<ICollection<Objective>> GetObjectivesAsync();
} }

View File

@@ -53,9 +53,10 @@ public class StaticDataGetter : IStaticDataGetter
return board; return board;
} }
public Task<Board> GetBoardAsync(int version) /// <inheritdoc/>
public async Task<Board> GetBoardAsync(int version)
{ {
return Task.FromResult(GetBoard(version)); return GetBoard(version);
} }
/// <inheritdoc/> /// <inheritdoc/>
@@ -66,6 +67,12 @@ public class StaticDataGetter : IStaticDataGetter
return buildings; return buildings;
} }
/// <inheritdoc/>
public async Task<ICollection<Building>> GetBuildingsAsync()
{
return GetBuildings();
}
/// <inheritdoc/> /// <inheritdoc/>
public ICollection<Objective> GetObjectives() public ICollection<Objective> GetObjectives()
{ {
@@ -73,4 +80,10 @@ public class StaticDataGetter : IStaticDataGetter
return objectives; return objectives;
} }
/// <inheritdoc/>
public async Task<ICollection<Objective>> GetObjectivesAsync()
{
return GetObjectives();
}
} }

View File

@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 18
VisualStudioVersion = 17.0.31903.59 VisualStudioVersion = 18.3.11512.155 d18.3
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LittleTown.Core", "LittleTown.Core\LittleTown.Core.csproj", "{E1A228C7-E008-47F4-9EBC-148D4A9071E0}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LittleTown.Core", "LittleTown.Core\LittleTown.Core.csproj", "{E1A228C7-E008-47F4-9EBC-148D4A9071E0}"
EndProject EndProject
@@ -113,4 +113,7 @@ Global
{12579937-5A8E-44F9-AC45-B742B311102E} = {5142DF7A-0B25-DAC6-14FF-F9CE4E6A354A} {12579937-5A8E-44F9-AC45-B742B311102E} = {5142DF7A-0B25-DAC6-14FF-F9CE4E6A354A}
{83375A45-793A-462B-BAB8-AD432FA49350} = {5142DF7A-0B25-DAC6-14FF-F9CE4E6A354A} {83375A45-793A-462B-BAB8-AD432FA49350} = {5142DF7A-0B25-DAC6-14FF-F9CE4E6A354A}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {35A15B53-B50E-40B5-A9F7-F47132A2EEE3}
EndGlobalSection
EndGlobal EndGlobal