//Method for the buildings to generate units
 public Unit BuildUnit(int factions)
 {
     //Determines Faction Type
     if (faction == 1)
     {
         //Determines what type of unit to generate
         if (unitType == "Melee")
         {
             //Creates the unit's
             MeleeUnit m = new MeleeUnit(xPos,
                                         yPos--,
                                         100,
                                         1,
                                         20,
                                         1,
                                         "M/");
             //Returns unit
             return(m);
         }
         //Does the same as abow except for ranged units
         else if (unitType == "Ranged")
         {
             RangedUnit ru = new RangedUnit(xPos,
                                            yPos--,
                                            100,
                                            1,
                                            20,
                                            5,
                                            1,
                                            "R}");
             return(ru);
         }
     }
     //Does the same as above except for the other team
     else if (faction == 0)
     {
         if (unitType == "Melee")
         {
             MeleeUnit m = new MeleeUnit(xPos,
                                         yPos--,
                                         100,
                                         1,
                                         20,
                                         0,
                                         "M/");
             return(m);
         }
         else if (unitType == "Ranged")
         {
             RangedUnit ru = new RangedUnit(xPos,
                                            yPos--,
                                            100,
                                            1,
                                            20,
                                            5,
                                            0,
                                            "R}");
             return(ru);
         }
     }
     //Return default
     return(null);
 }
Exemple #2
0
        //Displays the units onto the form
        public void Display(GroupBox groupBox)
        {
            //Clears form to prevent multiple instances of buttons
            groupBox.Controls.Clear();


            //Adding Units
            foreach (Unit u in units)
            {
                Button b = new Button();
                //Determines what type of unit to create
                if (u is MeleeUnit)
                {
                    //Creates the physical properties of the unit
                    MeleeUnit mu = (MeleeUnit)u;
                    b.Size     = new Size(30, 30);
                    b.Location = new Point(mu.XPos * 30, mu.YPos * 30);
                    b.Text     = mu.Symbol;
                    if (mu.Faction == 0)
                    {
                        b.ForeColor = Color.HotPink;
                    }
                    else
                    {
                        b.ForeColor = Color.Blue;
                    }
                }
                else
                {
                    //Creates the physical properties of the unit
                    RangedUnit ru = (RangedUnit)u;
                    b.Size     = new Size(30, 30);
                    b.Location = new Point(ru.XPos * 30, ru.YPos * 30);
                    b.Text     = ru.Symbol;
                    if (ru.Faction == 0)
                    {
                        b.ForeColor = Color.HotPink;
                    }
                    else
                    {
                        b.ForeColor = Color.Blue;
                    }
                }
                //adds the unit's stats to the Unit_Click method
                b.Click += Unit_Click;
                //Adds the units to the groupbox
                groupBox.Controls.Add(b);
            }

            //Adding Buildings
            foreach (Building bud in buildings)
            {
                Button b = new Button();
                //Determines what type of building to create
                if (bud is ResourceBuilding)
                {
                    //Creates its physical properties
                    ResourceBuilding rb = (ResourceBuilding)bud;

                    b.Size     = new Size(30, 30);
                    b.Location = new Point(rb.XPos * 30, rb.YPos * 30);
                    b.Text     = rb.Symbol;
                    if (rb.Faction == 0)
                    {
                        b.ForeColor = Color.HotPink;
                    }
                    else
                    {
                        b.ForeColor = Color.Blue;
                    }
                }
                else
                {
                    FactoryBuilding fb = (FactoryBuilding)bud;

                    b.Size     = new Size(30, 30);
                    b.Location = new Point(fb.XPos * 30, fb.YPos * 30);
                    b.Text     = fb.Symbol;
                    if (fb.Faction == 0)
                    {
                        b.ForeColor = Color.HotPink;
                    }
                    else
                    {
                        b.ForeColor = Color.Blue;
                    }
                }
                //Adds the stats to the Building_Click method
                b.Click += Building_Click;
                //Adds the buildings to the groupbox
                groupBox.Controls.Add(b);
            }
        }