I've written a code so you can roll a dice but I want the dice to flash different sides of it before ending on its final side. When using a switch in a for
loop, the switch doesn't seem to work. This is what I have so far.
Random r = new Random();
for (int i = 0; i < 10; i++)
{
Thread.Sleep(1000);
foreach (Control x in this.Controls)
{
if (x is PictureBox && x.Tag.ToString() == "Dice")
{ x.Visible = false; }
}
int rInt = r.Next(1, 7);
switch (rInt)
{
case 1: Dice1.Visible = true; break;
case 2: Dice2.Visible = true; break;
case 3: Dice3.Visible = true; break;
case 4: Dice4.Visible = true; break;
case 5: Dice5.Visible = true; break;
case 6: Dice6.Visible = true; break;
}
Console.WriteLine(rInt);
}
The output in the console shows that it does take 10 random numbers yet switch
doesn't seem to execute except for the last one.
Does anybody know if I'm doing something wrong?
Aucun commentaire:
Enregistrer un commentaire