// ReSharper disable All using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using QwirkleClassLibrary.Tiles; namespace QwirkleClassLibrary.Boards; [DataContract] public class Cell : INotifyPropertyChanged { public event PropertyChangedEventHandler? PropertyChanged; [DataMember] private readonly int x; [DataMember] private readonly int y; [DataMember] public Tile? Tile { get; private set;} /// /// This is the constructor for a Cell. /// /// The x attribute of the cell. /// The y attribute of the cell. /// Throw an exception if the x or y attribute is negative. public Cell(int x, int y) { if (x < 0 || y < 0) { throw new ArgumentException(x.ToString() + y.ToString()); } this.x = x; this.y = y; } /// /// A getter for the position of the cell on the x-axis. /// /// The position of the cell on the x-axis. public int GetX { get { return x; } } /// /// A getter for the position of the cell on the y-axis. /// /// The position of the cell on the y-axis. public int GetY { get { return y; } } /// /// Check if the Cell whether is empty or contains a tile. /// /// True if the cell is empty, false if the cell contains a tile. public bool IsFree { get { return Tile == null; } } /// /// A setter for the tile in the cell. /// /// The tile the player want to add in the cell. /// True if added succefully (if the cell didn't already contain a tile), false if there already was a tile in this cell. public bool SetTile(Tile addedTile) { if (Tile == null) { Tile = addedTile; OnPropertyChanged(nameof(Tile)); return true; } else { return false; } } protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } }