I'm working on building a die rolling program for use in an XNA project I'm using, but my question here is purely c# and is more on best practices or any gotchas I might need to look out for. Is it an effective use of a static method in an object's definition to outline the creation of default items.
Below is the snapshot of the code I'm using,
public struct Die{
private DieType die;
private static Random rnd = new Random();
public static Die d2 = new Die(DieType.d2);
public static Die d4 = new Die(DieType.d4);
public static Die d6 = new Die(DieType.d6);
public static Die d8 = new Die(DieType.d8);
public static Die d10 = new Die(DieType.d10);
public static Die d12 = new Die(DieType.d12);
public static Die d20 = new Die(DieType.d20);
public static Die d100 = new Die(DieType.d100);
public Die(DieType die){
this.die = die;
}
public int Roll(){
return rnd.Next((int)die);
}
}
Using this my code seems to compile without issues when I make references to the Die struct:
List <Roll> diceCup = new List<Roll>();
diceCup.Add (new Roll(4,Die.d6,-Die.d6.Roll()));
Roll is another struct that takes a Quantity of Die to roll and a short to modify it by.
In the case of my sample above, I create a new roll of 4d6-d6.
Is this going to cause me any problems later down the line if I am creating new instances of these dice?
Thanks for the advice!
Andrew