Exemple #1
0
        public List <IFigure> GetFiguresToGiveBack(ITile currentTile, CardinalDirection whereToGo, bool firstCall)
        {
            _figuresOnTiles.Clear();
            bool isChurchWithRoad = false;

            foreach (var side in currentTile.Directions)
            {
                if (side.Landscape == Landscape.Road)
                {
                    isChurchWithRoad = true;
                }
            }

            if ((currentTile.Speciality.Contains(Speciality.Colostor) || currentTile is Church) && isChurchWithRoad)
            {
                if (firstCall)
                {
                    if (currentTile.CenterFigure != null)
                    {
                        _figuresOnTiles.Add(currentTile.CenterFigure);
                        currentTile.CenterFigure = null;
                    }
                }
                else
                {
                    /*
                     * _firstTile = currentTile;
                     * SearchFiguresOnCastle(currentTile, whereToGo);
                     */
                    if (currentTile.GetTileSideByCardinalDirection(whereToGo).Landscape == Landscape.Road)
                    {
                        SearchFiguresOnRoad(currentTile, whereToGo, true);
                    }
                }
            }
            else if (currentTile.Speciality.Contains(Speciality.Colostor) || currentTile is Church)
            {
                if (currentTile.CenterFigure != null)
                {
                    _figuresOnTiles.Add(currentTile.CenterFigure);
                    currentTile.CenterFigure = null;
                }
            }
            else
            {
                _firstTile = currentTile;

                SearchFiguresOnCastle(currentTile, whereToGo);

                if (currentTile.GetTileSideByCardinalDirection(whereToGo).Landscape == Landscape.Road)
                {
                    SearchFiguresOnRoad(currentTile, whereToGo, true);
                }
            }

            return(_figuresOnTiles);
        }
Exemple #2
0
        private void SearchFiguresOnRoad(ITile currentTile, CardinalDirection whereToGo, bool firstCall)
        {
            if (firstCall)
            {
                _firstTile = currentTile;
                if (IsEndOfRoad(currentTile) && currentTile.GetTileSideByCardinalDirection(whereToGo).Landscape == Landscape.Road)
                {
                    CheckFigureOnTile(currentTile, (int)whereToGo);
                    SearchFiguresOnRoad(currentTile, whereToGo, false);
                }
                else if (!IsEndOfRoad(currentTile) && currentTile.GetTileSideByCardinalDirection(whereToGo).Landscape == Landscape.Road &&
                         SearchEndOfRoadTileInGivenDirection(currentTile, whereToGo) != null)
                {
                    var firstTile = SearchEndOfRoadTileInGivenDirection(currentTile, whereToGo);
                    _firstTile = firstTile;
                    CheckFigureOnTile(_firstTile, (int)_whereToGoAfterEndFound);
                    SearchFiguresOnRoad(firstTile, _whereToGoAfterEndFound, false);
                }
            }
            else
            {
                var neighborTile = TileUtils.GetNeighborTile(TileUtils.GetSurroundingTiles(currentTile), whereToGo);

                if (neighborTile == null)
                {
                    _figuresOnTiles.Clear();
                    return;
                }

                if (IsEndOfRoad(neighborTile) || neighborTile.Position.Equals(_firstTile.Position))
                {
                    CheckFigureOnTile(neighborTile, (int)TileUtils.GetOppositeDirection(whereToGo));
                    return;
                }

                int sideNumber = (int)TileUtils.GetOppositeDirection(whereToGo);

                for (int i = 0; i < 4; i++)
                {
                    if (neighborTile.Directions[i].Landscape == Landscape.Road)
                    {
                        CheckFigureOnTile(neighborTile, i);
                    }
                }

                for (int i = 0; i < 4; i++)
                {
                    if (neighborTile.Directions[i].Landscape == Landscape.Road && i != sideNumber)
                    {
                        SearchFiguresOnRoad(neighborTile, neighborTile.GetCardinalDirectionByIndex(i), false);
                        break;
                    }
                }
            }
        }
Exemple #3
0
 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;
             }
         }
     }
 }
Exemple #4
0
        public static bool CheckFitOfTile(ITile tile, Dictionary <CardinalDirection, ITile> surroundingTiles)
        {
            if (surroundingTiles.Count == 0)
            {
                return(false);
            }
            foreach (var neighborTile in surroundingTiles)
            {
                Landscape currentTileLandscape  = tile.GetTileSideByCardinalDirection(neighborTile.Key).Landscape;
                Landscape neighborTileLandscape = neighborTile.Value.GetTileSideByCardinalDirection(GetOppositeDirection(neighborTile.Key)).Landscape;

                if (!currentTileLandscape.Equals(neighborTileLandscape))
                {
                    return(false);
                }
            }
            return(true);
        }