/// <summary>
/// A collection to store multiple <see cref="Die" /> objects.
/// </summary>
public class DieCollection : System.Collections.ObjectModel.Collection<Die>
{
#region Constructors
/// <summary>
/// Creates a new, empty instance of the <see cref="DieCollection" /> class.
/// </summary>
public DieCollection()
{
}
/// <summary>
/// Create a new instance of the <see cref="DieCollection" /> with the specified number of items.
/// </summary>
/// <param name="dieCount">
/// The initial number of items in the collection.
/// </param>
/// <remarks>
/// The initial items all have the default number of faces, as defined by the <see cref="Die.DefaultFaceCount" /> field, and use the default random number generator.
/// </remarks>
public DieCollection(int dieCount)
{
for (var i = 0; i < dieCount; i++)
{
Items.Add(new Die());
}
}
/// <summary>
/// Create a new instance of the <see cref="DieCollection" /> with the specified number of items.
/// </summary>
/// <param name="dieCount">
/// The initial number of items in the collection.
/// </param>
/// <param name="faceCount">
/// The number of faces each die has.
/// </param>
/// <remarks>
/// The initial items all use the default random number generator.
/// </remarks>
public DieCollection(int dieCount, int faceCount)
{
for (var i = 0; i < dieCount; i++)
{
Items.Add(new Die(faceCount));
}
}
/// <summary>
/// Create a new instance of the <see cref="DieCollection" /> with the specified number of items.
/// </summary>
/// <param name="dieCount">
/// The initial number of items in the collection.
/// </param>
/// <param name="randomNumberGenerator">
/// The object used to select a die face.
/// </param>
/// <remarks>
/// The initial items all have the default number of faces, as defined by the <see cref="Die.DefaultFaceCount" /> field.
/// </remarks>
public DieCollection(int dieCount, IRandomNumberGenerator randomNumberGenerator)
{
for (var i = 0; i < dieCount; i++)
{
Items.Add(new Die(randomNumberGenerator));
}
}
/// <summary>
/// Create a new instance of the <see cref="DieCollection" /> with the specified number of items.
/// </summary>
/// <param name="dieCount">
/// The initial number of items in the collection.
/// </param>
/// <param name="faceCount">
/// The number of faces each die has.
/// </param>
/// <param name="randomNumberGenerator">
/// The object used to select a die face.
/// </param>
public DieCollection(int dieCount, int faceCount, IRandomNumberGenerator randomNumberGenerator)
{
for (var i = 0; i < dieCount; i++)
{
Items.Add(new Die(faceCount, randomNumberGenerator));
}
}
#endregion Constructors
#region Methods
/// <summary>
/// Rolls all the dice in the collection and returns the sum of the results.
/// </summary>
/// <returns>
/// An <b>Int32</b> containing the summed values of all dice.
/// </returns>
public int RollAll()
{
return Items.Sum(die => die.Roll());
}
#endregion Methods
}