plus simple
This commit was merged in pull request #13.
This commit is contained in:
@@ -17,6 +17,7 @@ public class MatchTesting
|
||||
Match match2 = new Match(getter);
|
||||
match2.AddPlayer("Player1");
|
||||
match2.AddPlayer("Player2");
|
||||
Assert.Throws<MatchConfigException>(() => match2.AddPlayer("Player2"));
|
||||
match2.Init();
|
||||
|
||||
Match match3 = new Match(getter);
|
||||
@@ -51,10 +52,23 @@ public class MatchTesting
|
||||
|
||||
PlayerZone player1 = match.GetPlayerZone("Player1");
|
||||
PlayerZone player1_3 = match.GetPlayerZone("Player2");
|
||||
|
||||
Assert.Equal(3, player1.Ressources[Enums.ResourceType.Piece]);
|
||||
player1.AddRessources(ResourceType.Piece, 1);
|
||||
Assert.Equal(3, player1_3.Ressources[Enums.ResourceType.Piece]);
|
||||
|
||||
Assert.Equal(4, player1.Objectives.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatchGetters()
|
||||
{
|
||||
StaticDataGetter getter = new();
|
||||
Match match = new Match(getter);
|
||||
match.AddPlayer("Player1");
|
||||
match.AddPlayer("Player2");
|
||||
match.Init();
|
||||
|
||||
Assert.Throws<ArgumentException>(() => match.GetPlayerZone("UnknownPlayer"));
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using LittleTown.Core.Actions;
|
||||
using LittleTown.StaticDataAcces;
|
||||
|
||||
namespace LittleTown.Core.Tests;
|
||||
|
||||
public class MatchUpdaterTesting
|
||||
{
|
||||
private class TestAction : IAction
|
||||
{
|
||||
public Action<MatchUpdater> CB { get; init; } = delegate { };
|
||||
|
||||
public void Execute(MatchUpdater updater)
|
||||
{
|
||||
CB(updater);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnforcePlayerCountInMatchCreation()
|
||||
{
|
||||
StaticDataGetter getter = new StaticDataGetter();
|
||||
|
||||
Match match = new Match(getter);
|
||||
match.AddPlayer("Player1");
|
||||
match.AddPlayer("Player2");
|
||||
match.Init();
|
||||
|
||||
TestAction ta = new TestAction()
|
||||
{
|
||||
CB = (updater) =>
|
||||
{
|
||||
Assert.True(updater.GetMatch() == match);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@ namespace LittleTown.Core.Actions;
|
||||
public class EmptyAction : IAction
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Execute(MatchUpdater updater)
|
||||
public void Execute(Match match)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(updater);
|
||||
ArgumentNullException.ThrowIfNull(match);
|
||||
|
||||
updater.NextPlayer();
|
||||
match.NextPlayer();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,6 @@ public interface IAction
|
||||
/// <summary>
|
||||
/// Methode demandant a l'action d'appliquer ses changement au match
|
||||
/// </summary>
|
||||
/// <param name="updater">une interface permettant de modifier le match, elle est valide que la durée de l'appel d'execute</param>
|
||||
public void Execute(MatchUpdater updater);
|
||||
/// <param name="match">le match a modifier avec cette action</param>
|
||||
public void Execute(Match match);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
namespace LittleTown.Core.Actions;
|
||||
|
||||
using LittleTown.Core;
|
||||
using LittleTown.Core.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Ceci est une structure offrant des méthodes pour modifier les données d'un match
|
||||
/// Il permet aux actions de modifier des valeurs qui sont privées
|
||||
/// </summary>
|
||||
public class MatchUpdater
|
||||
{
|
||||
/// <summary> Permet de récupérer le match qui sera modifié par cet updater </summary>
|
||||
public required Func<Match> GetMatch { get; init; }
|
||||
|
||||
/// <summary> Permet d'ajouter des ressources a un joueur </summary>
|
||||
public required Action<ResourceType> AddRessourceToPlayer { get; init; }
|
||||
|
||||
/// <summary> demande au match de changer de joueur en cours </summary>
|
||||
public required Action NextPlayer { get; init; }
|
||||
|
||||
}
|
||||
@@ -86,12 +86,7 @@ public class Match
|
||||
}
|
||||
|
||||
//autoriser l'action a s'executer en lui donner les getters dont elle a besoin
|
||||
action.Execute(new MatchUpdater()
|
||||
{
|
||||
GetMatch = () => { return this; },
|
||||
AddRessourceToPlayer = (resourceType) => { },
|
||||
NextPlayer = NextPlayer
|
||||
});
|
||||
action.Execute(this);
|
||||
}
|
||||
|
||||
/// <summary> Initialiser la partie, il faut avoir ajouté les joueurs au préalable </summary>
|
||||
@@ -171,7 +166,7 @@ public class Match
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private void NextPlayer()
|
||||
public void NextPlayer()
|
||||
{
|
||||
_currentPlayerIndex++;
|
||||
if (_currentPlayerIndex >= _players.Count)
|
||||
|
||||
Reference in New Issue
Block a user