random dice

PHOTO EMBED

Wed Oct 20 2021 08:17:16 GMT+0000 (UTC)

Saved by @_Ryan_ #c#

class Dice
    {
        private int _sides;

        public int Sides
        {
            get
            {
                return _sides;
            }
            
            set
            {
                _sides = value;
            }
        }

        public string type { get; set; }

        public Dice()
        {
            this.Sides = 6;
        }

        public Dice(int sides)
        {
            this.Sides = sides;
        }

        public int roll()
        {
            Random rnd = new Random();
            return rnd.Next(1, Sides + 1);
        }
    }

    class Program
    {

       
        static void Main(string[] args)
        {
            Dice dice1 = new Dice();
            Dice dice2 = new Dice(8);

            Console.WriteLine("Dice with {0} side", dice1.Sides);//6
            Console.WriteLine("Dice with {0} side", dice2.Sides);//8

            Console.WriteLine("Dice with 6 sides is {0}", dice1.roll());
            Console.WriteLine("Dice with 8 sides is {0}", dice2.roll());

            Console.ReadKey();
        }
    }
content_copyCOPY