public void TestNumberSurroundingMines() { GameIni game = new GameIni(); game.PopulateGrid(1, 2, 1); game.Board[0, 0] = "M"; Assert.AreEqual(1, game.NumberOfSurroundingMines(0, 1, 1, 1)); }
public void TestMinesPlaced() { GameIni game = new GameIni(); game.PopulateGrid(5, 10, 5); int rows = 5; int columns = 10; int countMines = 0; for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { if (game.Board[r, c] == "M") { countMines++; } } } Assert.AreEqual(5, countMines); }
public void TestPopulateGrid() { GameIni game = new GameIni(); game.PopulateGrid(5, 10, 5); int rows = 5; int columns = 10; int countEmpty = 0; for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { if (game.Board[r, c] == " ") { countEmpty++; } } } Assert.AreEqual(0, countEmpty); }
public void CreateBombGrid() { rightFlag = 0; Button b = new Button(); elapsed = 0; timer.Start(); if (BombGrid != null) { MainGrid.Children.Remove(BombGrid); } bombslefttxbx.Text = Convert.ToString(bombs); BombGrid = new Grid { Width = (new Mine()).Width * columns + 120, Height = (new Mine()).Height * rows + 60, //BombGrid.HorizontalAlignment = HorizontalAlignment.Center; //BombGrid.VerticalAlignment = VerticalAlignment.Bottom; Margin = new Thickness(5, 105, 5, 5) }; MainGrid.Children.Add(BombGrid); bool ok3bv = false; for (int r = 0; r < rows; r++) { BombGrid.RowDefinitions.Add(new RowDefinition()); } for (int c = 0; c < columns; c++) { BombGrid.ColumnDefinitions.Add(new ColumnDefinition()); } GameIni game = new GameIni(); ButtonGrid = game.PopulateGrid(rows, columns, bombs); game.BVCalc(ButtonGrid, rows, columns); do { //GameIni game = new GameIni(); //ButtonGrid = game.PopulateGrid(rows, columns, bombs); if (level == "Beginner") { if (game.BVCalc(ButtonGrid, rows, columns) >= 45) { ok3bv = true; } else { ButtonGrid = game.PopulateGrid(rows, columns, bombs); } } else if (level == "Intermediate") { if (game.BVCalc(ButtonGrid, rows, columns) >= 120) { ok3bv = true; } else { ButtonGrid = game.PopulateGrid(rows, columns, bombs); } } else if (level == "Advanced") { if (game.BVCalc(ButtonGrid, rows, columns) >= 290) { ok3bv = true; } else { ButtonGrid = game.PopulateGrid(rows, columns, bombs); } } } while (!ok3bv); for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { if (ButtonGrid[r, c] == "M") { Mine block = new Mine(); block.Background = Brushes.DarkGreen; //block.Content = "M"; Grid.SetRow(block, r); Grid.SetColumn(block, c); BombGrid.Children.Add(block); block.Click += Mouse_LeftClick; block.MouseRightButtonUp += Mouse_RightClick; } else if (ButtonGrid[r, c] == " ") { Tiles tile = new Tiles(); tile.Background = Brushes.DarkGreen; Grid.SetRow(tile, r); Grid.SetColumn(tile, c); tile.number = ButtonGrid[r, c]; BombGrid.Children.Add(tile); tile.Click += Mouse_LeftClick; tile.MouseRightButtonUp += Mouse_RightClick; } else { Tiles tile = new Tiles(); tile.Background = Brushes.DarkGreen; Grid.SetRow(tile, r); Grid.SetColumn(tile, c); tile.number = ButtonGrid[r, c]; BombGrid.Children.Add(tile); tile.Click += Mouse_LeftClick; tile.MouseRightButtonUp += Mouse_RightClick; } } } }