' DiceModule.vb
' A collection of common dice procedures.

    Imports System.IO

Module modDice

    Dim randomObject As Random = New Random

    ' rolls single die
    Function RollDie() As Integer
        Return randomObject.Next(1, 7)
    End Function ' RollDie

    ' die summation procedure
    Function RollAndSum(ByVal diceNumber As Integer) _
             As Integer

        Dim i As Integer
        Dim sum As Integer = 0

        For i = 1 To diceNumber
            sum += RollDie()
        Next

        Return sum
    End Function ' RollAndSum

    ' returns die image
    Function GetDieImage(ByVal dieValue As Integer, _
             Optional ByVal baseImageName As String = "die") _
             As System.Drawing.Image

        Return Image.FromFile(Directory.GetCurrentDirectory & _
           "\Images\" & baseImageName & dieValue & ".png")
    End Function ' GetDieImage
End Module ' modDice

