Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsMinesweeper
  12. {
  13.  
  14.  
  15. public partial class Form1 : Form
  16. {
  17.  
  18. private int yCurrent;
  19. private readonly int yFactor = 40;
  20.  
  21.  
  22. private int xCurrent;
  23. private readonly int xStart = 10;
  24. private readonly int xFactor = 40;
  25.  
  26. public Form1()
  27. {
  28. InitializeComponent();
  29.  
  30. yCurrent = 80;
  31.  
  32.  
  33.  
  34.  
  35. Random random = new Random();
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. MineFieldElement[,] mineFieldElements = new MineFieldElement[10, 10];
  45.  
  46. for (int i = 0; i < Math.Sqrt(mineFieldElements.Length); i++)
  47. {
  48.  
  49. if (i != 0)
  50. {
  51. yCurrent += yFactor;
  52. }
  53.  
  54.  
  55. for (int j = 0; j < Math.Sqrt(mineFieldElements.Length); j++)
  56. {
  57. if (j == 0)
  58. {
  59. xCurrent = xStart;
  60. }
  61. else
  62. {
  63. xCurrent += xFactor;
  64. }
  65. FieldButton fieldButton = new FieldButton(xCurrent, yCurrent);
  66. MineFieldElement mineFieldElement = new MineFieldElement();
  67. fieldButton.Tag = mineFieldElement;
  68. this.Controls.Add(fieldButton);
  69.  
  70. mineFieldElements[i, j] = mineFieldElement;
  71.  
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. }
  79.  
  80. for (int i = 0; i < 20; i++)
  81. {
  82.  
  83. Boolean valid = false;
  84.  
  85. while (!valid) {
  86. int xCoordinate = random.Next(0, 9);
  87. int yCoordinate = random.Next(0, 9);
  88. if (mineFieldElements[xCoordinate, yCoordinate].HasAMine)
  89. {
  90. valid = false;
  91. }
  92. else
  93. {
  94. valid = true;
  95. mineFieldElements[xCoordinate, yCoordinate].HasAMine = true;
  96. }
  97.  
  98. }
  99.  
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement