Esempio n. 1
0
        public bool CheckBuildingToBuild(Window window, ResourcesManager resources)
        {
            if (_buildSelected == false)
            {
                return(false);
            }

            if (_tab1Selected)
            {
                foreach (Sprite sprite in _tab1Sprite.Keys)
                {
                    if (sprite.GetGlobalBounds().Contains(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y))
                    {
                        _buildingTypeSprites.TryGetValue(sprite, out BuildingType building);
                        if (!resources.CheckResourcesNeeded(building))
                        {
                            return(false);
                        }
                        _mapCtx.ChosenBuilding = building;
                        window.SetMouseCursorVisible(false);
                        _mouseSprite          = new Sprite(sprite);
                        _mouseSprite.Position = new Vector2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y);
                        return(true);
                    }
                }
            }
            else if (_tab2Selected)
            {
                foreach (Sprite sprite in _tab2Sprite.Keys)
                {
                    if (sprite.GetGlobalBounds().Contains(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y))
                    {
                        _buildingTypeSprites.TryGetValue(sprite, out BuildingType building);
                        if (!resources.CheckResourcesNeeded(building))
                        {
                            return(false);
                        }
                        _mapCtx.ChosenBuilding = building;
                        window.SetMouseCursorVisible(false);
                        _mouseSprite          = new Sprite(sprite);
                        _mouseSprite.Position = new Vector2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y);
                        return(true);
                    }
                }
            }
            else if (_tab3Selected)
            {
                foreach (Sprite sprite in _tab3Sprite.Keys)
                {
                    if (sprite.GetGlobalBounds().Contains(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y))
                    {
                        _buildingTypeSprites.TryGetValue(sprite, out BuildingType building);
                        if (!resources.CheckResourcesNeeded(building))
                        {
                            return(false);
                        }
                        _mapCtx.ChosenBuilding = building;
                        window.SetMouseCursorVisible(false);
                        _mouseSprite          = new Sprite(sprite);
                        _mouseSprite.Position = new Vector2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y);
                        return(true);
                    }
                }
            }
            return(false);
        }