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
3.0 KiB
83 lines
3.0 KiB
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<Tile> TilesBag { get; private set; }
|
|
private readonly List<Tile> tiles = new List<Tile>();
|
|
|
|
/// <summary>
|
|
/// This is the constructor for the TileBag. It will create a tile of each of the possibilities among the Color and Shape Enums.
|
|
/// </summary>
|
|
/// <param name="nbSet">This parameter is used to indicate the number of copies we want to create.</param>
|
|
/// <exception cref="ArgumentException">Throw an exception if the number of copies is negative (impossible) or superior to 3 (contradiction with the rules).</exception>
|
|
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.Green));
|
|
tiles.Add(new Tile(Shape.Square, Color.Orange));
|
|
tiles.Add(new Tile(Shape.Square, Color.Purple));
|
|
tiles.Add(new Tile(Shape.Square, Color.Red));
|
|
tiles.Add(new Tile(Shape.Square, Color.Yellow));
|
|
|
|
TilesBag = tiles.AsReadOnly();
|
|
}
|
|
|
|
/// <summary>
|
|
/// This method is used to add a tile in the tile bag.
|
|
/// </summary>
|
|
/// <param name="tile">The tile we want to add in the bag.</param>
|
|
public void AddTileInBag(Tile tile)
|
|
{
|
|
tiles.Add(tile);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove a tile in the tile bag.
|
|
/// </summary>
|
|
/// <param name="tile">The tile you want to remove from the bag.</param>
|
|
/// <returns>True if the remove was successfull, false if it failed.</returns>
|
|
public bool RemoveTileInBag(Tile tile)
|
|
{
|
|
for (int i = 0; i < tiles.Count; i++)
|
|
{
|
|
if (tiles[i] == tile)
|
|
{
|
|
tiles.RemoveAt(i);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
} |