Exemple #1
0
        private bool CanPlaceFigureOnRoad(ITile currentTile, CardinalDirection whereToGo, bool firstCall)
        {
            ITile neighborTile = TileUtils.GetNeighborTile(TileUtils.GetSurroundingTiles(currentTile), whereToGo);

            if (firstCall)
            {
                _firstTile = currentTile;
                if (IsEndOfRoad(currentTile))
                {
                    return(CanPlaceFigureOnRoad(currentTile, whereToGo, false));
                }
                else
                {
                    CardinalDirection otherSide = CardinalDirection.North;
                    for (int i = 0; i < 4; i++)
                    {
                        if (currentTile.Directions[i].Landscape == Landscape.Road && i != (int)whereToGo)
                        {
                            otherSide = (CardinalDirection)i;
                        }
                    }

                    return(CanPlaceFigureOnRoad(currentTile, whereToGo, false) &&
                           CanPlaceFigureOnRoad(currentTile, otherSide, false));
                }
            }

            this.CheckFigureOnTile(currentTile, (int)whereToGo);

            if (neighborTile == null || neighborTile.Position.Equals(_firstTile.Position))
            {
                return(_canPlaceFigure);
            }

            if (IsEndOfRoad(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.Road)
                {
                    this.CheckFigureOnTile(currentTile, i);
                    _canPlaceFigure = false;
                }
            }

            for (var i = 0; i < 4; i++)
            {
                if (neighborTile.Directions[i].Landscape == Landscape.Road && i != (int)TileUtils.GetOppositeDirection(whereToGo))
                {
                    return(CanPlaceFigureOnRoad(neighborTile, neighborTile.GetCardinalDirectionByIndex(i), false));
                }
            }

            return(_canPlaceFigure);
        }
 /// <summary>
 /// Search the given tile's sides for roads, and if it find one it will cal calculation on it
 /// </summary>
 /// <param name="result">Gets the current number of road tiles</param>
 /// <param name="neighborTile">The tile to be examined</param>
 /// <param name="sideNumber">The integer value of that CardinalDirection where we came from</param>
 /// <returns>The number of tiles found following the road</returns>
 private int SearchInTilesSides(int result, ITile neighborTile, int sideNumber)
 {
     for (int i = 0; i < 4; i++)
     {
         if (neighborTile.Directions[i].Landscape == Landscape.Road && i != sideNumber)
         {
             result += CalculateWithDirections(neighborTile, neighborTile.GetCardinalDirectionByIndex(i));
             break;
         }
     }
     return(result);
 }
        /// <summary>
        /// It is supposed to be called after IsFinishedRoad has at least one true value. With the parameters it is going to go, and find the end of road, which is just put down.
        /// </summary>
        /// <param name="currentTile">The tile which has just been put down</param>
        /// <param name="whereToGo">The direction where to search for end of road tile</param>
        /// <returns>The end of road tile found in the given direction. Null if there is no end of road tile</returns>
        private ITile SearchEndOfRoadTileInGivenDirection(ITile currentTile, CardinalDirection whereToGo)
        {
            ITile neighborTile = TileUtils.GetNeighborTile(TileUtils.GetSurroundingTiles(currentTile), whereToGo);

            if (neighborTile == null || IsEndOfRoad(neighborTile) || _firstTile.Position.Equals(neighborTile.Position))
            {
                _whereToGoAfterEndOfRoadFound = TileUtils.GetOppositeDirection(whereToGo);
                return(neighborTile);
            }

            for (var i = 0; i < 4; i++)
            {
                if (neighborTile.Directions[i].Landscape == Landscape.Road && i != (int)TileUtils.GetOppositeDirection(whereToGo))
                {
                    return(SearchEndOfRoadTileInGivenDirection(neighborTile, neighborTile.GetCardinalDirectionByIndex(i)));
                }
            }
            return(null);
        }
Exemple #4
0
        private ITile GetEndOfCastle(ITile currentTile, CardinalDirection whereToGo)
        {
            ITile neighborTile = TileUtils.GetNeighborTile(TileUtils.GetSurroundingTiles(currentTile), whereToGo);

            if (neighborTile == null || IsEndOfCastle(neighborTile) || _firstTile.Position.Equals(neighborTile.Position) || CheckedTiles.Contains(neighborTile))
            {
                _whereToGoAfterEndFound = TileUtils.GetOppositeDirection(whereToGo);
                return(neighborTile);
            }

            CheckedTiles.Add(neighborTile);

            for (var i = 0; i < 4; i++)
            {
                if (neighborTile.Directions[i].Landscape == Landscape.Castle && i != (int)TileUtils.GetOppositeDirection(whereToGo))
                {
                    return(GetEndOfCastle(neighborTile, neighborTile.GetCardinalDirectionByIndex(i)));
                }
            }
            return(null);
        }
Exemple #5
0
        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));
        }