示例#1
0
        public void Generate()
        {
            for (int i = 0; i < numUnits; i++)
            {
                if (rnd.Next(0, 2) == 0)
                {
                    MeleeUnit mu = new MeleeUnit(rnd.Next(0, 20), rnd.Next(0, 20), 100, 1, 20, (i % 2 == 0 ? 1 : 0), "M") // creates melee unit object
                                   units.Add(mu);
                }
                else
                {
                    RangedUnit ru = new RangedUnit(rnd.Next(0, 20), rnd.Next(0, 20), 100, 1, 15, 5, (i % 2 == 0 ? 1 : 0), "R"); // creates ranged unit object
                    units.Add(ru);
                }
            }

            for (int i = 0; i < numBuildings; i++)
            {
                FactoryBuilding f = new FactoryBuilding(rnd.Next(0, 20), rnd.Next(0, 20), 400, (i % 2 == 0 ? 1 : 0), 5, "FB", (rnd.Next(0, 2) == 0 ? true : false)); //creates factory buildings
                buildings.Add(f);
            }

            for (int i = 0; i < numBuildings; i++)
            {
                ResourceBuilding r = new ResourceBuilding(rnd.Next(0, 20), rnd.Next(0, 20), 400, (i % 2 == 0 ? 1 : 0), 5, "RB", "Food", 15); // Creates resource buildings
                buildings.Add(r);
            }
        }
示例#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;  // Creates the buttons on the form to display the ranged units
                    if (ru.XPos == x && ru.YPos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = ru.ToString();
                    }
                }
                else if (u is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)u; // Creates the buttons on the form to display the melee units
                    {
                        if (mu.XPos == x && mu.YPos == y)
                        {
                            txtInfo.Text = "";
                            txtInfo.Text = mu.ToString();
                        }
                    }
                }

                foreach (Building B in buildings)
                {
                    if (B is FactoryBuilding) // Creates the information link on the form to display the factory buildings
                    {
                        FactoryBuilding fb = (FactoryBuilding)B;
                        if (fb.XPos == x && fb.YPos == y)
                        {
                            txtInfo.Text = "";
                            txtInfo.Text = fb.ToString();
                        }
                    }
                    else if (B is ResourceBuilding)
                    {
                        ResourceBuilding rb = (ResourceBuilding)B; // Creates the information link on the form to display the resource buildings
                        if (rb.XPos == x && rb.YPos == y)
                        {
                            txtInfo.Text = "";
                            txtInfo.Text = rb.ToString();
                        }
                    }
                }
            }
        }
示例#3
0
        public void Display(GroupBox grpBox)
        {
            grpBox.Controls.Clear();
            foreach (Unit u in units)
            {
                Button b = new Button();
                if (u is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)u;
                    b.Size     = new Size(20, 20);
                    b.Location = new Point(mu.XPos * 20, mu.YPos * 20);
                    b.Text     = mu.Symbol;
                    if (mu.Faction == 0)
                    {
                        b.ForeColor = Color.Red;
                    }
                    else
                    {
                        b.ForeColor = Color.Blue;
                    }
                }
                else
                {
                    RangedUnit ru = (RangedUnit)u;
                    b.Size     = new Size(20, 20);
                    b.Location = new Point(ru.XPos * 20, ru.YPos * 20);
                    b.Text     = ru.Symbol;
                    if (ru.Faction == 0)
                    {
                        b.ForeColor = Color.Red;
                    }
                    else
                    {
                        b.ForeColor = Color.Blue;
                    }
                }
                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)
                    {
                        for (int i = 0; i < numBuildings; i++)
                        {
                            units.Add(fb.ProduceUnit(fb.Faction));
                        }

                        unitSpawnTimer = 0;
                    }


                    B.Size     = new Size(30, 30);
                    B.Location = new Point(fb.XPos * 20, fb.YPos * 20);
                    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 * 20, rb.YPos * 20);
                    B.Text     = rb.Symbol;
                    rb.ResourceManagement();


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

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