I've got a set of six radio buttons inside of a list box and what I'm trying to accomplish is generate a random number all with different ranges (Dice for d&d) depending on what radio button is selected using the switch statement.
Where I'm having the trouble is knowing what radio button is selected so I can use the switch case.
I'm sure this application has been done before but I'm just learning and I thought it would be fun to try.
Here is the portion of the code I'm working with
private void btnRollDice_Cli ck(object sender, EventArgs e)
{
this.diceRollNu mbers.Clear();
Random randomNumber = new Random();
int numberOfDice = Convert.ToInt32 (this.textNumbe rOfDice.Text.Tr im());
int die;
//Roll the number of dice requested
for (int i = 0; i < numberOfDice; i++)
{
//Roll the selected dice
for (int g = 0; g < groupBoxDice.Co ntrols.Count; g++)
{
RadioButton current = (RadioButton)gr oupBoxDice.Cont rols[g];
switch (current.Checke d)
{
case <??>:
die = randomNumber.Ne xt(1, 4);
this.diceRollNu mbers.Add(die);
break;
case <??>:
die = randomNumber.Ne xt(1, 8);
this.diceRollNu mbers.Add(die);
break;
}
}
}
this.FillListBo x(this.diceRoll Numbers);
}
Where I'm having the trouble is knowing what radio button is selected so I can use the switch case.
I'm sure this application has been done before but I'm just learning and I thought it would be fun to try.
Here is the portion of the code I'm working with
private void btnRollDice_Cli ck(object sender, EventArgs e)
{
this.diceRollNu mbers.Clear();
Random randomNumber = new Random();
int numberOfDice = Convert.ToInt32 (this.textNumbe rOfDice.Text.Tr im());
int die;
//Roll the number of dice requested
for (int i = 0; i < numberOfDice; i++)
{
//Roll the selected dice
for (int g = 0; g < groupBoxDice.Co ntrols.Count; g++)
{
RadioButton current = (RadioButton)gr oupBoxDice.Cont rols[g];
switch (current.Checke d)
{
case <??>:
die = randomNumber.Ne xt(1, 4);
this.diceRollNu mbers.Add(die);
break;
case <??>:
die = randomNumber.Ne xt(1, 8);
this.diceRollNu mbers.Add(die);
break;
}
}
}
this.FillListBo x(this.diceRoll Numbers);
}
Comment