private void SearchFiguresOnCastle(ITile currentTile, CardinalDirection whereToGo) { CheckedTiles.Clear(); _starterWhereToGo = whereToGo; _firstTile = currentTile; CheckedTiles.Add(currentTile); if (IsEndOfCastle(currentTile)) { if (currentTile.GetTileSideByCardinalDirection(whereToGo).Landscape == Landscape.Castle) { CheckFigureOnTile(currentTile, (int)whereToGo); CalculateWithEndOfCastle(currentTile, whereToGo); } } else { for (int i = 0; i < 4; i++) { if (currentTile.Directions[i].Landscape == Landscape.Castle) { _foundEndofRoad.Clear(); _firstTile = GetEndOfCastle(currentTile, (CardinalDirection)i); if (_firstTile != null) { CheckedTiles.Clear(); CheckedTiles.Add(_firstTile); CheckFigureOnTile(_firstTile, (int)_whereToGoAfterEndFound); CalculateWithEndOfCastle(_firstTile, _whereToGoAfterEndFound); } break; } } } }
public bool CanPlaceFigure(ITile currentTile, CardinalDirection whereToGo, bool firstCall) { _figuresOnTiles.Clear(); CheckedTiles.Clear(); _canPlaceFigure = true; switch (currentTile.Directions[(int)whereToGo].Landscape) { case Landscape.Castle: return(CanPlaceFigureOnCastle(currentTile, whereToGo, firstCall)); case Landscape.Field: return(true); case Landscape.Road: return(CanPlaceFigureOnRoad(currentTile, whereToGo, firstCall)); default: return(true); } }
private bool CanPlaceFigureOnCastle(ITile currentTile, CardinalDirection whereToGo, bool firstCall) { ITile neighborTile = TileUtils.GetNeighborTile(TileUtils.GetSurroundingTiles(currentTile), whereToGo); if (firstCall) { _currentITile = currentTile; CheckedTiles.Clear(); _figuresOnTiles.Clear(); _canPlaceFigure = true; } if (_currentITile == null) { _canPlaceFigure = false; } if (IsChecked(_currentITile, CheckedTiles)) { return(_canPlaceFigure); } if (firstCall) { if (IsEndOfCastle(currentTile)) { return(CanPlaceFigureOnCastle(currentTile, whereToGo, false)); } else { List <bool> results = new List <bool>(); for (int i = 0; i < 4; i++) { if (currentTile.Directions[i].Landscape == Landscape.Castle && i != (int)whereToGo) { results.Add(CanPlaceFigureOnCastle(currentTile, (CardinalDirection)i, false)); } } return(results.All(e => e)); } } CheckedTiles.Add(currentTile); CheckFigureOnTile(currentTile, (int)whereToGo); if (neighborTile == null) { return(_canPlaceFigure); } if (IsEndOfCastle(neighborTile)) { CheckFigureOnTile(neighborTile, (int)TileUtils.GetOppositeDirection(whereToGo)); return(neighborTile.Directions[(int)TileUtils.GetOppositeDirection(whereToGo)].Figure == null && _canPlaceFigure); } for (int i = 0; i < 4; i++) { if (neighborTile.Directions[i].Figure != null && neighborTile.Directions[i].Landscape == Landscape.Castle) { CheckFigureOnTile(currentTile, i); _canPlaceFigure = false; } } var resultOfPlacementChecking = new List <bool>(); for (var i = 0; i < 4; i++) { if (neighborTile.Directions[i].Landscape == Landscape.Castle && i != (int)TileUtils.GetOppositeDirection(whereToGo)) { CheckFigureOnTile(neighborTile, i); resultOfPlacementChecking.Add(CanPlaceFigureOnCastle(neighborTile, neighborTile.GetCardinalDirectionByIndex(i), false)); } } return(resultOfPlacementChecking.All(e => e)); }