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.
83 lines
2.2 KiB
83 lines
2.2 KiB
// ReSharper disable All
|
|
using System.Runtime.CompilerServices;
|
|
using QwirkleClassLibrary.Tiles;
|
|
|
|
namespace QwirkleClassLibrary.Boards;
|
|
|
|
public class Cell
|
|
{
|
|
private readonly int x;
|
|
private readonly int y;
|
|
private Tile? tile = null;
|
|
|
|
/// <summary>
|
|
/// This is the constructor for a Cell.
|
|
/// </summary>
|
|
/// <param name="x">The x attribute of the cell.</param>
|
|
/// <param name="y">The y attribute of the cell.</param>
|
|
/// <exception cref="ArgumentException">Throw an exception if the x or y attribute is negative.</exception>
|
|
public Cell(int x, int y)
|
|
{
|
|
if (x < 0 || y < 0)
|
|
{
|
|
throw new ArgumentException(x.ToString() + y.ToString());
|
|
}
|
|
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
/// <summary>
|
|
/// A getter for the position of the cell on the x-axis.
|
|
/// </summary>
|
|
/// <returns>The position of the cell on the x-axis.</returns>
|
|
public int GetX
|
|
{
|
|
get { return x; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// A getter for the position of the cell on the y-axis.
|
|
/// </summary>
|
|
/// <returns>The position of the cell on the y-axis.</returns>
|
|
public int GetY
|
|
{
|
|
get { return y; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if the Cell whether is empty or contains a tile.
|
|
/// </summary>
|
|
/// <returns>True if the cell is empty, false if the cell contains a tile.</returns>
|
|
public bool IsFree
|
|
{
|
|
get { return tile == null; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// A getter for the tile in the cell.
|
|
/// </summary>
|
|
/// <returns>The tile if the cell isn't empty, null otherwise.</returns>
|
|
public Tile? GetTile
|
|
{
|
|
get { return tile; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// A setter for the tile in the cell.
|
|
/// </summary>
|
|
/// <param name="addedTile">The tile the player want to add in the cell.</param>
|
|
/// <returns>True if added succefully (if the cell didn't already contain a tile), false if there already was a tile in this cell.</returns>
|
|
public bool SetTile(Tile addedTile)
|
|
{
|
|
if (tile == null)
|
|
{
|
|
tile = addedTile;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
} |