private void Victory() { var list = new List <Point <int> >(); for (var r = 0; r < this.Minesweeper.Tiles.Width; r++) { for (var c = 0; c < this.Minesweeper.Tiles.Height; c++) { var tile = this.Minesweeper.Tiles[r, c]; if (tile.Type == TileType.Mine && tile.ExtraTileData != ExtraTileData.Flag) { this.SetTile(r, c, new Tile(TileType.Mine, false, ExtraTileData.Flag)); list.Add(new Point <int>(r, c)); } } } this.Minesweeper.MinesRemaining = 0; if (list.Count > 0) { this.TilesToUpdate = AnimatedTilesCollection.Create(list); } this.IsVictory = true; this.Mediator.Notify(ViewModelMessages.Victory); }
private void SelectSurroundingTiles(TileEventArgs e) { var tiles = (from tilePoint in this.GetSurroundingTiles(e.X, e.Y) let tile = this.Minesweeper.Tiles[tilePoint.X, tilePoint.Y] where (!tile.Shown) && (tile.ExtraTileData == ExtraTileData.None) select tilePoint).ToList(); this.SelectedTiles = tiles.Count > 0 ? AnimatedTilesCollection.Create(tiles) : null; }
private void UpdateTileListAndCheckForVictory(List <Point <int> > updateTileList) { this.GameStatistics[Statistic.Moves] = (int)this.GameStatistics[Statistic.Moves] + 1; this.TilesToUpdate = AnimatedTilesCollection.Create(updateTileList); if (this.revealedSpaces == this.targetSpaceCount) { this.Victory(); } }
/// <summary> /// This method is called on GameOver to end the game and reveal the mines. /// </summary> private void GameOver(int clickX, int clickY) { var list = new List <Point <int> >(); for (var r = 0; r < this.Minesweeper.Tiles.Width; r++) { for (var c = 0; c < this.Minesweeper.Tiles.Height; c++) { var tile = this.Minesweeper.Tiles[r, c]; if (tile.Type == TileType.Mine) { this.SetTile(r, c, new Tile(tile.Type, true)); list.Add(new Point <int>(r, c)); } } } this.IsGameOver = true; this.HoverTile = new Point <int>(-1, -1); this.TilesToUpdate = AnimatedTilesCollection.Create(list); if (clickX > -1 && clickY > 0) { this.SelectionBrush = TileBoardViewModel.mineClickBrush; var tile = this.Minesweeper.Tiles[clickX, clickY]; // mine was clicked, causing game over if (tile.Type == TileType.Mine) { this.SelectedTiles = AnimatedTilesCollection.Create(new List <Point <int> >(1) { new Point <int>(clickX, clickY) }); } else { var mineTiles = (from tilePoint in this.GetSurroundingTiles(clickX, clickY) let surroundingTile = this.Minesweeper.Tiles[tilePoint.X, tilePoint.Y] where (surroundingTile.Type == TileType.Mine) select tilePoint).ToList(); this.SelectedTiles = AnimatedTilesCollection.Create(mineTiles); } } this.Mediator.Notify(ViewModelMessages.GameOver); }
private void TileTapRightDown(TileEventArgs e) { if (!this.boardInitialized) { return; } if (!e.Tile.Shown) { if (e.Tile.ExtraTileData == ExtraTileData.None) { this.SetTile(e.X, e.Y, new Tile(e.Tile.Type, e.Tile.Shown, ExtraTileData.Flag)); this.Minesweeper.MinesRemaining--; this.GameStatistics[Statistic.FlagsPlaced] = (int)this.GameStatistics[Statistic.FlagsPlaced] + 1; } else if (e.Tile.ExtraTileData == ExtraTileData.Flag) { this.SetTile( e.X, e.Y, new Tile( e.Tile.Type, e.Tile.Shown, (this.areQuestionMarksEnabled) ? ExtraTileData.QuestionMark : ExtraTileData.None)); this.Minesweeper.MinesRemaining++; this.GameStatistics[Statistic.FlagsPlaced] = (int)this.GameStatistics[Statistic.FlagsPlaced] - 1; } else // ExtraTileData.QuestionMark { this.SetTile(e.X, e.Y, new Tile(e.Tile.Type, e.Tile.Shown, ExtraTileData.None)); } this.TilesToUpdate = AnimatedTilesCollection.Create(new List <Point <int> >(1) { new Point <int>(e.X, e.Y) }); } }