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))); }
public GameCell(GameCell cell) { Row = cell.Row; Column = cell.Column; Type = cell.Type; Color = cell.Color; BindCell = cell.BindCell; }
public void Clear() { Type = GameCellType.None; Color = GameCellColor.None; // Связанный блок if (BindCell != null) { BindCell.BindCell = null; } BindCell = null; }
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; }
// Костылёк (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); }
protected virtual bool Equals(IGameCell other) { return (Equals(Position, other.Position) && Equals(Damaged, other.Damaged)); }