Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

LIEK MY DIE?

Name: Anonymous 2012-01-10 21:42


#!/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

Name: Anonymous 2012-01-11 8:45

>>17
No, this is enterprise quality:


using System;

/// <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);
  }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List