Пример #1
0
        public void Display(GroupBox grpBox)
        {
            grpBox.Controls.Clear();

            foreach (Unit u in units)
            {
                Button b = new Button();
                if (u is MeleeUnit) // Creates the buttons on the form to display the melee units
                {
                    MeleeUnit mu = (MeleeUnit)u;
                    b.Size     = new Size(20, 20);
                    b.Location = new Point(mu.XPos * width, mu.YPos * height);
                    b.Text     = mu.Symbol;
                    if (mu.Faction == 0)
                    {
                        b.ForeColor = Color.Red;
                    }
                    else
                    {
                        b.ForeColor = Color.Blue;
                    }
                }
                else if (u is RangedUnit)
                {
                    RangedUnit ru = (RangedUnit)u;  // Creates the buttons on the form to display the ranged units
                    b.Size     = new Size(20, 20);
                    b.Location = new Point(ru.XPos * width, ru.YPos * height);
                    b.Text     = ru.Symbol;
                    if (ru.Faction == 0)
                    {
                        b.ForeColor = Color.Red;
                    }
                    else
                    {
                        b.ForeColor = Color.Blue;
                    }
                }
                else if (u is WizardUnit)
                {
                    WizardUnit wu = (WizardUnit)u; // Creates the information link on the form to display the wizard units
                    b.Size      = new Size(20, 20);
                    b.Location  = new Point(wu.XPos * width, wu.YPos * height);
                    b.Text      = wu.Symbol;
                    b.ForeColor = Color.Green;
                }

                b.Click += Unit_Click;
                grpBox.Controls.Add(b);
            }



            foreach (Building b in buildings)
            {
                Button B = new Button();
                if (b is FactoryBuilding)
                {
                    FactoryBuilding fb = (FactoryBuilding)b;   // Creates the buttons on the form to display the factory buildings

                    if (unitSpawnTimer == fb.ProductionSpeed && resources != 0)
                    {
                        for (int i = 0; i < numBuildings; i++)
                        {
                            units.Add(fb.ProduceUnit(fb.Faction));
                            resources = resources - 20;
                        }

                        unitSpawnTimer = 0;
                    }


                    B.Size     = new Size(30, 30);
                    B.Location = new Point(fb.XPos * width, fb.YPos * height);
                    B.Text     = fb.Symbol;

                    if (fb.Faction == 0)
                    {
                        B.ForeColor = Color.Red;
                    }
                    else
                    {
                        B.ForeColor = Color.Blue;
                    }
                }
                else
                {
                    ResourceBuilding rb = (ResourceBuilding)b;  // Creates the buttons on the form to display the resource buildings

                    B.Size     = new Size(30, 30);
                    B.Location = new Point(rb.XPos * width, rb.YPos * height);
                    B.Text     = rb.Symbol;
                    rb.ResourceManagement();
                    resources = rb.resourceGenerated;

                    if (rb.Faction == 0)
                    {
                        B.ForeColor = Color.Red;
                    }
                    else
                    {
                        B.ForeColor = Color.Blue;
                    }
                }

                B.Click += Unit_Click;
                grpBox.Controls.Add(B);
            }
            unitSpawnTimer++;
            count = units.Count();
        }
Пример #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) // 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;
                    }
                }
            }
        }