Classe combinaison indicateur fini

master
Pauline PRADY 1 year ago
parent fe0edefc68
commit 993529e941

@ -4,7 +4,47 @@
{
public CombinaisonIndicateur(CombinaisonJoueur combinaisonJoueur, CombinaisonSecrete combinaisonSecrete)
{
if(!combinaisonJoueur.EstComplete())
{
throw new ArgumentException("Combinaison non complète");
}
JetonJoueur?[] lesJetonsJoueur = new JetonJoueur?[combinaisonJoueur.TailleLogique];
for(int i = 0; i < combinaisonJoueur.TailleLogique; ++i)
{
lesJetonsJoueur[i] = (JetonJoueur) combinaisonJoueur.GetJeton(i);
}
JetonJoueur?[] lesJetonsSecret = new JetonJoueur?[combinaisonSecrete.TailleLogique];
for (int i = 0; i < combinaisonSecrete.TailleLogique; ++i)
{
lesJetonsSecret[i] = (JetonJoueur)combinaisonSecrete.GetJeton(i);
}
for (int i = 0; i < Combinaison.taillePhysique; ++i)
{
JetonJoueur? jetonJoueur = lesJetonsJoueur[i];
JetonJoueur? jetonSecret = lesJetonsSecret[i];
if (jetonJoueur is not null && jetonSecret is not null && ComparerJeton(jetonJoueur, jetonSecret))
{
AjouterJetonBienPlace();
lesJetonsJoueur[i] = null;
lesJetonsSecret[i] = null;
}
}
for (int i = 0; i < Combinaison.taillePhysique; ++i)
{
JetonJoueur? jetonJoueur = lesJetonsJoueur[i];
if (jetonJoueur is not null && ContientJeton(jetonJoueur, lesJetonsSecret))
{
AjouterJetonBonneCouleur();
lesJetonsJoueur[i] = null;
lesJetonsSecret[i] = null;
}
}
}
private void AjouterJetonBienPlace()
@ -24,17 +64,9 @@
return jetonJoueur.Couleur == jetonSecret.Couleur;
}
private bool ContientJeton(JetonJoueur jetonJoueur, JetonJoueur[] jetonsSecret)
private bool ContientJeton(JetonJoueur jetonJoueur, JetonJoueur?[] jetonsSecret)
{
for(int i = 0; i < jetonsSecret.Length; i++)
{
if(ComparerJeton(jetonJoueur, jetonsSecret[i]))
{
return true;
}
}
return false;
return Array.IndexOf(jetonsSecret, jetonJoueur) != -1;
}
}
}

Loading…
Cancel
Save