58 lines
1.3 KiB
C#
58 lines
1.3 KiB
C#
|
|
namespace Dungeoneer {
|
|
|
|
public sealed class Command {
|
|
|
|
public static void Roll(IList<string> args) {
|
|
var argc = args.Count;
|
|
if(argc == 1) {
|
|
if(args[0].Contains("d")) {
|
|
var parts = args[0].Split('d');
|
|
Roll(new List<string> { parts[1], parts[0] });
|
|
return;
|
|
}
|
|
var arg = args[0];
|
|
int sides;
|
|
try { sides = int.Parse(arg); }
|
|
catch(Exception _) {
|
|
Console.WriteLine($"'{arg}' is not a number");
|
|
return;
|
|
}
|
|
var result = Dungeoneer.Util.Roll(sides);
|
|
Console.WriteLine($" -> {result}");
|
|
} else if(argc == 2) {
|
|
var result = 0;
|
|
var first = args[0];
|
|
int sides;
|
|
try { sides = int.Parse(first); }
|
|
catch(Exception _) {
|
|
Console.WriteLine($"'{first}' is not a number");
|
|
return;
|
|
}
|
|
var second = args[1];
|
|
int count;
|
|
try { count = int.Parse(second); }
|
|
catch(Exception _) {
|
|
Console.WriteLine($"'{second}' is not a number");
|
|
return;
|
|
}
|
|
if(count == 1) {
|
|
Roll(new List<string> { first });
|
|
return;
|
|
}
|
|
|
|
var work = "";
|
|
for(int _ = 0; _ < count; _++) {
|
|
var roll = Dungeoneer.Util.Roll(sides);
|
|
result += roll;
|
|
work += $"{roll} ";
|
|
}
|
|
Console.WriteLine($"{work}\n -> {result}");
|
|
} else
|
|
Console.WriteLine($"'roll' accepts 1 or 2 arguments ({argc} given)");
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|