La taille du code en cours de saisi s'adapte automatiquement
continuous-integration/drone/push Build is failing Details

master
Céleste BARBOSA 11 months ago
parent b355e26c61
commit dc21e90c76

@ -1,31 +1,26 @@
using CoreLibrary.Exceptions; using CoreLibrary.Exceptions;
using System.ComponentModel; using System.Collections.ObjectModel;
namespace CoreLibrary.Core namespace CoreLibrary.Core
{ {
/// <summary> /// <summary>
/// Classe représentant un code composé de jetons et ses différentes méthodes. /// Classe représentant un code composé de jetons et ses différentes méthodes.
/// </summary> /// </summary>
public class Code : INotifyPropertyChanged public class Code
{ {
public event PropertyChangedEventHandler? PropertyChanged; private readonly ObservableCollection<Jeton?> lesJetons = new ObservableCollection<Jeton?>();
void OnPropertyChanged(string propertyName) /// <summary>
{ /// Le nombre maximum de jetons dans le code.
if (PropertyChanged != null) /// </summary>
{ public int NbJetonsMax { get; private set; }
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private readonly Jeton?[] lesJetons;
/// <summary> /// <summary>
/// Le nombre de jetons dans le code. /// Le nombre de jetons dans le code.
/// </summary> /// </summary>
public int NbJetons { get; private set; } = 0; public int NbJetons { get => lesJetons.Count; }
public IEnumerable<Jeton?> Jetons => lesJetons; public ObservableCollection<Jeton?> Jetons => lesJetons;
/// <summary> /// <summary>
/// Initialise une nouvelle instance de la classe <see cref="Code"/> avec la longueur de code spécifiée. /// Initialise une nouvelle instance de la classe <see cref="Code"/> avec la longueur de code spécifiée.
@ -34,12 +29,12 @@ namespace CoreLibrary.Core
/// <exception cref="TailleCodeException">Levée lorsque la longueur du code spécifiée est inférieure ou égale à zéro.</exception> /// <exception cref="TailleCodeException">Levée lorsque la longueur du code spécifiée est inférieure ou égale à zéro.</exception>
public Code(int tailleCode) public Code(int tailleCode)
{ {
NbJetonsMax = tailleCode;
if (tailleCode <= 0) if (tailleCode <= 0)
{ {
throw new TailleCodeException(tailleCode); throw new TailleCodeException(tailleCode);
} }
lesJetons = new Jeton?[tailleCode];
} }
/// <summary> /// <summary>
@ -54,7 +49,10 @@ namespace CoreLibrary.Core
throw new TailleCodeException(jetons.Count()); throw new TailleCodeException(jetons.Count());
} }
lesJetons = new Jeton?[jetons.Count()]; NbJetonsMax = jetons.Count();
foreach (Jeton jeton in jetons) foreach (Jeton jeton in jetons)
{ {
AjouterJeton(jeton); AjouterJeton(jeton);
@ -68,13 +66,12 @@ namespace CoreLibrary.Core
/// <exception cref="CodeCompletException">Levée lorsque le code est plein.</exception> /// <exception cref="CodeCompletException">Levée lorsque le code est plein.</exception>
public void AjouterJeton(Jeton jeton) public void AjouterJeton(Jeton jeton)
{ {
if (NbJetons == TailleMaximale()) if (lesJetons.Count == NbJetonsMax)
{ {
throw new CodeCompletException(); throw new CodeCompletException();
} }
lesJetons[NbJetons++] = jeton; lesJetons.Add(jeton);
OnPropertyChanged(nameof(Jetons));
} }
/// <summary> /// <summary>
@ -83,13 +80,12 @@ namespace CoreLibrary.Core
/// <exception cref="CodeVideException">Levée lorsque le code est vide.</exception> /// <exception cref="CodeVideException">Levée lorsque le code est vide.</exception>
public void SupprimerDernierJeton() public void SupprimerDernierJeton()
{ {
if (NbJetons == 0) if (lesJetons.Count == 0)
{ {
throw new CodeVideException(); throw new CodeVideException();
} }
lesJetons[--NbJetons] = null; lesJetons.RemoveAt(lesJetons.Count - 1);
OnPropertyChanged(nameof(Jetons));
} }
/// <summary> /// <summary>
@ -100,13 +96,13 @@ namespace CoreLibrary.Core
/// <exception cref="IndiceCodeException">Levée lorsque l'indice est supérieur à la taille maximale du code, inférieur à 0 ou qu'il n'y a pas de jeton à l'indice spécifié</exception> /// <exception cref="IndiceCodeException">Levée lorsque l'indice est supérieur à la taille maximale du code, inférieur à 0 ou qu'il n'y a pas de jeton à l'indice spécifié</exception>
public Jeton RecupererJeton(int indice) public Jeton RecupererJeton(int indice)
{ {
if (indice < 0 || indice >= TailleMaximale()) if (indice < 0 || indice >= NbJetonsMax)
throw new IndiceCodeException(indice, NbJetons - 1); throw new IndiceCodeException(indice, lesJetons.Count - 1);
Jeton? jeton = lesJetons[indice]; Jeton? jeton = lesJetons[indice];
if (!jeton.HasValue) if (!jeton.HasValue)
throw new IndiceCodeException(indice, NbJetons - 1); throw new IndiceCodeException(indice, lesJetons.Count - 1);
return jeton.Value; return jeton.Value;
} }
@ -117,16 +113,7 @@ namespace CoreLibrary.Core
/// <returns>True si le code est complet, sinon False.</returns> /// <returns>True si le code est complet, sinon False.</returns>
public bool EstComplet() public bool EstComplet()
{ {
return NbJetons == lesJetons.Length; return lesJetons.Count == NbJetonsMax;
}
/// <summary>
/// Recupère la taille maximale du code.
/// </summary>
/// <returns>Taille maximale du code.</returns>
public int TailleMaximale()
{
return lesJetons.Length;
} }
/// <summary> /// <summary>
@ -164,8 +151,6 @@ namespace CoreLibrary.Core
{ {
Jeton? sonJeton = sesJetons[i]; Jeton? sonJeton = sesJetons[i];
if (sonJeton.HasValue && mesJetons.Contains(sonJeton.Value)) if (sonJeton.HasValue && mesJetons.Contains(sonJeton.Value))
{ {
indicateurs = indicateurs.Append(Indicateur.BONNECOULEUR).ToArray(); indicateurs = indicateurs.Append(Indicateur.BONNECOULEUR).ToArray();

@ -82,9 +82,9 @@ namespace CoreLibrary.Core
/// <exception cref="CodeIncompletException">Levée lorsque le code fourni est incomplet.</exception> /// <exception cref="CodeIncompletException">Levée lorsque le code fourni est incomplet.</exception>
public void AjouterCode(Code code) public void AjouterCode(Code code)
{ {
if (code.TailleMaximale() != tailleCode) if (code.NbJetonsMax != tailleCode)
{ {
throw new CodeInvalideException(code.TailleMaximale(), tailleCode); throw new CodeInvalideException(code.NbJetonsMax, tailleCode);
} }
if (!code.EstComplet()) if (!code.EstComplet())
@ -111,9 +111,9 @@ namespace CoreLibrary.Core
/// <exception cref="CodeIncompletException">Levée lorsque le code fourni est incomplet.</exception> /// <exception cref="CodeIncompletException">Levée lorsque le code fourni est incomplet.</exception>
public bool EstBonCode(Code code) public bool EstBonCode(Code code)
{ {
if (code.TailleMaximale() != tailleCode) if (code.NbJetonsMax != tailleCode)
{ {
throw new CodeInvalideException(code.TailleMaximale(), tailleCode); throw new CodeInvalideException(code.NbJetonsMax, tailleCode);
} }
if (!code.EstComplet()) if (!code.EstComplet())

@ -1,8 +1,4 @@
using CoreLibrary.Core; namespace CoreLibrary.Regles
using CoreLibrary.Exceptions;
using CoreLibrary.Joueurs;
namespace CoreLibrary.Regles
{ {
/// <summary> /// <summary>
/// Classe définissant les règles classiques du jeu. /// Classe définissant les règles classiques du jeu.

@ -96,10 +96,28 @@
</Label.GestureRecognizers> </Label.GestureRecognizers>
</Label> </Label>
<Label FontSize="Medium" HorizontalOptions="Center" VerticalOptions="Center" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Column="1" TextColor="{Binding Code.Jetons[0].Couleur, Converter={StaticResource CouleurVersCouleurMAUI}}" Text="{Binding Code.Jetons[0], Converter={StaticResource JetonVersTexte}}"/> <FlexLayout
<Label FontSize="Medium" HorizontalOptions="Center" VerticalOptions="Center" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Column="2" TextColor="{Binding Code.Jetons[1].Couleur, Converter={StaticResource CouleurVersCouleurMAUI}}" Text="{Binding Code.Jetons[1], Converter={StaticResource JetonVersTexte}}"/> VerticalOptions="Center"
<Label FontSize="Medium" HorizontalOptions="Center" VerticalOptions="Center" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Column="3" TextColor="{Binding Code.Jetons[2].Couleur, Converter={StaticResource CouleurVersCouleurMAUI}}" Text="{Binding Code.Jetons[2], Converter={StaticResource JetonVersTexte}}"/> Grid.Column="1"
<Label FontSize="Medium" HorizontalOptions="Center" VerticalOptions="Center" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Column="4" TextColor="{Binding Code.Jetons[3].Couleur, Converter={StaticResource CouleurVersCouleurMAUI}}" Text="{Binding Code.Jetons[3], Converter={StaticResource JetonVersTexte}}"/> Grid.ColumnSpan="4"
Direction="Row"
Wrap="Wrap"
JustifyContent="SpaceAround"
AlignItems="Center"
BindableLayout.ItemsSource="{Binding Code.Jetons}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label
FontSize="Medium"
HorizontalOptions="Center"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
TextColor="{Binding Couleur, Converter={StaticResource CouleurVersCouleurMAUI}}"
Text="{Binding ., Converter={StaticResource JetonVersTexte}}"/>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
<Label FontSize="Medium" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Column="5" Text="V"> <Label FontSize="Medium" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Column="5" Text="V">
<Label.GestureRecognizers> <Label.GestureRecognizers>

Loading…
Cancel
Save