Example #1
0
        public bool CanBuildBuilding(OffsetAndRotation offsetAndRotation, RotatedBuilding rotatedBuilding)
        {
            for (int x = 0; x < rotatedBuilding.Width; x++)
            {
                for (int y = 0; y < rotatedBuilding.Height; y++)
                {
                    var tilePos = offsetAndRotation.Offset + new Integer2(x, y);
                    var tile    = this[tilePos];

                    if (tile == null)
                    {
                        return(false);
                    }

                    string resourceAtPos = rotatedBuilding[x, y];

                    if (resourceAtPos == null)
                    {
                        continue;
                    }

                    if (tile.Resource != resourceAtPos)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #2
0
        public IEnumerable <OffsetAndRotation> AllBuildableLocations(BuildingTemplate buildingTemplate, IntegerRect?rect = null)
        {
            int boardWidth  = Width;
            int boardHeight = Height;

            var boundingRect = rect ?? new IntegerRect(0, 0, boardWidth, boardHeight);

            foreach (var orientation in buildingTemplate.MeaningfulOrientations())
            {
                var rotatedBuilding = new RotatedBuilding(buildingTemplate, orientation);

                int availableXOffset = boundingRect.xMax - rotatedBuilding.Width + 1;
                int availableYOffset = boundingRect.yMax - rotatedBuilding.Height + 1;

                for (int buildingOffsetX = boundingRect.x; buildingOffsetX < availableXOffset; buildingOffsetX++)
                {
                    for (int buildingOffsetY = boundingRect.y; buildingOffsetY < availableYOffset; buildingOffsetY++)
                    {
                        var buildLocation = new OffsetAndRotation(new Integer2(buildingOffsetX, buildingOffsetY), orientation);

                        if (CanBuildBuilding(buildLocation, rotatedBuilding))
                        {
                            yield return(buildLocation);
                        }
                    }
                }
            }
        }