|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
namespace CoreLibrary
|
|
|
|
|
using CoreLibrary.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace CoreLibrary
|
|
|
|
|
{
|
|
|
|
|
public class Code
|
|
|
|
|
{
|
|
|
|
@ -8,42 +10,57 @@
|
|
|
|
|
|
|
|
|
|
public Code(int tailleCode)
|
|
|
|
|
{
|
|
|
|
|
if(tailleCode <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new TailleCodeException(tailleCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lesJetons = new Jeton?[tailleCode];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Code(IEnumerable<Jeton> jetons)
|
|
|
|
|
{
|
|
|
|
|
if (jetons.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new TailleCodeException(jetons.Count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lesJetons = new Jeton?[jetons.Count()];
|
|
|
|
|
foreach(Jeton jeton in jetons)
|
|
|
|
|
{
|
|
|
|
|
AjouterJeton(jeton);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AjouterJeton(Jeton jeton)
|
|
|
|
|
{
|
|
|
|
|
if (EstComplet())
|
|
|
|
|
throw new CodeTableauLesJetonsCompletException();
|
|
|
|
|
if (NbJetons == TailleMaximale())
|
|
|
|
|
{
|
|
|
|
|
throw new CodeCompletException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lesJetons[NbJetons++] = jeton;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SupprimerDernierJeton()
|
|
|
|
|
{
|
|
|
|
|
if(NbJetons <= 0)
|
|
|
|
|
throw new CodeTableauLesJetonsVideException();
|
|
|
|
|
if(NbJetons == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new CodeVideException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lesJetons[NbJetons-1] = null;
|
|
|
|
|
--NbJetons;
|
|
|
|
|
lesJetons[--NbJetons] = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Jeton RecupererJeton(int indice)
|
|
|
|
|
{
|
|
|
|
|
if(indice < 0 || indice > TailleMaximale())
|
|
|
|
|
throw new CodeIndiceHorsDePorteeException();
|
|
|
|
|
throw new IndiceCodeException(indice, NbJetons-1);
|
|
|
|
|
|
|
|
|
|
Jeton? jeton = lesJetons[indice];
|
|
|
|
|
|
|
|
|
|
if (!jeton.HasValue)
|
|
|
|
|
throw new CodeJetonNullException();
|
|
|
|
|
throw new IndiceCodeException(indice, NbJetons-1);
|
|
|
|
|
|
|
|
|
|
return jeton.Value;
|
|
|
|
|
}
|
|
|
|
@ -66,11 +83,12 @@
|
|
|
|
|
public IEnumerable<Indicateur> Comparer(Code autreCode)
|
|
|
|
|
{
|
|
|
|
|
// Mon code est le code correct, l'autre code est celui qui teste
|
|
|
|
|
if (!autreCode.EstComplet())
|
|
|
|
|
throw new CodeTableauLesJetonsIncompletException();
|
|
|
|
|
|
|
|
|
|
Indicateur[] indicateurs = [];
|
|
|
|
|
|
|
|
|
|
if (EstComplet() || !autreCode.EstComplet())
|
|
|
|
|
return indicateurs;
|
|
|
|
|
|
|
|
|
|
Jeton?[] mesJetons = Jetons().ToArray();
|
|
|
|
|
Jeton?[] sesJetons = autreCode.Jetons().ToArray();
|
|
|
|
|
|
|
|
|
|