Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace jco2641
  5. {
  6.     class Program
  7.     {
  8.         static Random rnd = new Random();
  9.  
  10.         static void RollDice(List<String> dieSpec){
  11.            
  12.             int diceTotal = 0;
  13.            
  14.             foreach(string dice in dieSpec){
  15.                 if (dice.Contains('d') || dice.Contains('D')) {
  16.                     char[] sep = {'d','D'};
  17.                     String[] pDice = dice.Split(sep);
  18.                     for(int n=0; n < Int16.Parse(pDice[0]); n++) {
  19.                         int r = rnd.Next(Int16.Parse(pDice[1])) + 1;
  20.                         diceTotal += r;
  21.                         Console.WriteLine("1d" + pDice[1] + " " + r + " " + diceTotal);
  22.                     }
  23.                 } else {
  24.                     int r = Int16.Parse(dice);
  25.                     diceTotal += r;
  26.                     Console.WriteLine(dice + " " + r + " " + diceTotal);
  27.                 }
  28.             }
  29.             Console.WriteLine(diceTotal);
  30.         }
  31.  
  32.         static void Main(string[] args)
  33.         {
  34.             string line = "1d20 + 1d8 + 3d6 - 3";
  35.            
  36.             List<String> dice = new List<string>(line.Split("+"));
  37.  
  38.             if(dice[dice.Count-1].Contains('-')) {
  39.                 string lastEle = dice[dice.Count-1];
  40.                 dice.RemoveAt(dice.Count-1);
  41.                 List<String> lastEles = new List<string>(lastEle.Split('-'));
  42.                 lastEles[1] = "-" + lastEles[1].Trim();
  43.                 dice.AddRange(lastEles);
  44.             }
  45.             RollDice(dice);
  46.        }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement