#!/usr/bin/ruby
module Game
class Die
class << self
def roll num, val, drop = 0
sto = Array.new num
0.upto(num - 1){ |a| sto[a] = rand(1 .. val) }
sum = 0
unless drop > 0
sto.each { |b| sum += b }
else
sto.sort!
0.upto(num - 1 - drop) { |b| sum += b }
end
sum
end
end
end
end
/// <summary>
/// Represents a die.
/// </summary>
public class Die
{
/// <summary>
/// Number of sides of the die.
/// </summary>
public uint sides
{
get; protected set;
}
/// <summary>
/// Constructs a new Die object.
/// </summary>
/// <param name="nSides">Number of sides.</param>
public Die(uint nSides = 6)
{
this.sides = nSides;
}
/// <summary>
/// Rolls the die.
/// </summary>
/// <returns>The result of rolling the dice.</returns>
public int Roll()
{
Random r = new Random();
return r.Next((int)sides+1);
}
}