Randomizing not working c# -


so have been trying work on randomizing of dice, there seems problem. question doing wrong? code below. on design page, have 2 picture boxes, each 6 faces of dice. have 2 labels showing dice number got. have 2 more labels underneath picture boxes win. have 1 label in middle says tie if tie. appreciated!

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms;  namespace practice_randomizing { public partial class form1 : form {     public form1()     {         initializecomponent();     }      private void button1_click(object sender, eventargs e)     {         random rand = new random();         int random = rand.next(6);          int player1;         player1 = 0;         int player2;                     player2 = 0;          if         (random == 0)         {             picturebox1.image = properties.resources.dice_11;             label1.text = "you got 1!";             picturebox1.visible = true;         }          else         if         (random ==  1)         {             picturebox1.image = properties.resources.dice_21;             label1.text = "you got 2!";             picturebox1.visible = true;         }         else         if         (random == 2)         {             picturebox1.image = properties.resources.dice_31;             label1.text = "you got 3!";             picturebox1.visible = true;         }         else         if         (random == 3)         {             picturebox1.image = properties.resources.dice_41;             label1.text = "you got 4!";             picturebox1.visible = true;         }         else         if         (random == 4)         {             picturebox1.image = properties.resources.dice_51;             label1.text = "you got 5!";             picturebox1.visible = true;         }         else         {             picturebox1.image = properties.resources.dice_61;             label1.text = "you got 6!";             picturebox1.visible = true;               {                 int dice2 = rand.next(6);                 if                     (dice2 == 0)                 {                     picturebox2.image = properties.resources.dice_11;                     label5.text = "you got 1!";                     picturebox2.visible = true;                 }                  else                         if                         (dice2 == 1)                 {                     picturebox2.image = properties.resources.dice_21;                     label5.text = "you got 2!";                     picturebox2.visible = true;                 }                 else                         if                         (dice2 == 2)                 {                     picturebox2.image = properties.resources.dice_31;                     label5.text = "you got 3!";                     picturebox2.visible = true;                 }                 else                         if                         (dice2 == 3)                 {                     picturebox2.image = properties.resources.dice_41;                     label5.text = "you got 4!";                     picturebox2.visible = true;                 }                 else                         if                         (dice2 == 4)                 {                     picturebox2.image = properties.resources.dice_51;                     label5.text = "you got 5!";                     picturebox2.visible = true;                 }                 else                 {                     picturebox2.image = properties.resources.dice_61;                     label5.text = "you got 6!";                     picturebox2.visible = true;                       if                           (random == 0 && dice2 == 0)                         label4.text = "tie!";                      if                    (random == 0 && dice2 == 0)                         label4.text = "tie!";                      else                    if                    (random == 1 && dice2 == 1)                         label4.text = "tie!";                     else                    if                    (random == 2 && dice2 == 2)                         label4.text = "tie!";                     else                    if                    (random == 3 && dice2 == 3)                         label4.text = "tie!";                     else                    if                    (random == 4 && dice2 == 4)                         label4.text = "tie!";                     else                    if                    (random == 5 && dice2 == 5)                         label4.text = "tie!";                     else                    if                    (random == 1 && dice2 == 0)                     {                         label2.text = "win!";                         player1++;                         label4.text = " " + player1;                     }                     else                    if                    (random == 1 && dice2 == 2)                         label3.text = "win!";                     else                    if                    (random == 1 && dice2 == 3)                         label3.text = "win!";                     else                    if                    (random == 1 && dice2 == 4)                         label3.text = "win!";                     else                    if                    (random == 1 && dice2 == 5)                     {  label2.text = "win!";                     player1++;                     label6.text = " " + player1;                 }                     else                    if                    (random == 2 && dice2 == 0)                         label2.text = "win!";                     else                    if                    (random == 2 && dice2 == 1)                         label2.text = "win!";                     else                    if                    (random == 2 && dice2 == 3)                         label3.text = "win!";                     else                    if                    (random == 2 && dice2 == 4)                         label2.text = "win!";                     else                    if                    (random == 2 && dice2 == 5)                         label2.text = "win!";                     else                    if                    (random == 3 && dice2 == 0)                         label2.text = "win!";                     else                    if                    (random == 3 && dice2 == 1)                         label2.text = "win!";                     else                    if                    (random == 3 && dice2 == 2)                         label2.text = "win!";                     else                    if                    (random == 3 && dice2 == 4)                         label3.text = "win!";                     else                    if                    (random == 3 && dice2 == 5)                         label3.text = "win!";                     else                    if                    (random == 4 && dice2 == 0)                         label2.text = "win!";                     else                    if                    (random == 4 && dice2 == 1)                         label2.text = "win!";                     else                    if                    (random == 4 && dice2 == 2)                         label2.text = "win!";                     else                    if                    (random == 4 && dice2 == 3)                         label2.text = "win!";                     else                    if                    (random == 4 && dice2 == 5)                         label3.text = "win!";                     else                    if                    (random == 5 && dice2 == 0)                         label2.text = "win!";                     else                    if                    (random == 5 && dice2 == 1)                         label2.text = "win!";                     else                    if                    (random == 5 && dice2 == 2)                         label2.text = "win!";                      else                    if                    (random == 5 && dice2 == 3)                         label2.text = "win!";                     else                    if                    (random == 5 && dice2 == 4)                         label2.text = "win!";                      label2.text = " ";                     label3.text = " ";                     label4.text = " ";                                    }             }         }     }                            } 

}

you haven't closed chains of if ... else statements, code picking second dice inside code when first dice 6, , code checking winner inside code when second dice 6.

put } close last else of 2 chains of if ... else statements, following code runs.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -