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();
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter