public void UnblockAllTemporarilyBlockedTiles() { foreach (var tile in AllTiles.Where(a => a.IsTemporarilyBlocked)) { tile.IsTemporarilyBlocked = false; } }
/// <summary> /// Places the miens randomly on the board /// </summary> /// <param name="tile">the tile to not put bomb in because it is the first tile clicked</param> private void PlaceMines(Tile tile) { Progress = GameProgress.InProgress; //Place mines after the first mine has been uncovered var placedMines = 0; Random rand = new Random(); while (placedMines != TotalMines) { int xRow = rand.Next(0, Rows - 1); int xCol = rand.Next(0, Columns - 1); foreach (var t in AllTiles.Where(singleTile => singleTile.Row == xRow && singleTile.Column == xCol)) { if (t != tile && t.Type != TileType.Bomb) { AllTiles[AllTiles.IndexOf(t)].Type = TileType.Bomb; placedMines++; } } } //Storing instances of adjacentTiles in every tile and changing foreach (var singleTile in AllTiles) { singleTile.InitializeAdjacentTile(this); singleTile.ChangeContent(); } stopwatch.Start(); dispatcherTimer.Start(); }
public void CreateGrid() { var tiles = AllTiles.Where(x => x.Point != null); int xMin = tiles.Min(x => x.Point.X); int xMax = tiles.Max(x => x.Point.X); int yMin = tiles.Min(x => x.Point.Y); int yMax = tiles.Max(x => x.Point.Y); for (int i = yMin, iGrid = 0; i <= yMax; i++, iGrid++) { Grid.Add(new List <Tile>()); for (int j = xMin; j <= xMax; j++) { Tile t = tiles.Where(x => x.Point.X == j && x.Point.Y == i).First(); Grid[iGrid].Add(t); } } }