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.
sae201_qwirkle/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs

85 lines
2.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
{
get { return shape; }
}
/// <summary>
/// A getter for the color of the Tile.
/// </summary>
/// <returns>The color attribute of the Tile.</returns>
public Color GetColor
{
get { return 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 (otherTile != null)
{
if (color == otherTile.color)
{
return shape.CompareTo(otherTile.shape);
}
return color.CompareTo(otherTile.color);
}
throw new ArgumentException("Object is not a Tile");
}
}
}