public object Clone() { var clone = new TetriBricksGame(); foreach (BrickColumn bc in Columns) { var bcClone = new BrickColumn(); foreach (Brick b in bc.Bricks) { var bClone = new Brick(b.Row, b.Column, b.Color); bcClone.Bricks.Add(bClone); } clone.Columns.Add(bcClone); } return clone; }
public List<Brick> GetAdjacentBricks(Brick brick) { var foundBricks = new List<Brick>(); List<Brick> bricksToSearch = Bricks; FindNeighbors(brick, foundBricks, bricksToSearch); return foundBricks; }
private void FindNeighbors(Brick brick, List<Brick> foundBricks, List<Brick> bricksToSearch) { IEnumerable<Brick> neighbors = from b in bricksToSearch where b.Color == brick.Color && ( ((Math.Abs(b.Row - brick.Row) == 1) && (b.Column == brick.Column)) || ((Math.Abs(brick.Column - b.Column) == 1) && (brick.Row == b.Row)) ) select b; foreach (Brick b in neighbors.Where(b => !foundBricks.Contains(b))) { foundBricks.Add(b); FindNeighbors(b, foundBricks, bricksToSearch); } }
internal bool RemoveBrick(Brick brick) { // is there a future ? if (_moveHistory.Count - 1 > _currentMove) { _moveHistory.RemoveRange(_currentMove + 1, (_moveHistory.Count - 1 - _currentMove)); _currentMove = _moveHistory.Count - 1; } List<Brick> bricks = CurrentGame.GetAdjacentBricks(brick); if (bricks.Count > 1) { var gameStep = (TetriBricksGame) CurrentGame.Clone(); gameStep.RemoveBricks(bricks); gameStep.Score = gameStep.Score + CurrentGame.Score; _moveHistory.Add(gameStep); _currentMove = _moveHistory.Count - 1; return true; } else return false; }