Beispiel #1
0
        /// <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);
        }
Beispiel #3
0
        public void CellsTestIfBlowCellIsCloned()
        {
            BlownCell blownCell = new BlownCell();
            blownCell.X = 2;
            blownCell.Y = 3;
            blownCell.Color = Color.White;
            blownCell.CellView = CellView.Bomb1;

            ICell clonedBlownCell = blownCell.Clone();

            Assert.AreEqual(blownCell.X, clonedBlownCell.X, "X coordinate has not cloned.");
            Assert.AreEqual(blownCell.Y, clonedBlownCell.Y, "Y coordinate has not cloned.");
            Assert.AreEqual(blownCell.Color, clonedBlownCell.Color, "Cell Color has not cloned.");
            Assert.AreEqual(blownCell.CellView, clonedBlownCell.CellView, "CellView Color has not cloned.");
        }
Beispiel #4
0
 public void CellsTestIfBlownCellYIsPositive()
 {
     var cellBlown = new BlownCell();
     cellBlown.Y = -1;
 }
Beispiel #5
0
 public void CellsTestIfBlownCellXIsPositive()
 {
     var blownCell = new BlownCell();
     blownCell.X = -1;
 }
Beispiel #6
0
        public void TestIfCellWhiteColorIsCorrectlySetDisplayed()
        {
            BlownCell blownCell = new BlownCell();
            blownCell.X = 2;
            blownCell.Y = 3;
            blownCell.Color = Color.White;
            blownCell.CellView = CellView.Bomb1;

            string cellToString = blownCell.ToString();

            Assert.AreEqual(cellToString, " 1 ", string.Format("!{0}!", cellToString));
        }