using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace QwirkleClassLibrary.Tiles { public class TileBag { 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) { throw new ArgumentException(nbSet.ToString()); } // for (int i = 0; i < nbSet; i++) // { // foreach (Shape s in Enum.GetValues(typeof(Shape))) // { // foreach (Color c in Enum.GetValues(typeof(Color))) // { // Tile t = new Tile(s, c); // tiles.Add(t); // } // } // } tiles.Add(new Tile(Shape.Club, Color.Blue)); tiles.Add(new Tile(Shape.Club, Color.Green)); tiles.Add(new Tile(Shape.Club, Color.Orange)); tiles.Add(new Tile(Shape.Club, Color.Purple)); tiles.Add(new Tile(Shape.Club, Color.Red)); tiles.Add(new Tile(Shape.Club, Color.Yellow)); tiles.Add(new Tile(Shape.Square, Color.Blue)); tiles.Add(new Tile(Shape.Square, Color.Red)); tiles.Add(new Tile(Shape.Square, Color.Orange)); tiles.Add(new Tile(Shape.Square, Color.Purple)); tiles.Add(new Tile(Shape.Square, Color.Green)); tiles.Add(new Tile(Shape.Square, Color.Yellow)); TilesBag = tiles.AsReadOnly(); } /// /// 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); } /// /// 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++) { if (tiles[i] == tile) { tiles.RemoveAt(i); return true; } } return false; } } }