Beispiel #1
0
        public void Unit_Click(object sender, EventArgs e)
        {
            int    x, y;
            Button b = (Button)sender;

            x = b.Location.X / 20;
            y = b.Location.Y / 20;
            foreach (Unit u in units)
            {
                if (u is RangedUnit) // allows for the button to display information to the text box for the ranged unit
                {
                    RangedUnit ru = (RangedUnit)u;
                    if (ru.XPos == x && ru.YPos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = ru.ToString();
                    }
                }
                else if (u is MeleeUnit)  // allows for the button to display information to the text box for the melee unit
                {
                    MeleeUnit mu = (MeleeUnit)u;
                    if (mu.XPos == x && mu.YPos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = mu.ToString();
                    }
                }

                else if (u is WizardUnit) // allows for the button to display information to the text box for the wizard unit
                {
                    WizardUnit wu = (WizardUnit)u;
                    if (wu.XPos == x && wu.YPos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = wu.ToString();
                    }
                }
            }

            foreach (Building B in buildings)
            {
                if (B is FactoryBuilding)
                {
                    FactoryBuilding fb = (FactoryBuilding)B; // allows for the button to display information to the text box for the factory building
                    if (fb.XPos == x && fb.YPos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = fb.ToString();
                    }
                }
                else if (B is ResourceBuilding)
                {
                    ResourceBuilding rb = (ResourceBuilding)B; // allows for the button to display information to the text box for the resource building
                    if (rb.XPos == x && rb.YPos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = rb.ToString() + "           Resources Produced: " + resources;
                    }
                }
            }
        }