Exemplo n.º 1
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (player != null)
            {
                if (selectedTower != null)
                {
                    if (selectedTower.LevelTower < 3)
                    {
                        priceForUpgarde = selectedTower.Value * selectedTower.LevelTower;

                        spriteBatch.Draw(texture, position, /*new Rectangle(0,0,texture.Width + 50, texture.Height),*/ Color.White);
                        string textButton = "Улучшить за " + priceForUpgarde.ToString();
                        spriteBatch.DrawString(font, textButton, this.GetCenterSprite, Color.Black);

                        if (pressed)
                        {
                            if (player.Gold >= priceForUpgarde)
                            {
                                player.Gold -= priceForUpgarde;
                                selectedTower.LevelTower++;
                                selectedTower.AddOrDeleteWeightToMap(map, false); // Сначала удаляем будто, а затем ставим заново с новым весом)
                                selectedTower.LevelUp();
                                selectedTower.AddOrDeleteWeightToMap(map, true);
                            }
                            colorButton = Color.Red;
                        }
                        else
                        {
                            colorButton = Color.White;
                        }
                    }
                    else
                    {
                        spriteBatch.DrawString(font, "Башня максимального уровня", new Vector2(position.X + 5, position.Y + 5), Color.Black);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void SetTower()
        {
            MouseState mouse = Mouse.GetState();

            if (mouse.LeftButton == ButtonState.Pressed)
            {
                int cellX = mouse.X / 64;
                int cellY = mouse.Y / 64;
                if (typeOfAction == 1 && gold >= ArrowTower.GetPrice || typeOfAction == 2 && gold >= FrostTower.GetPrice || typeOfAction == 3 && gold >= FireTower.GetPrice) // действие установки башен 1 -обычные 2 фрост
                {
                    if (level.ClickOnMAp(cellX, cellY))
                    {
                        if (!CellWithTower(cellX, cellY) && level.map[cellX, cellY] != 2 && level.map[cellX, cellY] != 3 && level.map[cellX, cellY] != 1) // пустое место или рядом с башней (лучше противоположное условие сделать)
                        {
                            cellX = cellX * 64;
                            cellY = cellY * 64;
                            Vector2 pos = new Vector2(cellX, cellY);
                            foreach (TowerTextureStorage tTS in towerTextureStorages)
                            {
                                if (typeOfAction == tTS.Key)
                                {
                                    towerTexture  = tTS.TowerTexture;
                                    bulletTexture = tTS.BulletTexture;
                                    break;
                                }
                            }
                            switch (typeOfAction)
                            {
                            case 1:
                                nowAddTower = new ArrowTower(pos, towerTexture, bulletTexture);
                                break;

                            case 2:
                                nowAddTower = new FrostTower(pos, towerTexture, bulletTexture);
                                break;

                            case 3:
                                nowAddTower = new FireTower(pos, towerTexture, bulletTexture);
                                break;
                            }
                            towers.Add(nowAddTower);
                            gold -= nowAddTower.Value;
                            nowAddTower.AddOrDeleteWeightToMap(level.map, true);
                            Game1.sounds["buildingTower"].Play();
                        }
                        else
                        {
                            ;//Клетка занята или в ней нельзя строить
                        }
                    }
                }
            }
            if (mouse.RightButton == ButtonState.Pressed) // Продажа башни
            {
                int cellX = mouse.X / 64;
                int cellY = mouse.Y / 64;
                if (level.ClickOnMAp(cellX, cellY))
                {
                    if (CellWithTower(cellX, cellY))
                    {
                        foreach (Tower tower in towers)
                        {
                            if (new Vector2(cellX, cellY) == new Vector2(tower.Position.X / 64, tower.Position.Y / 64))
                            {
                                RemoveTower(tower);
                                Game1.sounds["deleteTower"].Play();
                                tower.AddOrDeleteWeightToMap(level.map, false);
                                gold += tower.Value / 2;
                                if (tower == upgradeButton.GetSelectedTower)
                                {
                                    upgradeButton.GetSelectedTower = null;
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }