/// <summary> /// Cell factory implementation. /// </summary> /// <param name="cellType">Cell type.</param> /// <returns>Required cell.</returns> public static ICell CreateCell(CellType cellType) { //// Uses "lazy initialization". ICell cell; switch (cellType) { case CellType.EmptyCell: cell = new EmptyCell(); cell.CellView = CellView.Empty; break; case CellType.Bomb: int bombSize = RandomGenerator.GetRandomNumber(MIN_BOMB_SIZE, MAX_BOMB_SIZE); cell = new BombCell(bombSize); cell.CellView = (CellView)bombSize + ASCII_VIEW_OFFSET; break; case CellType.BlownCell: cell = new BlownCell(); cell.CellView = CellView.Blown; break; default: throw new ArgumentException("Invalid cell type give to the cell factory"); } return cell; }
/// <summary> /// Cell factory implementation. /// </summary> /// <param name="cellType">Cell type.</param> /// <returns>Required cell.</returns> public static ICell CreateCell(CellType cellType) { //// Uses "lazy initialization". ICell cell; switch (cellType) { case CellType.EmptyCell: cell = new EmptyCell(); cell.CellView = CellView.Empty; break; case CellType.Bomb: int bombSize = RandomGenerator.GetRandomNumber(MIN_BOMB_SIZE, MAX_BOMB_SIZE); cell = new BombCell(bombSize); cell.CellView = (CellView)bombSize + ASCII_VIEW_OFFSET; break; case CellType.BlownCell: cell = new BlownCell(); cell.CellView = CellView.Blown; break; default: throw new ArgumentException("Invalid cell type give to the cell factory"); } return(cell); }
public void CellsTestIfEmptyCellIsCloned() { EmptyCell emptyCell = new EmptyCell(); emptyCell.X = 2; emptyCell.Y = 3; emptyCell.Color = Color.White; emptyCell.CellView = CellView.Bomb1; ICell clonedEmptyCell = emptyCell.Clone(); Assert.AreEqual(emptyCell.X, clonedEmptyCell.X, "X coordinate has not cloned."); Assert.AreEqual(emptyCell.Y, clonedEmptyCell.Y, "Y coordinate has not cloned."); Assert.AreEqual(emptyCell.Color, clonedEmptyCell.Color, "Cell Color has not cloned."); Assert.AreEqual(emptyCell.CellView, clonedEmptyCell.CellView, "CellView Color has not cloned."); }
public void CellsTestIfEmptyCellYIsPositive() { var cell = new EmptyCell(); cell.Y = -1; }
public void CellsTestIfEmptyCellXIsPositive() { var emptyCell = new EmptyCell(); emptyCell.X = -1; }