You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.4 KiB
125 lines
3.4 KiB
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;
|
|
|
|
/// <summary>
|
|
/// This is the constructor for a Tile.
|
|
/// </summary>
|
|
/// <param name="sh">The shape of the tile.</param>
|
|
/// <param name="co">The color of the tile.</param>
|
|
public Tile(Shape sh, Color co)
|
|
{
|
|
shape = sh;
|
|
color = co;
|
|
}
|
|
|
|
/// <summary>
|
|
/// This method is used to return the color and the shape into a string.
|
|
/// </summary>
|
|
/// <returns>A string with the color and the shape of the tile.</returns>
|
|
public string NameColorTile()
|
|
{
|
|
return color.ToString() + shape.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// A getter for the shape of the Tile.
|
|
/// </summary>
|
|
/// <returns>The shape attribute of the Tile.</returns>
|
|
public Shape GetShape => shape;
|
|
|
|
/// <summary>
|
|
/// A getter for the color of the Tile.
|
|
/// </summary>
|
|
/// <returns>The color attribute of the Tile.</returns>
|
|
public Color GetColor => color;
|
|
|
|
/// <summary>
|
|
/// This method is used to override the ToString() method. It is simply a tool to facilitate the development.
|
|
/// </summary>
|
|
/// <returns>The color and the shape of the tile, spaced, in a string format.</returns>
|
|
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<Tile>.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;
|
|
}
|
|
}
|
|
} |