I am trying to make a Minesweeper game and I want to randomly place bombs across and array of buttons
So far my code for the array of buttons looks like this:
I want to have an array of buttons and just change the text of 10 of them, selected at random to display a B or a background image of a bomb.
int horizontal = 270;
int vertical = 150;
Button[] buttonArray = new Button[81];
for (int i = 0; i < buttonArray.Length; i++)
{
buttonArray[i] = new Button();
buttonArray[i].Size = new Size(20, 20);
buttonArray[i].Location = new Point(horizontal, vertical);
if ((i == 8) || (i == 17) || (i == 26) || (i == 35) ||
(i == 53) || (i == 62) || (i == 71))
{
vertical = 150;
horizontal = horizontal + 20;
}
else
vertical = vertical + 20;
this.Controls.Add(buttonArray[i]);
}
Aucun commentaire:
Enregistrer un commentaire