Пример #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="level">level data</param>
        /// <param name="x">horizontal position</param>
        /// <param name="y">vertical position</param>
        /// <param name="canBuild">whether or not this tile can be built on presently</param>
        public GameTileMenu(Level level, int x, int y, Boolean canBuild)
        {
            InitializeComponent();

            // Set fields
            this.level = level;
            this.x = x;
            this.y = y;

            // Apply data to labels
            tileName.Content = level.GetTileName(x, y);
            typeLabel.Content = level.GetTileType(x, y);

            // Draw the tile or tower
            string path;
            if (level.IsTower(x, y))
                path = directory + "Tower" + level.GetTileName(x, y);
            else
                path = directory + "Tile" + level.GetTileName(x, y);
            Canvas tile = ControlManager.CreateCanvas(path, 4, 4, 16);
            ContentRoot.Children.Add(tile);

            // Add buttons

            // If it is a tower, add the "Sell" button
            // If the tower can be upgraded, add the "Upgrade" button
            if (level.IsTower(x, y))
            {
                Button option = CreateOptionButton("Sell Tower", 8, 60, 8);
                option.Click += Sell_Click;
                ContentRoot.Children.Add(option);

                // Check if the tower can be upgraded
                // Needs enough money and a tower to upgrade into
                foreach (Tower t in level.TowerList)
                {
                    if (t.baseTower.Equals(level.GetTileName(x, y)) && level.Money >= t.buildCost)
                    {
                        Button upgrade = CreateOptionButton("Upgrade", 8, 95, 8);
                        upgrade.Click += Upgrade_Click;
                        Height = Height + 35;
                        ContentRoot.Children.Add(upgrade);
                        break;
                    }
                }
            }

            // If it is a tile and it is buildable and enough money is owned to build at least one tower,
            // add the "Build" button
            else if (level.CanBuild && level.IsBuildable(x, y) && canBuild)
            {
                Button option = CreateOptionButton("Build Tower", 8, 60, 8);
                option.Click += Build_Click;
                ContentRoot.Children.Add(option);
            }
            else
                Height = Height - 35;
        }