Question: Dice are used in many tabletop games to implement various game mechanics. Dice come in a variety of shapes and sizes, with four, six, eight,

Dice are used in many tabletop games to implement various game mechanics. Dice come in a variety of shapes and sizes, with four, six, eight, ten, twelve, or twenty sides. Many games need you to assemble a collection of different-sized dice and roll them together. Create a program to imitate dice for a tabletop game.
Create a class for a single dice. The constructor should accept an integer that indicates how many sides the die has. The class should include a function that simulates rolling the die and returns a random number from the valid range.
Create another class that represents a pool of dice. This class should include functions for adding or removing a die from the pool. The class should also include a function that rolls all of the dice in the pool and returns the total that was rolled.
//All commands
add 6
add 4
roll 4
roll 6
add 16
roll 16
roll 16
roll 16
rollall
add 8
add 10
remove 4
rollall
remove 16
remove 6
remove 12
add 2
rollall
Exit
Sample input/output:
Enter Command:
add 6
Adding Dice 6...
Enter Command:
add 4
Adding Dice 4...
Enter Command:
roll 4
Dice 4, Roll Result: 2
Enter Command:
roll 6
Dice 6, Roll Result: 6
Enter Command:
add 16
Adding Dice 16...
Enter Command:
roll 16
Dice 16, Roll Result: 11
Enter Command:
roll 16
Dice 16, Roll Result: 1
Enter Command:
roll 16
Dice 16, Roll Result: 6
Enter Command:
rollall
Rolling all Dice:
Dice 4: Roll Result: 3
Dice 6: Roll Result: 1
Dice 16: Roll Result: 16
Summation of all roll(s): 20.
Enter Command:
add 8
Adding Dice 8...
Enter Command:
add 10 can you please solve it in C# starter code: namespace MyDicePool
{
public class Dice
{
public int Side { get; private set; }
private static Random _r;
static Dice()
{
_r = new Random(7);
}
public Dice(int side)
{
Side = side;
}
public string Roll()
{
//ToDo
//Please complete this method
return "";
}
public override string ToString()
{
//ToDo
//Please complete this method
return "";
}
}
public class DicePool
{
// TODO create DicePool classes
public List DiceList { get; private set; }= new List();
public DicePool()
{
}
public void AddDice(int side)
{
//ToDo
//Please complete this method
}
public bool RemoveDice(int side)
{
//ToDo
//Please complete this method
return false;
}
public string RollAllDice()
{
//ToDo
//Please complete this method
return "";
}
public override string ToString()
{
return RollAllDice();
}
}
class Program
{
static void Main(string[] args)
{
DicePool dicePool = new DicePool();
string command;
do
{
Console.WriteLine("Enter Command:");
command = Console.ReadLine();
command = command.Trim();
command = command.ToLower();
string[] split = command.Split();
if (split[0]== "adddice" || split[0]== "add")
{
int sides = int.Parse(split[1]);
Console.WriteLine($"Adding Dice {sides}...");
dicePool.AddDice(sides);
}
else if (split[0]== "remove")
{
int sides = int.Parse(split[1]);
Console.WriteLine($"Removing Dice {sides}...");
Console.WriteLine($"Remove Successful: {dicePool.RemoveDice(sides)}");
}
else if (split[0]== "roll")
{
int sides = int.Parse(split[1]);
Dice dice = dicePool.DiceList.Find(d => d.Side == sides);
if (dice != null)
{
Console.WriteLine($"Dice {dice}, Roll Result: {dice.Roll()}");
}
else
{
Console.WriteLine("Dice not found...
Cannot roll this dice!");
}
}
else if (split[0]== "rollall")
{
Console.WriteLine("Rolling all Dice:");
Console.WriteLine(

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!