''' <summary>
''' Represents a single die.
''' </summary>
Public Class Die
#Region " Fields "
''' <summary>
''' The number of faces a die will have by default, if not specified by the user.
''' </summary>
Public Shared ReadOnly DefaultFaceCount As Integer = 6
''' <summary>
''' The object used to select a die face.
''' </summary>
Private faceSelector As IRandomNumberGenerator
''' <summary>
''' The current face value of the die.
''' </summary>
Private _value As Integer
#End Region 'Fields
#Region " Properties "
''' <summary>
''' Gets or sets the number of faces the die has.
''' </summary>
''' <value>
''' An <b>Int32</b> containing the number of faces.
''' </value>
''' <remarks>
''' The default number of faces is defined by <see cref="DefaultFaceCount" />
''' </remarks>
Public Property FaceCount() As Integer
''' <summary>
''' Gets the current face value of the die.
''' </summary>
''' <value>
''' An <b>Int32</b> containing the current face value.
''' </value>
''' <remarks>
''' This would be the side facing upwards on a physical die.
''' </remarks>
Public ReadOnly Property Value() As Integer
Get
Return _value
End Get
End Property
#End Region 'Properties
#Region " Constructors "
''' <summary>
''' Creates a new instance of the <see cref="Die" /> class with the default number of faces and using the default random number generator.
''' </summary>
''' <remarks>
''' The default number of faces is defined by <see cref="DefaultFaceCount" />
''' </remarks>
Public Sub New()
Me.New(DefaultFaceCount)
End Sub
''' <summary>
''' Creates a new instance of the <see cref="Die" /> class using the default random number generator.
''' </summary>
''' <param name="faceCount">
''' The number of faces the die has.
''' </param>
Public Sub New(ByVal faceCount As Integer)
Me.New(faceCount, New RandomNumberGenerator)
End Sub
''' <summary>
''' Creates a new instance of the <see cref="Die" /> class with the default number of faces.
''' </summary>
''' <param name="randomNumberGenerator">
''' The object used to select a die face.
''' </param>
''' <remarks>
''' The default number of faces is defined by <see cref="DefaultFaceCount" />
''' </remarks>
Public Sub New(randomNumberGenerator As IRandomNumberGenerator)
Me.New(DefaultFaceCount, randomNumberGenerator)
End Sub
''' <summary>
''' Creates a new instance of the <see cref="Die" /> class.
''' </summary>
''' <param name="faceCount">
''' The number of faces the die has.
''' </param>
''' <param name="randomNumberGenerator">
''' The object used to select a die face.
''' </param>
Public Sub New(ByVal faceCount As Integer, randomNumberGenerator As IRandomNumberGenerator)
If faceCount <= 0 Then
Throw New ArgumentOutOfRangeException("faceCount", "Dice must have one or more faces.")
End If
Me.FaceCount = faceCount
If randomNumberGenerator Is Nothing Then
randomNumberGenerator = New RandomNumberGenerator()
End If
faceSelector = randomNumberGenerator
End Sub
#End Region 'Constructors
#Region " Methods "
Public Function Roll() As Integer
_value = faceSelector.GenerateRandomNumber(FaceCount)
Return Value
End Function
#End Region 'Methods
End Class