@ -9,14 +9,23 @@ using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Boards
namespace QwirkleClassLibrary.Boards
{
{
/// <summary>
/// This class is used to create the board for our Qwirkle Game. It uses others classes, such as Cell and Tile, to take care of the tiles placements during the game.
/// </summary>
public class Board
public class Board
{
{
public ReadOnlyCollection < Cell > ReadCells = > cells . AsReadOnly ( ) ;
public ReadOnlyCollection < Cell > ReadCells = > cells . AsReadOnly ( ) ;
private readonly List < Cell > cells = new ( ) ;
private readonly List < Cell > cells = new ( ) ;
public int Rows { get ; }
public int Rows { get ; }
public int Columns { get ; }
public int Columns { get ; }
/// <summary>
/// This is the constructor for the board. The parameters 'rows' and 'cols' are used to calculate the size of the board.
/// </summary>
/// <param name="rows">The numbers of rows in the board.</param>
/// <param name="cols">The number of columns in the board.</param>
public Board ( int rows , int cols )
public Board ( int rows , int cols )
{
{
Rows = rows ;
Rows = rows ;
@ -32,6 +41,10 @@ namespace QwirkleClassLibrary.Boards
}
}
}
}
/// <summary>
/// This method is used to check if a cell in the board whether it already contains a tile or not.
/// </summary>
/// <returns>Returns a boolean : true if the cell doesn't contain any tile, false if it already contains a tile.</returns>
public bool HasOccupiedCase ( )
public bool HasOccupiedCase ( )
{
{
foreach ( var cell in cells )
foreach ( var cell in cells )
@ -44,6 +57,13 @@ namespace QwirkleClassLibrary.Boards
return false ;
return false ;
}
}
/// <summary>
/// This method is used to add a tile specified by the player, to the coordinates x, y of the board, also provided by the player.
/// </summary>
/// <param name="x">The position of the tile in the x-axis of the board.</param>
/// <param name="y">The position of the tile in the y-axis of the board.</param>
/// <param name="tile">The tile the player want to place in the board.</param>
/// <returns></returns>
public bool AddTileInCell ( int x , int y , Tile tile )
public bool AddTileInCell ( int x , int y , Tile tile )
{
{
foreach ( var t in cells )
foreach ( var t in cells )
@ -58,16 +78,30 @@ namespace QwirkleClassLibrary.Boards
return false ;
return false ;
}
}
/// <summary>
/// A getter for the cells attribute of the Board Class.
/// </summary>
/// <returns>The cells of the board in a List format.</returns>
public List < Cell > GetCells ( )
public List < Cell > GetCells ( )
{
{
return cells ;
return cells ;
}
}
/// <summary>
/// A getter for the ReadCells attribute of the Board Class.
/// </summary>
/// <returns>The cells of the board, but in a IReadOnlyCollection format.</returns>
public IReadOnlyCollection < Cell > GetReadCells ( )
public IReadOnlyCollection < Cell > GetReadCells ( )
{
{
return ReadCells ;
return ReadCells ;
}
}
/// <summary>
/// A getter for the cell in the coordinates x, y of the board.
/// </summary>
/// <param name="x">The position of the cell in the x-axis of the board.</param>
/// <param name="y">The position of the cell in the y-axis of the board.</param>
/// <returns></returns>
public Cell ? GetCell ( int x , int y )
public Cell ? GetCell ( int x , int y )
{
{
foreach ( var t in cells )
foreach ( var t in cells )