You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mastermind/Sources/CoreLibrary/Joueurs/Joueur.cs

56 lines
1.6 KiB

using CoreLibrary.Exceptions;
using CoreLibrary.Persistance;
using CoreLibrary.Evenements;
using CoreLibrary.Regles;
using CoreLibrary.Statistiques;
using System.Runtime.Serialization;
namespace CoreLibrary.Joueurs
{
[DataContract]
[KnownType(typeof(ReglesClassiques))]
public class Joueur : IEstPersistant
{
public event EventHandler<JoueurSeConnecterEventArgs>? JoueurSeConnecter;
private void QuandJoueurSeConnecter() => JoueurSeConnecter?.Invoke(this, new JoueurSeConnecterEventArgs(this));
[DataMember]
private Dictionary<(IRegles, Statistique), int> statistiques = new Dictionary<(IRegles, Statistique), int>();
[DataMember]
public string Nom { get; private set; } = "";
[DataMember]
public bool EstConnecte { get; private set; } = false;
public Joueur()
{
}
public Joueur(string nom)
{
Nom = nom;
}
public Joueur SeConnecter(Joueur joueur)
{
if (EstConnecte)
throw new JoueurDejaConnecteException(this);
Nom = joueur.Nom;
statistiques = joueur.statistiques;
EstConnecte = true;
QuandJoueurSeConnecter();
return this;
}
public int Statistique(IRegles regles, Statistique statistique) =>
statistiques.GetValueOrDefault((regles, statistique), 0);
public void IncrementerStatistique(IRegles regles, Statistique statistique) =>
statistiques[(regles, statistique)] = Statistique(regles, statistique) + 1;
}
}