Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 WindowsFormsMinesweeper
- {
- public partial class Form1 : Form
- {
- private int yCurrent;
- private readonly int yFactor = 40;
- private int xCurrent;
- private readonly int xStart = 10;
- private readonly int xFactor = 40;
- public Form1()
- {
- InitializeComponent();
- yCurrent = 80;
- Random random = new Random();
- MineFieldElement[,] mineFieldElements = new MineFieldElement[10, 10];
- for (int i = 0; i < Math.Sqrt(mineFieldElements.Length); i++)
- {
- if (i != 0)
- {
- yCurrent += yFactor;
- }
- for (int j = 0; j < Math.Sqrt(mineFieldElements.Length); j++)
- {
- if (j == 0)
- {
- xCurrent = xStart;
- }
- else
- {
- xCurrent += xFactor;
- }
- FieldButton fieldButton = new FieldButton(xCurrent, yCurrent);
- MineFieldElement mineFieldElement = new MineFieldElement();
- fieldButton.Tag = mineFieldElement;
- this.Controls.Add(fieldButton);
- mineFieldElements[i, j] = mineFieldElement;
- }
- }
- for (int i = 0; i < 20; i++)
- {
- Boolean valid = false;
- while (!valid) {
- int xCoordinate = random.Next(0, 9);
- int yCoordinate = random.Next(0, 9);
- if (mineFieldElements[xCoordinate, yCoordinate].HasAMine)
- {
- valid = false;
- }
- else
- {
- valid = true;
- mineFieldElements[xCoordinate, yCoordinate].HasAMine = true;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement