Beispiel #1
0
        // shows units once they are clicked
        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 WizardUnit)
                {
                    WizardUnit wu = (WizardUnit)u;
                    if (wu.XPos == x && wu.YPos == y)
                    {
                        txtInfo.Text = "";
                        txtInfo.Text = wu.ToString();
                    }
                    else if (u is MeleeUnit)
                    {
                        MeleeUnit mu = (MeleeUnit)u;
                        if (mu.XPos == x && mu.YPos == y)
                        {
                            txtInfo.Text = "";
                            txtInfo.Text = mu.ToString();
                        }
                    }
                }
                foreach (Building bu in building)
                {
                    if (bu is ResourceBuilding)
                    {
                        ResourceBuilding ru = (ResourceBuilding)bu;
                        if (ru.XPos == x && ru.YPos == y)
                        {
                            txtInfo.Text = "";
                            txtInfo.Text = ru.ToString();
                        }
                    }
                    else if (bu is FactoryBuilding)
                    {
                        FactoryBuilding mu = (FactoryBuilding)bu;
                        if (mu.XPos == x && mu.YPos == y)
                        {
                            txtInfo.Text = "";
                            txtInfo.Text = mu.ToString();
                        }
                    }
                }
            }
        }
Beispiel #2
0
 // generates units
 public void Generate()
 {
     for (int i = 0; i < numUnits; i++)
     {
         WizardUnit wu = new WizardUnit(r.Next(0, 20), r.Next(0, 20), 30, 5, 1, 2, 2, "P");
         units.Add(wu);
     }
     for (int i = 0; i < numBuilding; i++)
     {
         if (r.Next(0, 2) == 0)
         {
             building.Add(new FactoryBuilding(r.Next(0, 20), r.Next(0, 20), 3, (i % 2 == 0 ? 1 : 0), "F"));
         }
         else
         {
             building.Add(new ResourceBuilding(r.Next(0, 20), r.Next(0, 20), 3, (i % 2 == 0 ? 1 : 0), "R"));
         }
     }
 }
Beispiel #3
0
        // displays units on map
        public void Display(GroupBox groupBox)
        {
            groupBox.Controls.Clear();
            foreach (Unit u in units)
            {
                Button b = new Button();

                if (u is WizardUnit)
                {
                    WizardUnit wu = (WizardUnit)u;
                    b.Size     = new Size(20, 20);
                    b.Location = new Point(wu.XPos * 20, wu.YPos * 20);
                    b.Text     = wu.Symbol;
                    if (wu.Faction == 3)
                    {
                        b.ForeColor = Color.Violet;
                    }
                }
                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.Green;
                    }
                }
                else if (u is RangedUnit)
                {
                    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.Green;
                    }
                }

                b.Click += Unit_Click;
                groupBox.Controls.Add(b);
            }
            foreach (Building b in building)
            {
                Button button = new Button();
                if (b is FactoryBuilding)
                {
                    FactoryBuilding bb = (FactoryBuilding)b;
                    button.Size     = new Size(20, 20);
                    button.Location = new Point(bb.XPos * 20, bb.YPos * 20);
                    button.Text     = bb.Symbol;
                    if (bb.Faction == 0)
                    {
                        button.ForeColor = Color.Red;
                    }
                    else
                    {
                        button.ForeColor = Color.Green;
                    }
                }
                else
                {
                    ResourceBuilding rb = (ResourceBuilding)b;
                    button.Size     = new Size(20, 20);
                    button.Location = new Point(rb.XPos * 20, rb.YPos * 20);
                    button.Text     = rb.Symbol;
                    if (rb.Faction == 0)
                    {
                        button.ForeColor = Color.Red;
                    }
                    else
                    {
                        button.ForeColor = Color.Green;
                    }
                }
                button.Click += Unit_Click;
                groupBox.Controls.Add(button);
            }
        }