From bd7d748c7deb8e56928d582892dc035f0f54b06f Mon Sep 17 00:00:00 2001 From: rportet Date: Tue, 21 May 2024 17:08:59 +0200 Subject: [PATCH] adding doxygen comments for the Boards and Tiles packages + changing the AddTileInBag test --- Qwirkle/QwirkleClassLibrary/Boards/Board.cs | 34 ++++++++++++++++++++ Qwirkle/QwirkleClassLibrary/Boards/Cell.cs | 27 ++++++++++++++++ Qwirkle/QwirkleClassLibrary/Tiles/Color.cs | 3 ++ Qwirkle/QwirkleClassLibrary/Tiles/Shape.cs | 2 +- Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs | 23 ++++++++++++- Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs | 17 ++++++++-- Qwirkle/TestBase/TestTileBag.cs | 7 ---- 7 files changed, 102 insertions(+), 11 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Boards/Board.cs b/Qwirkle/QwirkleClassLibrary/Boards/Board.cs index 2af84a5..107b20a 100644 --- a/Qwirkle/QwirkleClassLibrary/Boards/Board.cs +++ b/Qwirkle/QwirkleClassLibrary/Boards/Board.cs @@ -9,14 +9,23 @@ using QwirkleClassLibrary.Tiles; namespace QwirkleClassLibrary.Boards { + /// + /// 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. + /// public class Board { public ReadOnlyCollection ReadCells => cells.AsReadOnly(); + private readonly List cells = new(); public int Rows { get; } public int Columns { get; } + /// + /// This is the constructor for the board. The parameters 'rows' and 'cols' are used to calculate the size of the board. + /// + /// The numbers of rows in the board. + /// The number of columns in the board. public Board(int rows, int cols) { Rows = rows; @@ -32,6 +41,10 @@ namespace QwirkleClassLibrary.Boards } } + /// + /// This method is used to check if a cell in the board whether it already contains a tile or not. + /// + /// Returns a boolean : true if the cell doesn't contain any tile, false if it already contains a tile. public bool HasOccupiedCase() { foreach (var cell in cells) @@ -44,6 +57,13 @@ namespace QwirkleClassLibrary.Boards return false; } + /// + /// 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. + /// + /// The position of the tile in the x-axis of the board. + /// The position of the tile in the y-axis of the board. + /// The tile the player want to place in the board. + /// public bool AddTileInCell(int x, int y, Tile tile) { foreach (var t in cells) @@ -58,16 +78,30 @@ namespace QwirkleClassLibrary.Boards return false; } + /// + /// A getter for the cells attribute of the Board Class. + /// + /// The cells of the board in a List format. public List GetCells() { return cells; } + /// + /// A getter for the ReadCells attribute of the Board Class. + /// + /// The cells of the board, but in a IReadOnlyCollection format. public IReadOnlyCollection GetReadCells() { return ReadCells; } + /// + /// A getter for the cell in the coordinates x, y of the board. + /// + /// The position of the cell in the x-axis of the board. + /// The position of the cell in the y-axis of the board. + /// public Cell? GetCell(int x, int y) { foreach (var t in cells) diff --git a/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs b/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs index 544b284..3c2581d 100644 --- a/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs +++ b/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs @@ -10,6 +10,12 @@ public class Cell private readonly int y; 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) @@ -21,26 +27,47 @@ public class Cell 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) diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/Color.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Color.cs index 394317b..780d96c 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/Color.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Color.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace QwirkleClassLibrary.Tiles { + /// + /// This is the constructor for the Color Enum : it is used to set the colors avaible for the tiles. + /// public enum Color { Red, diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/Shape.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Shape.cs index 833781b..1e174e7 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/Shape.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Shape.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace QwirkleClassLibrary.Tiles { /// - /// Enum is used to have a finished number of shapes for the tiles. + /// This is the constructor for the Shape Enum : it is used to set the shapes avaible for the tiles. /// public enum Shape { diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs index e73ec4a..70d1b2f 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs @@ -12,27 +12,48 @@ namespace QwirkleClassLibrary.Tiles private readonly Shape shape; private readonly Color color; + /// + /// This is the constructor for a Tile. + /// + /// The shape of the tile. + /// The color of the tile. public Tile(Shape sh, Color co) { shape = sh; color = co; } + /// + /// This method is used to return the color and the shape into a string. + /// + /// A string with the color and the shape of the tile. public string NameColorTile() { return color.ToString() + shape.ToString(); } - + + /// + /// A getter for the shape of the Tile. + /// + /// The shape attribute of the Tile. public Shape GetShape { get { return shape; } } + /// + /// A getter for the color of the Tile. + /// + /// The color attribute of the Tile. public Color GetColor { get { return color; } } + /// + /// This method is used to override the ToString() method. It is simply a tool to facilitate the development. + /// + /// The color and the shape of the tile, spaced, in a string format. public override string ToString() { return color.ToString() + " " + shape.ToString(); diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs b/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs index 218516f..e9f515e 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs @@ -12,6 +12,11 @@ namespace QwirkleClassLibrary.Tiles public ReadOnlyCollection TilesBag { get; private set; } private readonly List tiles = new List(); + /// + /// This is the constructor for the TileBag. It will create a tile of each of the possibilities among the Color and Shape Enums. + /// + /// This parameter is used to indicate the number of copies we want to create. + /// Throw an exception if the number of copies is negative (impossible) or superior to 3 (contradiction with the rules). public TileBag(int nbSet) { if (nbSet < 0 || nbSet > 3) @@ -34,12 +39,20 @@ namespace QwirkleClassLibrary.Tiles TilesBag = tiles.AsReadOnly(); } - public bool AddTileInBag(Tile tile) + /// + /// This method is used to add a tile in the tile bag. + /// + /// The tile we want to add in the bag. + public void AddTileInBag(Tile tile) { tiles.Add(tile); - return true; } + /// + /// Remove a tile in the tile bag. + /// + /// The tile you want to remove from the bag. + /// True if the remove was successfull, false if it failed. public bool RemoveTileInBag(Tile tile) { for (int i = 0; i < tiles.Count; i++) diff --git a/Qwirkle/TestBase/TestTileBag.cs b/Qwirkle/TestBase/TestTileBag.cs index 685c3e8..cbfc07b 100644 --- a/Qwirkle/TestBase/TestTileBag.cs +++ b/Qwirkle/TestBase/TestTileBag.cs @@ -19,13 +19,6 @@ public class TestTileBag Assert.Equal(bag.TilesBag.Count, nbset * 36); } - [Fact] - public void Test_AddTileInBag() - { - Tile tok = new(Shape.Club, Color.Green); - TileBag bag = new TileBag(2); - Assert.True(bag.AddTileInBag(tok)); - } [Theory] [InlineData(true)]