// ReSharper disable All
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Boards;
[DataContract]
public class Cell
{
[DataMember]
private readonly int x;
[DataMember]
private readonly int y;
[DataMember]
private Tile? tile = null;
///
/// 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 getter for the tile in the cell.
///
/// The tile if the cell isn't empty, null otherwise.
public Tile? GetTile
{
get { return tile; }
}
///
/// 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;
return true;
}
else
{
return false;
}
}
}