Beispiel #1
0
        public object Clone()
        {
            var clone = new MinesweeperBoard(Width, Height);

            for (var i = 0; i < Height; i++)
            {
                for (var j = 0; j < Width; j++)
                {
                    clone[i, j] = (MinesweeperCell)this[i, j].Clone();
                }
            }
            return(clone);
        }
 public void MinesweeperBoard_WholeBoardUncovered_WithNoMines()
 {
     int width = 50, height = 50;
     var board = new MinesweeperBoard(width, height, 0);
     for (var i = 0; i < width; i++)
     {
         for (var j = 0; j < height; j++)
         {
             if (board[i, j].Status == CellStatus.Uncovered)
             {
                 Assert.Fail("Board with no mines has invalid cell status");
             }
         }
     }
 }
 public void MinesweeperBoard_CascadesAllButOne_WithOneMine()
 {
     int width = 50, height = 50;
     var board = new MinesweeperBoard(width, height, 0);
     board[0, 0].Type = CellType.Mined;
     board.Uncover(25, 25, 0);
     var cascaded = 0;
     for (var i = 0; i < width; i++)
     {
         for (var j = 0; j < height; j++)
         {
             if (board[i, j].Status == CellStatus.Uncovered)
                 cascaded++;
         }
     }
     Assert.AreEqual(width * height - 1, cascaded, "Wrong number of cascaded cells");
 }
 public void MinesweeperBoard_Clone_PerformsDeepCopy()
 {
     int width = 50, height = 50, numMines = 10;
     var board = new MinesweeperBoard(width, height, numMines);
     var clone = (MinesweeperBoard) board.Clone();
     Assert.AreNotSame(board, clone, "Clone cannot produce same object reference");
     for (var i = 0; i < height; i++)
     {
         for (var j = 0; j < width; j++)
         {
             var original = board[i, j];
             var copied = clone[i, j];
             //Debug.WriteLine(original.Equals(copied) + " " + original.X + " " + original.Y + " " + original.Type + " " + original.Status + " " + copied.X + " " + copied.Y + " " + copied.Type + " " + copied.Status);
             Assert.IsTrue(board[i, j].Equals(clone[i, j]));
             Assert.AreNotSame(board[i, j], clone[i, j], "Clone copied a cell object reference");
         }
     }
 }
 public MinesweeperController(int width, int height, int numMines)
 {
     Board = new MinesweeperBoard(width, height, numMines);
 }
 public object Clone()
 {
     var clone = new MinesweeperBoard(Width, Height);
     for (var i = 0; i < Height; i++)
     {
         for (var j = 0; j < Width; j++)
         {
             clone[i, j] = (MinesweeperCell) this[i, j].Clone();
         }
     }
     return clone;
 }
Beispiel #7
0
 public MinesweeperController(int width, int height, int numMines)
 {
     Board = new MinesweeperBoard(width, height, numMines);
 }