Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace jco2641
- {
- class Program
- {
- static Random rnd = new Random();
- static void RollDice(List<String> dieSpec){
- int diceTotal = 0;
- foreach(string dice in dieSpec){
- if (dice.Contains('d') || dice.Contains('D')) {
- char[] sep = {'d','D'};
- String[] pDice = dice.Split(sep);
- for(int n=0; n < Int16.Parse(pDice[0]); n++) {
- int r = rnd.Next(Int16.Parse(pDice[1])) + 1;
- diceTotal += r;
- Console.WriteLine("1d" + pDice[1] + " " + r + " " + diceTotal);
- }
- } else {
- int r = Int16.Parse(dice);
- diceTotal += r;
- Console.WriteLine(dice + " " + r + " " + diceTotal);
- }
- }
- Console.WriteLine(diceTotal);
- }
- static void Main(string[] args)
- {
- string line = "1d20 + 1d8 + 3d6 - 3";
- List<String> dice = new List<string>(line.Split("+"));
- if(dice[dice.Count-1].Contains('-')) {
- string lastEle = dice[dice.Count-1];
- dice.RemoveAt(dice.Count-1);
- List<String> lastEles = new List<string>(lastEle.Split('-'));
- lastEles[1] = "-" + lastEles[1].Trim();
- dice.AddRange(lastEles);
- }
- RollDice(dice);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement