Tech Off Post

Single Post Permalink

View Thread: C# dice Roller
  • User profile image
    St23aM

     

    I have posted this on my blog but, I thought I would post it here as well to see what advice / comments I can get. I appreciate your help and any advice that you might provide me about this program or programming in general. I am mainly using this program as a practice program for learning C#.  




    "I know I have asked this before and I have been working on this program for about 5 weeks now, However Could someone help me out again. All I want to do is return a String that has each die roll listed and then the total of those die rolls added together. This is the code I have I have changed it a bit please critique me I am trying to learn the right way to do things".  

    using System;

    namespace Dice

    {

       public class Dice

         {

          public string RollDice(int NumberOfDice, int NumberOfSides, int DiceMod)

          {

                      int Sides = NumberOfSides +1;

                      int X = 0;

                      int Roll = 0;

                      int[] Total = null;

                      Total = new int[NumberOfDice];

                      for (X = 0; X != NumberOfDice; X++)

                      {

                            Roll = 0;

                            Random DiceCall = new Random();

                            Roll += DiceCall.Next(1, Sides) + DiceMod;

                            Total[X] = Roll;

                           

                      }

                     

                      string[] ReturnString = (string[]) Total.Clone();

                      string ReturnWholeString = ReturnString.ToString();

                       return ReturnWholeString + Total;

               

                }

          }

    }

    Thanks ahead of time for the great responses and advice

    -St23aM