Exemple #1
0
 public void Generate()
 {
     for (int i = 0; i < numUnits; i++)
     {
         if (r.Next(0, 2) == 0) //Generate Melee Unit
         {
             MeleeUnit m = new MeleeUnit(r.Next(0, 20), r.Next(0, 20), 100, 1, 20, (i % 2 == 0 ? 1 : 0), "M");
             units.Add(m);
         }
         else //Generate Ranged Unit
         {
             RangeUnit ru = new RangeUnit(r.Next(0, 20), r.Next(0, 20), 100, 1, 20, 5, (i % 2 == 0 ? 1 : 0), "R");
             units.Add(ru);
         }
     }
 }
        public override void Combat(Unit attacker)
        {
            if (attacker is MeleeUnit)
            {
                Health = Health - ((MeleeUnit)attacker).Attack;
            }

            else if (attacker is RangeUnit)
            {
                RangeUnit ru = (RangeUnit)attacker;
                Health = Health - (ru.Attack - ru.AttackRange); //(((RangeUnit)attacker)).Attack;
            }

            if (Health <= 0)
            {
                Death(); //Death!!!
            }
        }
Exemple #3
0
 public void Display(GroupBox groupBox)
 {
     groupBox.Controls.Clear();
     foreach (Unit u in units)
     {
         if (u is MeleeUnit)
         {
             MeleeUnit mu = (MeleeUnit)u;
             Button    b  = new Button();
             b.Size     = new Size(40, 40);
             b.Location = new Point(mu.XPos * 40, mu.YPos * 40);
             b.Text     = mu.Symbol;
             if (mu.Faction == 0)
             {
                 b.ForeColor = Color.Red;
             }
             else
             {
                 b.ForeColor = Color.Green;
             }
         }
         else
         {
             RangeUnit ru = (RangeUnit)u;
             Button    b  = new Button();
             b.Size     = new Size(40, 40);
             b.Location = new Point(ru.XPos * 40, ru.YPos * 40);
             b.Text     = ru.Symbol;
             if (ru.Faction == 0)
             {
                 b.ForeColor = Color.Red;
             }
             else
             {
                 b.ForeColor = Color.Green;
             }
         }
     }
 }