Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Generate()
- {
- Random rand = new Random();
- _field = new CellInfo[Width, Height];
- var cellIndex = new List<Point>();
- for (int i = 0; i < Height; i++)
- for (int j = 0; j < Width; j++)
- {
- _field[j, i] = 0;
- cellIndex.Add(new Point(j, i));
- }
- for (int i = 0; i < Mines, i++)
- {
- var p = cellIndex[rand.Next(cellIndex.Count)];
- cellIndex.Remove(p);
- _field[p.X, p.Y] = _field[p.X, p.Y] | CellInfo.IsMine;
- bool left, up, right, down;
- left = up = right = down = false;
- if((p.X - 1) > 0)
- {
- left = true;
- _field[p.X - 1, p.Y]++;
- }
- if ((p.Y - 1) > 0)
- {
- up = true;
- _field[p.X, p.Y - 1]++;
- }
- if ((p.X + 1) < Width)
- {
- right = true;
- _field[p.X + 1, p.Y]++;
- }
- if ((p.X + 1) < Height)
- {
- down = true;
- _field[p.X, p.Y + 1]++;
- }
- if (up)
- {
- if (left)
- _field[p.X - 1, p.Y - 1]++;
- if(right)
- _field[p.X + 1, p.Y - 1]++;
- }
- if (down)
- {
- if (left)
- _field[p.X - 1, p.Y + 1]++;
- if (right)
- _field[p.X + 1, p.Y + 1]++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement