Ejemplo n.º 1
0
        private void OnLeftMouseButtonPressed()
        {
            if (UserInterface.TargetEntity == null && gameMap.HoveredTile != null &&
                defenceMenu.SelectedItem != null)
            {
                var tile = gameMap.HoveredTile;
                if (defenceMenu.SelectedItem.Cost <= stats.Points
                    // Make sure the tile does not contain any objects
                    && !(wallManager.CheckContainsWall(tile, out _) ||
                         defenceManager.CheckContainsDefence(tile) ||
                         trapManager.CheckContainsTrap(tile) ||
                         enemyManager.CheckTileContainsEnemy(tile) ||
                         castle.ContainsTile(tile)))
                {
                    if (defenceMenu.SelectedItem.Name == DefenceTypes.Wall)
                    {
                        wallManager.CreateWall(gameMap.HoveredTile);
                    }
                    else if (defenceMenu.SelectedItem.Name == DefenceTypes.Cannon)
                    {
                        defenceManager.CreateDefence(DefenceTypes.Cannon, gameMap.HoveredTile);
                    }
                    else if (defenceMenu.SelectedItem.Name == DefenceTypes.Spikes)
                    {
                        trapManager.CreateTrap(DefenceTypes.Spikes, gameMap.HoveredTile);
                    }

                    stats.Points -= defenceMenu.SelectedItem.Cost;

                    if (preferences.IsAudioEnabled)
                    {
                        itemPlacedSound.Play();
                    }
                }
            }
        }