Beispiel #1
0
        public static void BuildTownHall(Tile tile, Costs costs)
        {
            bool      isAllowed = true;
            Rectangle rectangle = new Rectangle(tile.Rect.X, tile.Rect.Y, tileSize * 2, tileSize * 2);
            int       tilePosX  = (tile.Rect.X) / tileSize + 1;
            int       tilePosY  = (tile.Rect.Y) / tileSize + 1;

            isAllowed = BuildingOperations.CheckIntersections(isAllowed, rectangle);

            if (tile.Type.Contains("grass") &&
                tileMap[tilePosX, tile.Rect.Y / tileSize].IsClear &&
                tileMap[tilePosX, tilePosY].IsClear &&
                tileMap[tile.Rect.X / tileSize, tilePosY].IsClear &&
                tileMap[tile.Rect.X / tileSize, tilePosY + 1].IsClear &&
                tileMap[tilePosX, tilePosY + 1].IsClear &&
                isAllowed &&
                tile.IsClear)
            {
                mechanics.Buildings.Add(new Townhall(buildingTileSheet.Sprite(TexturePackerMonoGameDefinitions.buildingAtlas.LargeSelect)
                                                     , new Vector2(tile.Rect.X, tile.Rect.Y)
                                                     , rectangle
                                                     , Actions.Townhall
                                                     , costs
                                                     ));

                // Set tiles underneath to not clear
                tileMap[tilePosX, tile.Rect.Y / tileSize].IsClear = false;
                tileMap[tilePosX, tilePosY].IsClear = false;
                tileMap[tile.Rect.X / tileSize, tilePosY].IsClear = false;
                tile.IsClear = false;

                // Add the first road pieces
                BuildRoad(tileMap[tile.Rect.X / tileSize, tilePosY + 1], true);
                BuildRoad(tileMap[tilePosX, tilePosY + 1], true);

                // Unlocks the first menu tier
                MenuBuilder.MenuTierOne();
                RemoveIntersectingTrees(rectangle);
            }
        }
Beispiel #2
0
        public static Actions BuildStuff(Actions mouseAction, Vector2 mousePositionInWorld)
        {
            foreach (Tile tile in tileMap)
            {
                if (tile != null && tile.Rect.Contains(mousePositionInWorld))
                {
                    if (mouseAction == Actions.Townhall)
                    {
                        // Only allowed to build it once
                        foreach (Building building in mechanics.Buildings)
                        {
                            if (building.Type == Actions.Townhall)
                            {
                                mouseAction = Actions.Nothing;
                                return(mouseAction);
                            }
                        }
                        BuildingOperations.BuildTownHall(tile, new Costs(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                        mouseAction = Actions.Nothing;
                    }
                    if (mouseAction == Actions.House)
                    {
                        BuildingOperations.BuildSmallBuilding(tile, mouseAction, Costs.HouseCosts());
                    }
                    if (mouseAction == Actions.Farm)
                    {
                        BuildingOperations.BuildLargeBuilding(tile, mouseAction, Costs.FarmCosts());
                    }
                    if (mouseAction == Actions.Woodcutter)
                    {
                        BuildingOperations.BuildSmallBuilding(tile, mouseAction, Costs.WoodcutterCosts());
                    }
                    if (mouseAction == Actions.Quarry)
                    {
                        BuildingOperations.BuildQuarry(tile, mouseAction, Costs.WoodcutterCosts());
                    }
                    if (mouseAction == Actions.Scientist)
                    {
                        BuildingOperations.BuildLargeBuilding(tile, mouseAction, Costs.ScientistCosts());
                    }
                    if (mouseAction == Actions.Brewery)
                    {
                        BuildingOperations.BuildLargeBuilding(tile, mouseAction, Costs.BreweryCosts());
                    }
                    if (mouseAction == Actions.Tavern)
                    {
                        BuildingOperations.BuildLargeBuilding(tile, mouseAction, Costs.TavernCosts());
                    }
                    if (mouseAction == Actions.Storage)
                    {
                        BuildingOperations.BuildLargeBuilding(tile, mouseAction, Costs.StorageCosts());
                    }
                    if (mouseAction == Actions.Road)
                    {
                        BuildingOperations.BuildRoad(tile, false);
                    }
                }
            }

            // Sort buildings for rendering later
            IOrderedEnumerable <Building> sortedBuildings = mechanics.Buildings.OrderBy(building => building.Position.Y);

            mechanics.Buildings = new List <Building>();
            foreach (Building building in sortedBuildings)
            {
                mechanics.Buildings.Add(building);
            }

            mechanics.MaxPop = mechanics.GetMaxPop();
            return(mouseAction);
        }