Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c2b9d0b3c2 |
@@ -23,4 +23,4 @@ app.MapGet("/helloWorld", () =>
|
||||
.WithName("HelloWorld")
|
||||
.WithOpenApi();
|
||||
|
||||
app.Run();
|
||||
await app.RunAsync();
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<div class="rootTile">
|
||||
@Building.Name
|
||||
</div>
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
root {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
<div class="board">
|
||||
<div class="terrain">
|
||||
@foreach (var row in MatchViewModel.Rows)
|
||||
@for(int y = Board.Height-1; y >= 0; y--)
|
||||
{
|
||||
<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>
|
||||
}
|
||||
@@ -35,7 +37,10 @@
|
||||
@for (int i = 0; i < 6; i++)
|
||||
{
|
||||
<div class="building">
|
||||
<div>building @i</div>
|
||||
@if (!Match.BuildingInfos.ElementAt(i).IsBuilt)
|
||||
{
|
||||
<AvailibleBuildingTile Building="Match.BuildingInfos.ElementAt(i).Building"></AvailibleBuildingTile>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -45,7 +50,10 @@
|
||||
@for (int i = 0; i < 6; i++)
|
||||
{
|
||||
<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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<div class="cell-root @CssTileType">
|
||||
<h3>@Tile.ResourceType</h3>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
.cell-root {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.rock {
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
.lake {
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.forest
|
||||
{
|
||||
background-color: green;
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
<PageTitle>Match</PageTitle>
|
||||
<div class="board">
|
||||
<MatchBoard MatchViewModel="MatchViewModel" />
|
||||
<MatchBoard Match="match"/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,19 +48,31 @@ public class WasmStaticDataGetter : IStaticDataGetter
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICollection<Building> GetBuildings()
|
||||
public async Task<ICollection<Building>> GetBuildingsAsync()
|
||||
{
|
||||
InitializeAsync().GetAwaiter().GetResult();
|
||||
await InitializeAsync();
|
||||
|
||||
List<Building> buildings = JsonSerializer.Deserialize<List<Building>>(_buildingData)
|
||||
?? throw new JsonException("Cannot deserialize Buildings");
|
||||
return buildings;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICollection<Building> GetBuildings()
|
||||
{
|
||||
throw new NotImplementedException("Use the asynchronous version of GetBuildings for WebAssembly.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICollection<Objective> GetObjectives()
|
||||
{
|
||||
InitializeAsync().GetAwaiter().GetResult();
|
||||
throw new NotImplementedException("Use the asynchronous version of GetObjectives for WebAssembly.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<ICollection<Objective>> GetObjectivesAsync()
|
||||
{
|
||||
await InitializeAsync();
|
||||
|
||||
List<Objective> objectives = JsonSerializer.Deserialize<List<Objective>>(_objectivesData)
|
||||
?? throw new JsonException("Cannot deserialize Objectives");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
@inherits LayoutComponentBase
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
<div class="page">
|
||||
<div class="sidebar">
|
||||
@@ -6,13 +6,7 @@
|
||||
</div>
|
||||
|
||||
<main>
|
||||
<div class="top-row px-4">
|
||||
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
|
||||
</div>
|
||||
|
||||
<article class="content px-4">
|
||||
@Body
|
||||
</article>
|
||||
@Body
|
||||
</main>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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<ArgumentOutOfRangeException>(() => { match.Init(); });
|
||||
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => match.Init() );
|
||||
|
||||
Match match2 = new Match(getter);
|
||||
match2.AddPlayer("Player1");
|
||||
match2.AddPlayer("Player2");
|
||||
Assert.Throws<MatchConfigException>(() => 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");
|
||||
|
||||
@@ -24,10 +24,10 @@ public class Board
|
||||
/// <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>
|
||||
/// <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)
|
||||
return null;
|
||||
throw new ArgumentException($"Cannot get the cell at {x},{y}");
|
||||
|
||||
return Tiles[x + y * Width];
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
/// </summary>
|
||||
public class Match
|
||||
{
|
||||
private IStaticDataGetter StaticData { get; set; }
|
||||
|
||||
/// <summary> LE numero du tour en cours (Partant de 1) </summary>
|
||||
public int CurrentTurn { get; private set; } = 1;
|
||||
|
||||
@@ -19,7 +22,7 @@ public class Match
|
||||
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>
|
||||
private List<int> _playerTurnsOrder = new List<int>();
|
||||
private readonly List<int> _playerTurnsOrder = new List<int>();
|
||||
|
||||
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<Building> _buildings;
|
||||
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 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;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <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;
|
||||
|
||||
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<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>
|
||||
public void NextPlayer()
|
||||
{
|
||||
|
||||
@@ -19,8 +19,16 @@ public interface IStaticDataGetter
|
||||
/// <returns></returns>
|
||||
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>
|
||||
/// <returns></returns>
|
||||
public ICollection<Objective> GetObjectives();
|
||||
|
||||
/// <summary> Récupérer la liste des objectifs du jeu </summary>
|
||||
/// <returns></returns>
|
||||
public Task<ICollection<Objective>> GetObjectivesAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -53,9 +53,10 @@ public class StaticDataGetter : IStaticDataGetter
|
||||
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/>
|
||||
@@ -66,6 +67,12 @@ public class StaticDataGetter : IStaticDataGetter
|
||||
return buildings;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<ICollection<Building>> GetBuildingsAsync()
|
||||
{
|
||||
return GetBuildings();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICollection<Objective> GetObjectives()
|
||||
{
|
||||
@@ -73,4 +80,10 @@ public class StaticDataGetter : IStaticDataGetter
|
||||
|
||||
return objectives;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<ICollection<Objective>> GetObjectivesAsync()
|
||||
{
|
||||
return GetObjectives();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user