Created
March 6, 2014 23:29
-
-
Save maxpowa/9401938 to your computer and use it in GitHub Desktop.
Dice!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public enum Die { one = 1, two, three, four, five, six } | |
public struct Dice | |
{ | |
static Random rand = new Random(); | |
Die firstDie; | |
Die secondDie; | |
public Dice() | |
{ | |
this.firstDie = Die.one; | |
this.secondDie = Die.one; | |
} | |
public Dice(bool random = false) | |
{ | |
if (random) | |
{ | |
this.firstDie = (Die)rand.Next(1, 7); | |
this.secondDie = (Die)rand.Next(1, 7); | |
} | |
else | |
{ | |
this.firstDie = Die.one; | |
this.secondDie = Die.one; | |
} | |
} | |
public override string ToString() | |
{ | |
return String.Format("{0} ({1} and {2})", (int)this.firstDie + (int)this.secondDie, this.firstDie, this.secondDie); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment