Exemplo n.º 1
0
        public override bool Can_AttackR(RangedUnit enemycanattack)
        {
            bool Xpositioninrange = false;

            if (Math.Abs(enemycanattack.XPos) <= Math.Abs(this.XPos) + this.Attack_Range)
            {
                Xpositioninrange = true;
            }

            bool Ypositioninrange = false;

            if (Math.Abs(enemycanattack.YPos) <= Math.Abs(this.YPos) + this.Attack_Range)
            {
                Ypositioninrange = true;
            }

            if (Xpositioninrange && Ypositioninrange)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public override RangedUnit Closest_Other_EnemyR(List <RangedUnit> Runits)
        {
            RangedUnit closestenemy           = null;
            int        closestenemydifference = 0;
            int        totaldifference;

            foreach (RangedUnit R in Runits)
            {
                totaldifference  = Math.Abs(this.XPos - R.XPos);
                totaldifference += Math.Abs(this.YPos - R.YPos);
                if (closestenemy == null)
                {
                    closestenemy           = R;
                    closestenemydifference = totaldifference;
                }
                else
                {
                    if (closestenemydifference > totaldifference)
                    {
                        closestenemy           = R;
                        closestenemydifference = totaldifference;
                    }
                }
            }

            return(closestenemy);
        }
Exemplo n.º 3
0
        public Unit checkforenemies(Unit lookingforenemies)
        {
            if (lookingforenemies is RangedUnit)
            {
                RangedUnit enemy = lookingforenemies as RangedUnit;
                enemy = lookingforenemies.Closest_Other_EnemyR(map.rangedUnits);
                return(enemy);
            }
            else if (lookingforenemies is MeleeUnit)
            {
                MeleeUnit enemy = lookingforenemies as MeleeUnit;
                enemy = lookingforenemies.Closest_Other_EnemyM(map.meleeUnits);
                return(enemy);
            }
            //task 3 wizard added
            else if (lookingforenemies is WizardUnit)
            {
                WizardUnit enemy = lookingforenemies as WizardUnit;
                enemy = lookingforenemies.Closest_Other_EnemyW(map.wizardUnits);
                return(enemy);
            }

            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        //Generate
        public void Generate()
        {
            int type;

            for (int i = 0; i < noUnits; i++)
            {
                type = (r.Next(0, 2));
                if (type == 0)
                {
                    //make MeleeUnit
                    MeleeUnit Mu = new MeleeUnit((r.Next(0, 20)),
                                                 (r.Next(0, 20)),
                                                 60,
                                                 4,
                                                 (i % 2 == 0 ? 1 : 0), "M");
                    units.Add(Mu);
                }
                else if (type == 1)
                {
                    //make RangedUnit
                    RangedUnit Ru = new RangedUnit((r.Next(0, 20)),
                                                   (r.Next(0, 20)),
                                                   50,
                                                   6,
                                                   (i % 2 == 0 ? 1 : 0), "R");
                    units.Add(Ru);
                }
            }
            //Generating Buildings
            for (int i = 0; i < buildNoUnits; i++)
            {
                //makebuilding
                type = (r.Next(0, 2));
                if (type == 0)
                {
                    //making resourcebuilding
                    ResourceBuilding RB = new ResourceBuilding((r.Next(0, 20)),
                                                               (r.Next(0, 20))
                                                               , 100,
                                                               (i % 2 == 0 ? 1 : 0),
                                                               "@");
                    build.Add(RB);
                }
                else
                {
                    //making FactoryBuilding
                    FactoryBuilding RB = new FactoryBuilding((r.Next(0, 20)),
                                                             (r.Next(0, 20))
                                                             , 100,
                                                             (i % 2 == 0 ? 1 : 0),
                                                             "#", 30,
                                                             (r.Next(0, 2)));
                    build.Add(RB);
                }
            }
        }
Exemplo n.º 5
0
        //button click information
        public void InfoClick(object sender, EventArgs e)
        {
            Button b = (Button)sender;
            int    x = b.Location.X / 20;
            int    y = b.Location.Y / 20;

            foreach (Unit u in units)
            {
                if (u is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)u;
                    if (mu.xpos == x && mu.ypos == y)
                    {
                        txt.Text = "";
                        txt.Text = mu.ToString();
                    }
                }
                if (u is RangedUnit)
                {
                    RangedUnit ru = (RangedUnit)u;
                    if (ru.xpos == x && ru.ypos == y)
                    {
                        txt.Text = "";
                        txt.Text = ru.ToString();
                    }
                }
            }
            foreach (Buildings f in build)
            {
                if (f is FactoryBuilding)
                {
                    FactoryBuilding mu = (FactoryBuilding)f;
                    if (mu.xxpos == x && mu.yypos == y)
                    {
                        txt.Text = "";
                        txt.Text = mu.ToString();
                    }
                }
                if (f is ResourceBuilding)
                {
                    ResourceBuilding mu = (ResourceBuilding)f;
                    if (mu.xxpos == x && mu.yypos == y)
                    {
                        txt.Text = "";
                        txt.Text = mu.ToString();
                    }
                }
            }
        }
Exemplo n.º 6
0
        public Unit UnitSpawner()
        {
            Unit unit;

            if (b_team == 1)
            {
                MeleeUnit m = new MeleeUnit(b_xpos, b_ypos + 1, 50, 7, 1, 1, "M", false, "Warrior");
                unit = m;
            }
            else
            {
                RangedUnit ru = new RangedUnit(b_xpos, b_ypos + 1, 20, 10, 5, 2, "R", false, "Archer");
                unit = ru;
            }

            return(unit);
        }
Exemplo n.º 7
0
        public void UnitGeneration()
        {
            int randomXposition;
            int randomYposition;

            //generating melee units
            for (int i = 0; i < melee_unit_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                MeleeUnit M = new MeleeUnit(randomXposition, randomYposition, 50, 10, 1, 1, "o/*", false, "Warrior");
                meleeUnits.Add(M);
                units.Add(M);
            }
            //generating ranged units
            for (int i = 0; i < ranged_unit_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);
                RangedUnit R = new RangedUnit(randomXposition, randomYposition, 50, 10, 5, 1, "o|}", false, "Archer");
                rangedUnits.Add(R);
                units.Add(R);
            }

            foreach (Building b in buildings)
            {
                if (b is FactoryBuilding)
                {
                    FactoryBuilding f = (FactoryBuilding)b;
                    if (f.production_speed % gameengine.RoundsCompleted == 0)
                    {
                        units.Add(f.UnitSpawner());
                    }
                }
                if (b is ResourceBuilding)
                {
                    ResourceBuilding rs = (ResourceBuilding)b;
                    rs.ResourceGeneration();
                }
            }
        }
Exemplo n.º 8
0
 //Display
 public void Display(GroupBox place)
 {
     place.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.image;
             if (mu.faction == 0)
             {
                 b.ForeColor = Color.Red;
             }
             else
             {
                 b.ForeColor = Color.Green;
             }
         }
         else
         {
             RangedUnit ru = (RangedUnit)u;
             b.Size     = new Size(20, 20);
             b.Location = new Point(ru.xpos * 20, ru.ypos * 20);
             b.Text     = ru.image;
             if (ru.faction == 0)
             {
                 b.ForeColor = Color.Red;
             }
             else
             {
                 b.ForeColor = Color.Green;
             }
         }
         b.Click += InfoClick;
         place.Controls.Add(b);
     }
 }
Exemplo n.º 9
0
        public void UnitGeneration()
        {
            int randomXposition;
            int randomYposition;

            for (int i = 0; i < melee_unit_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);
                MeleeUnit M = new MeleeUnit(randomXposition, randomYposition, 50, 10, 1, 1, "o/*", false);
                meleeUnits.Add(M);
                units.Add(M);
            }
            for (int i = 0; i < ranged_unit_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);
                RangedUnit R = new RangedUnit(randomXposition, randomYposition, 50, 10, 5, 1, "o|}", false);
                rangedUnits.Add(R);
                units.Add(R);
            }
        }
Exemplo n.º 10
0
 public Unit UnitSpawner()
 {
     if (b_team == 1 && rb.Team == 1 && rb.resources_generated > 1)//team 1 (Melee Units)
     {
         Unit      unit;
         MeleeUnit m = new MeleeUnit(b_xpos, b_ypos + 1, 50, 7, 1, 1, "oP", false, "Warrior");
         unit = m;
         return(unit);
     }
     if (b_team == 2 && rb.Team == 2 && rb.resources_generated > 1)//team 2 (Ranged Units)
     {
         Unit       unit;
         RangedUnit ru = new RangedUnit(b_xpos, b_ypos + 1, 30, 10, 5, 2, "o|}", false, "Archer");
         unit = ru;
         return(unit);
     }
     else if (b_team == 3 && rb.Team == 3 && rb.resources_generated > 2) //team 3 (Wizard Units)
     {
         Unit       unit;
         WizardUnit w = new WizardUnit(b_xpos, b_ypos + 1, 40, 8, 1, 3, "o/*", false, "Wizard");
         unit = w;
         return(unit);
     }
 }
Exemplo n.º 11
0
 public abstract bool Can_AttackR(RangedUnit enemycanattack);
Exemplo n.º 12
0
 public abstract void CombatR(RangedUnit enemytofight);
Exemplo n.º 13
0
        //gameLogic
        public void GameLogic()
        {
            for (int i = 0; i < m.Build.Count; i++)
            {
                if (m.Build[i] is FactoryBuilding)
                {
                    FactoryBuilding bu = (FactoryBuilding)m.Build[i];
                    (Unit type, int prodspeed) = bu.Spawn();
                    PrdSp = prodspeed;
                    if (prodspeed == countertick3)
                    {
                        m.Units.Add(type);
                    }
                }
                if (m.Build[i] is ResourceBuilding)
                {
                    ResourceBuilding bu = (ResourceBuilding)m.Build[i];
                    bu.ResourcesGenerated();
                }
            }
            //every x rounds
            if (PrdSp == countertick3)
            {
                countertick3 = 0;
            }
            countertick3++;

            for (int i = 0; i < m.Units.Count; i++)
            {
                //checking if unit is melee
                if (m.Units[i] is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)m.Units[i];
                    (Unit closest, int distance) = mu.ClosestUnit(m.Units);
                    //checking health

                    //setting speed local value
                    speed1 = mu.speed;


                    if (mu.health <= mu.maxHealth * 0.25 && mu.speed == countertick1)
                    {
                        mu.Move(r.Next(0, 4));
                    }
                    else
                    {
                        //Check in range
                        if (mu.IsInRange(closest) == true)
                        {
                            mu.isAttacking = true;
                            mu.Combat(closest);
                        }
                        //moving in direction
                        else
                        {
                            if (closest is MeleeUnit && mu.speed == countertick1)
                            {
                                MeleeUnit closestMu = (MeleeUnit)closest;
                                if (mu.xpos > closestMu.xpos) //North
                                {
                                    mu.Move(0);
                                }
                                else if (mu.xpos < closestMu.xpos) //South
                                {
                                    mu.Move(2);
                                }
                                else if (mu.ypos > closestMu.ypos) //West
                                {
                                    mu.Move(3);
                                }
                                else if (mu.ypos < closestMu.ypos) //East
                                {
                                    mu.Move(1);
                                }
                            }
                            else if (closest is RangedUnit && mu.speed == countertick1)
                            {
                                RangedUnit closestRu = (RangedUnit)closest;
                                if (mu.xpos > closestRu.xpos) //North
                                {
                                    mu.Move(0);
                                }
                                else if (mu.xpos < closestRu.xpos) //South
                                {
                                    mu.Move(2);
                                }
                                else if (mu.ypos > closestRu.ypos) //West
                                {
                                    mu.Move(3);
                                }
                                else if (mu.ypos < closestRu.ypos) //East
                                {
                                    mu.Move(1);
                                }
                            }
                        }
                    }
                }

                // checking if unit is rangedunit
                else if (m.Units[i] is RangedUnit)
                {
                    RangedUnit Ru = (RangedUnit)m.Units[i];
                    (Unit closest, int distance) = Ru.ClosestUnit(m.Units);
                    //checking health

                    //setting speed local value
                    speed2 = Ru.speed;

                    if (Ru.health <= Ru.maxHealth * 0.25 && Ru.speed == countertick2)
                    {
                        Ru.Move(r.Next(0, 4));
                    }
                    else
                    {
                        //Check in range
                        if (Ru.IsInRange(closest) == true)
                        {
                            Ru.isAttacking = true;
                            Ru.Combat(closest);
                        }
                        //moving in direction
                        else
                        {
                            if (closest is MeleeUnit && Ru.speed == countertick2)
                            {
                                MeleeUnit closestMu = (MeleeUnit)closest;
                                if (Ru.xpos > closestMu.xpos) //North
                                {
                                    Ru.Move(0);
                                }
                                else if (Ru.xpos < closestMu.xpos) //South
                                {
                                    Ru.Move(2);
                                }
                                else if (Ru.ypos > closestMu.ypos) //West
                                {
                                    Ru.Move(3);
                                }
                                else if (Ru.ypos < closestMu.ypos) //East
                                {
                                    Ru.Move(1);
                                }
                            }
                            else if (closest is RangedUnit && Ru.speed == countertick2)
                            {
                                RangedUnit closestRu = (RangedUnit)closest;
                                if (Ru.xpos > closestRu.xpos) //North
                                {
                                    Ru.Move(0);
                                }
                                else if (Ru.xpos < closestRu.xpos) //South
                                {
                                    Ru.Move(2);
                                }
                                else if (Ru.ypos > closestRu.ypos) //West
                                {
                                    Ru.Move(3);
                                }
                                else if (Ru.ypos < closestRu.ypos) //East
                                {
                                    Ru.Move(1);
                                }
                            }
                        }
                    }
                }
            }
            if (speed1 == countertick1)
            {
                countertick1 = 0;
            }
            if (speed2 == countertick2)
            {
                countertick2 = 0;
            }
            m.Display(maap);
            round++;
            countertick1++;
            countertick2++;
        }
Exemplo n.º 14
0
        //Display
        public void Display(GroupBox place)
        {
            place.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.image;
                    if (mu.faction == 0)
                    {
                        b.ForeColor = Color.Red;
                    }
                    else
                    {
                        b.ForeColor = Color.Green;
                    }
                }
                else
                {
                    RangedUnit ru = (RangedUnit)u;
                    b.Size     = new Size(20, 20);
                    b.Location = new Point(ru.xpos * 20, ru.ypos * 20);
                    b.Text     = ru.image;
                    if (ru.faction == 0)
                    {
                        b.ForeColor = Color.Red;
                    }
                    else
                    {
                        b.ForeColor = Color.Green;
                    }
                }
                b.Click += InfoClick;
                place.Controls.Add(b);
            }

            //building Display
            {
                foreach (Buildings b in build)
                {
                    Button c = new Button();
                    if (b is ResourceBuilding)
                    {
                        ResourceBuilding Bu = (ResourceBuilding)b;
                        c.Size     = new Size(30, 30);
                        c.Location = new Point(Bu.xxpos * 20, Bu.yypos * 20);
                        c.Text     = Bu.iimage;
                        if (Bu.ffaction == 0)
                        {
                            c.ForeColor = Color.Red;
                        }
                        else
                        {
                            c.ForeColor = Color.Green;
                        }
                    }
                    else
                    {
                        FactoryBuilding Fu = (FactoryBuilding)b;
                        c.Size     = new Size(30, 30);
                        c.Location = new Point(Fu.xxpos * 20, Fu.yypos * 20);
                        c.Text     = Fu.iimage;
                        if (Fu.ffaction == 0)
                        {
                            c.ForeColor = Color.Red;
                        }
                        else
                        {
                            c.ForeColor = Color.Green;
                        }
                    }
                    c.Click += InfoClick;
                    place.Controls.Add(c);
                }
            }
        }
Exemplo n.º 15
0
        //gameLogic
        public void GameLogic()
        {
            for (int i = 0; i < m.Units.Count; i++)
            {
                //checking if unit is melee
                if (m.Units[i] is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)m.Units[i];

                    //setting speed local value
                    speed1 = mu.speed;

                    (Unit closest, int distance) = mu.ClosestUnit(m.Units);
                    //checking health
                    if (mu.health <= mu.maxHealth * 0.25 && mu.speed == countertick1)
                    {
                        mu.Move(r.Next(0, 4));
                    }
                    else
                    {
                        //Check in range
                        if (mu.IsInRange(closest) == true)
                        {
                            mu.isAttacking = true;
                            mu.Combat(closest);
                        }
                        //moving in direction
                        else
                        {
                            if (closest is MeleeUnit && mu.speed == countertick1)
                            {
                                MeleeUnit closestMu = (MeleeUnit)closest;
                                //checking if unit is dead

                                if (mu.xpos > closestMu.xpos)     //North
                                {
                                    mu.Move(0);
                                }
                                else if (mu.xpos < closestMu.xpos)     //South
                                {
                                    mu.Move(2);
                                }
                                else if (mu.ypos > closestMu.ypos)     //West
                                {
                                    mu.Move(3);
                                }
                                else if (mu.ypos < closestMu.ypos)     //East
                                {
                                    mu.Move(1);
                                }
                            }
                            else if (closest is RangedUnit && mu.speed == countertick1)
                            {
                                RangedUnit closestRu = (RangedUnit)closest;
                                //checking if unit is dead

                                if (mu.xpos > closestRu.xpos)     //North
                                {
                                    mu.Move(0);
                                }
                                else if (mu.xpos < closestRu.xpos)     //South
                                {
                                    mu.Move(2);
                                }
                                else if (mu.ypos > closestRu.ypos)     //West
                                {
                                    mu.Move(3);
                                }
                                else if (mu.ypos < closestRu.ypos)     //East
                                {
                                    mu.Move(1);
                                }
                            }
                        }
                    }
                }
                // checking if unit is rangedunit
                else if (m.Units[i] is RangedUnit)
                {
                    RangedUnit Ru = (RangedUnit)m.Units[i];

                    speed2 = Ru.speed;

                    (Unit closest, int distance) = Ru.ClosestUnit(m.Units);
                    //checking health
                    if (Ru.health <= Ru.maxHealth * 0.25 && Ru.speed == countertick2)
                    {
                        Ru.Move(r.Next(0, 4));
                    }
                    else
                    {
                        //Check in range
                        if (Ru.IsInRange(closest) == true)
                        {
                            Ru.isAttacking = true;
                            Ru.Combat(closest);
                        }
                        //moving in direction
                        else
                        {
                            if (closest is MeleeUnit && Ru.speed == countertick2)
                            {
                                MeleeUnit closestMu = (MeleeUnit)closest;

                                if (Ru.xpos > closestMu.xpos)     //North
                                {
                                    Ru.Move(0);
                                }
                                else if (Ru.xpos < closestMu.xpos)     //South
                                {
                                    Ru.Move(2);
                                }
                                else if (Ru.ypos > closestMu.ypos)     //West
                                {
                                    Ru.Move(3);
                                }
                                else if (Ru.ypos < closestMu.ypos)     //East
                                {
                                    Ru.Move(1);
                                }
                            }
                            else if (closest is RangedUnit && Ru.speed == countertick2)
                            {
                                RangedUnit closestRu = (RangedUnit)closest;

                                if (Ru.xpos > closestRu.xpos)     //North
                                {
                                    Ru.Move(0);
                                }
                                else if (Ru.xpos < closestRu.xpos)     //South
                                {
                                    Ru.Move(2);
                                }
                                else if (Ru.ypos > closestRu.ypos)     //West
                                {
                                    Ru.Move(3);
                                }
                                else if (Ru.ypos < closestRu.ypos)     //East
                                {
                                    Ru.Move(1);
                                }
                            }
                        }
                    }
                }
            }
            //checking speeds
            if (speed1 == countertick1)
            {
                countertick1 = 0;
            }
            if (speed2 == countertick2)
            {
                countertick2 = 0;
            }

            m.Display(maap);
            round++;
            countertick1++;
            countertick2++;
        }
Exemplo n.º 16
0
        public void startround()
        {
            //combat for ranged units
            foreach (RangedUnit R in map.rangedUnits)
            {
                Unit enemy = checkforenemies(R);
                if (enemy != null)
                {
                    if (R.Health >= 25 / 100 * R.MaxHealth)
                    {
                        //movecloser
                        R.Move(Movecloser());
                        if (enemy is RangedUnit)
                        {
                            R.Move(RunAway());//won't attack team mate
                        }
                        if (enemy is MeleeUnit)
                        {
                            MeleeUnit Enemy = enemy as MeleeUnit;
                            if (R.Can_AttackM(Enemy))
                            {
                                R.CombatM(Enemy);
                            }
                        }
                        if (enemy is WizardUnit)
                        {
                            WizardUnit Enemy = enemy as WizardUnit;
                            if (R.Can_AttackW(Enemy))
                            {
                                R.CombatW(Enemy);
                            }
                        }
                    }
                    else
                    {
                        R.Move(RunAway());
                        //run away
                    }
                }
                else
                {
                    //do nothing
                }
            }
            //combat for melee units
            foreach (MeleeUnit M in map.meleeUnits)
            {
                Unit enemy = checkforenemies(M);
                if (enemy != null)
                {
                    if (M.Health >= 25 / 100 * M.MaxHealth)
                    {
                        //movecloser
                        M.Move(Movecloser());
                        if (enemy is RangedUnit)
                        {
                            RangedUnit Enemy = enemy as RangedUnit;
                            if (M.Can_AttackR(Enemy))
                            {
                                M.CombatR(Enemy);
                            }
                        }
                        if (enemy is MeleeUnit)
                        {
                            M.Move(RunAway());//won't attack team mate
                        }
                        if (enemy is WizardUnit)
                        {
                            WizardUnit Enemy = enemy as WizardUnit;
                            if (M.Can_AttackW(Enemy))
                            {
                                M.CombatW(Enemy);
                            }
                        }
                    }
                    else
                    {
                        M.Move(RunAway());

                        //run away
                    }
                }
                else
                {
                    //do nothing
                }
            }
            //combat for wizard units(aoe not implemented)
            foreach (WizardUnit W in map.wizardUnits)
            {
                Unit enemy = checkforenemies(W);
                if (enemy != null)
                {
                    if (W.Health >= 50 / 100 * W.MaxHealth)//if health is above 50%
                    {
                        //movecloser
                        W.Move(Movecloser());
                        //wizards attack everything
                        if (enemy is RangedUnit)
                        {
                            RangedUnit Enemy = enemy as RangedUnit;
                            if (W.Can_AttackR(Enemy))
                            {
                                W.CombatR(Enemy);
                            }
                        }
                        if (enemy is MeleeUnit)
                        {
                            MeleeUnit Enemy = enemy as MeleeUnit;
                            if (W.Can_AttackM(Enemy))
                            {
                                W.CombatM(Enemy);
                            }
                        }
                        if (enemy is WizardUnit)
                        {
                            WizardUnit Enemy = enemy as WizardUnit;
                            if (W.Can_AttackW(Enemy))
                            {
                                W.CombatW(Enemy);
                            }
                        }
                    }
                    else//runaway
                    {
                        W.Move(RunAway());
                    }
                }
                else
                {
                    //do nothing
                }
            }
            roundscompleted++;
        }
Exemplo n.º 17
0
 public override void B_CombatR(RangedUnit buildingtofight)
 {
     buildingtofight.Health -= this.attack;
     Attacking = true;
 }
Exemplo n.º 18
0
 public override void CombatR(RangedUnit enemytofight)
 {
     enemytofight.Health -= this.attack;
     Attacking            = true;
 }
Exemplo n.º 19
0
        public void startround()
        {
            //combat for ranged units
            foreach (RangedUnit R in map.rangedUnits)
            {
                Unit enemy = checkforenemies(R);
                if (enemy != null)
                {
                    if (R.Health >= 25 / 100 * R.MaxHealth)
                    {
                        //movecloser
                        R.Move(Movecloser());
                        if (enemy is RangedUnit)
                        {
                            R.Move(RunAway());//won't attack team mate
                        }
                        else
                        {
                            MeleeUnit Enemy = enemy as MeleeUnit;
                            if (R.Can_AttackM(Enemy))
                            {
                                R.CombatM(Enemy);
                            }
                        }
                    }
                    else
                    {
                        R.Move(RunAway());
                        //run away
                    }
                }
                else
                {
                    //do nothing
                }
            }
            //combat for melee units
            foreach (MeleeUnit M in map.meleeUnits)
            {
                Unit enemy = checkforenemies(M);
                if (enemy != null)
                {
                    if (M.Health >= 25 / 100 * M.MaxHealth)
                    {
                        //movecloser
                        M.Move(Movecloser());
                        if (enemy is RangedUnit)
                        {
                            RangedUnit Enemy = enemy as RangedUnit;
                            if (M.Can_AttackR(Enemy))
                            {
                                M.CombatR(Enemy);
                            }
                        }
                        else
                        {
                            M.Move(RunAway());//won't attack team mate
                        }
                    }
                    else
                    {
                        M.Move(RunAway());

                        //run away
                    }
                }
                else
                {
                    //do nothing
                }
            }
            roundscompleted++;
        }