Пример #1
0
        public void Building_Click(object sender, EventArgs e)
        {
            int    x, y;
            Button b = (Button)sender;

            x = b.Location.X / 20;
            y = b.Location.Y / 20;
            foreach (Building bu in buildings)
            {
                if (bu is FactoryBuilding)
                {
                    FactoryBuilding fb = (FactoryBuilding)bu;
                    if (fb.Xpos == x && fb.Ypos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = fb.ToString();
                    }
                }
                else if (bu is ResourceBuilding)
                {
                    ResourceBuilding rb = (ResourceBuilding)bu;
                    if (rb.Xpos == x && rb.Ypos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = rb.ToString();
                    }                                                           //when a building is clicked, ToString is called
                }
            }
        }
Пример #2
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)
                {
                    RangedUnit ru = (RangedUnit)u;
                    if (ru.Xpos == x && ru.Ypos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = ru.ToString();
                    }
                }
                else if (u is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)u;
                    if (mu.Xpos == x && mu.Ypos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = mu.ToString();
                    }
                }
                else if (u is WizardUnit)
                {
                    WizardUnit wu = (WizardUnit)u;
                    if (wu.Xpos == x && wu.Ypos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = wu.ToString();
                    }
                }
            }
            foreach (Building bu in buildings)
            {
                if (bu is FactoryBuilding)
                {
                    FactoryBuilding fb = (FactoryBuilding)bu;
                    if (fb.Xpos == x && fb.Ypos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = fb.ToString();
                    }
                }
                else if (bu is ResourceBuilding)
                {
                    ResourceBuilding rb = (ResourceBuilding)bu;
                    if (rb.Xpos == x && rb.Ypos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = rb.ToString();
                    }                                                           //when a building is clicked, ToString is called
                }
            }
        }