using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace QwirkleClassLibrary.Tiles { [DataContract] public class Tile : IComparable { [DataMember] private readonly Shape shape; [DataMember] private readonly Color color; /// /// This is the constructor for a Tile. /// /// The shape of the tile. /// The color of the tile. public Tile(Shape sh, Color co) { shape = sh; color = co; } /// /// This method is used to return the color and the shape into a string. /// /// A string with the color and the shape of the tile. public string NameColorTile() { return color.ToString() + shape.ToString(); } /// /// A getter for the shape of the Tile. /// /// The shape attribute of the Tile. public Shape GetShape => shape; /// /// A getter for the color of the Tile. /// /// The color attribute of the Tile. public Color GetColor => color; /// /// This method is used to override the ToString() method. It is simply a tool to facilitate the development. /// /// The color and the shape of the tile, spaced, in a string format. public override string ToString() { return color.ToString() + " " + shape.ToString(); } public int CompareTo(object? obj) { if (obj == null) { return 1; } var otherTile = obj as Tile; if (color == otherTile!.color) { return shape.CompareTo(otherTile.shape); } return color.CompareTo(otherTile.color); } public override bool Equals(object? obj) { if (obj == null || GetType() != obj.GetType()) { return false; } var otherTile = obj as Tile; return color == otherTile!.color && shape == otherTile.shape; } public override int GetHashCode() { return HashCode.Combine(color, shape); } public static bool operator ==(Tile tile1, Tile tile2) { return EqualityComparer.Default.Equals(tile1, tile2); } public static bool operator !=(Tile tile1, Tile tile2) { return !(tile1 == tile2); } public static bool operator <(Tile tile1, Tile tile2) { return tile1.CompareTo(tile2) < 0; } public static bool operator >(Tile tile1, Tile tile2) { return tile1.CompareTo(tile2) > 0; } public static bool operator <=(Tile tile1, Tile tile2) { return tile1.CompareTo(tile2) <= 0; } public static bool operator >=(Tile tile1, Tile tile2) { return tile1.CompareTo(tile2) >= 0; } } }