Esempio n. 1
0
        public IGameField Build()
        {
            if (ShipsLeft.Values.Any(x => x != 0))
            {
                return(null);
            }

            var newField = new IGameCell[Size.Height, Size.Width];

            foreach (var position in this.EnumeratePositions())
            {
                if (newField.GetValue(position) != null)
                {
                    continue;
                }

                if (!this[position])
                {
                    newField.SetValue(position, new EmptyCell(position));
                    continue;
                }

                var curShip = new Ship(EnumerateReadyShipCells(position));
                foreach (var piece in curShip.Pieces)
                {
                    newField.SetValue(piece.Position, piece);
                }
            }

            return(new GameField(Rules,
                                 position => newField.GetValue(position)));
        }
Esempio n. 2
0
 public GameCell(GameCell cell)
 {
     Row      = cell.Row;
     Column   = cell.Column;
     Type     = cell.Type;
     Color    = cell.Color;
     BindCell = cell.BindCell;
 }
Esempio n. 3
0
        public void Clear()
        {
            Type  = GameCellType.None;
            Color = GameCellColor.None;

            // Связанный блок
            if (BindCell != null)
            {
                BindCell.BindCell = null;
            }
            BindCell = null;
        }
Esempio n. 4
0
 public GameCell(int rowIndex,
                 int columnIndex,
                 GameCellType type   = GameCellType.None,
                 GameCellColor color = GameCellColor.None,
                 IGameCell bindCell  = null)
 {
     Row      = rowIndex;
     Column   = columnIndex;
     Type     = type;
     Color    = color;
     BindCell = bindCell;
 }
Esempio n. 5
0
        // Костылёк (ANTI DRY!)
        private static bool CanFallDownAnotherCell(IGameCell cell, IGameField gameField)
        {
            if (cell.Row + 1 == gameField.Height)
            {
                return(false);
            }

            //// Для падения одиночных блоков (Если это пустой блок или вирус, то это к нему отношения не имеет)
            if (cell.Type == GameCellType.None || cell.Type == GameCellType.Virus)
            {
                return(false);
            }

            if (gameField[cell.Row + 1, cell.Column].Type != GameCellType.None)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
 protected virtual bool Equals(IGameCell other)
 {
     return
         (Equals(Position, other.Position) &&
          Equals(Damaged, other.Damaged));
 }