diff --git a/source/Trek-12/Models/Cell.cs b/source/Trek-12/Models/Cell.cs index 8369dc8..66e5f4f 100644 --- a/source/Trek-12/Models/Cell.cs +++ b/source/Trek-12/Models/Cell.cs @@ -2,15 +2,50 @@ public class Cell { - private Position pos; - private int value; - private string type; - private string background; - + public Position Pos { get; private set; } + + private int? value; + public int? Value { + get + { + return value; + } + set + { + if (value < 0) + { + throw new Exception("La valeur doit être supérieure à 0"); + } + this.value = value; + } + } + + private string Type { get; set; } + + private string? Background { get; set; } + public Cell(int x, int y) { - pos = new Position(x, y); + Pos = new Position(x, y); } - public string GetCellType() => type; + public string GetCellType() => Type; + + + // Redefinition de l'opérateur == pour comparer deux cellules + public override bool Equals(object? obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + Cell c = (Cell)obj; + return (Pos.X == c.Pos.X) && (Pos.Y == c.Pos.Y); + } + + // Redefinition de la méthode de Hash pour l'opérateur == + public override int GetHashCode() + { + return Pos.X * Pos.Y; + } } \ No newline at end of file