using System;
namespace TheDiscoveryProject {
public class MainApp {
public static void Usage() {
string msg = "Dice Rolling Simulation\n\n";
msg += "Usage: dice [-t <type of die>] [-n <number of dice>]\n\n";
msg += "Examples:\n";
msg += "dice \t\t\t==> result of 2D6\n";
msg += "dice -t 20 \t\t==> result of 2D20\n";
msg += "dice -n 3 \t\t==> result of 3D6\n";
msg += "dice -t 10 -n 1 \t==> result of 1D10\n";
msg += "dice -n 1 -t 10 \t==> result of 1D10\n\n";
msg += "will print \"nDt ==> x\" to the screen\n";
msg += "and return x for use by %errorlevel%";
Console.WriteLine(msg);
}
public static int Main(string[] args) {
int typeDie = 6;
int numDice = 2;
if (args.Length > 0) {
for (int i = 0; i < args.Length; i++) {
if (args[i].StartsWith("-")) {
switch (args[i]) {
case "-t": if (args.Length < i + 2) {
Usage(); return -1;
}
if (args[i + 1].StartsWith("-")) {
Usage(); return -1;
}
typeDie = Convert.ToInt32(args[i + 1]);
i++;
break;
case "-n": if (args.Length < i + 2) {
Usage(); return -1;
}
if (args[i + 1].StartsWith("-")) {
Usage(); return -1;
}
numDice = Convert.ToInt32(args[i + 1]);
i++;
break;
default:
Usage();
return -1;
}
} else { Usage(); return -1; }
}
}
Random rnd = new Random((int)DateTime.Now.Ticks);
int result = 0;
for (int i = 1; i <= numDice; i++) {
result += rnd.Next(1, typeDie + 1);
}
Console.WriteLine("{0}D{1} ==> {2}", numDice, typeDie, result);
return result;
}
}
}