Beispiel #1
0
        public override WizardUnit Closest_Other_EnemyW(List <WizardUnit> Wunits)
        {
            WizardUnit closestenemy           = null;
            int        closestenemydifference = 0;
            int        totaldifference;

            foreach (WizardUnit W in Wunits)
            {
                totaldifference  = Math.Abs(this.XPos - W.XPos);
                totaldifference += Math.Abs(this.YPos - W.YPos);
                if (closestenemy == null)
                {
                    closestenemy           = W;
                    closestenemydifference = totaldifference;
                }
                else
                {
                    if (closestenemydifference > totaldifference)
                    {
                        closestenemy           = W;
                        closestenemydifference = totaldifference;
                    }
                }
            }
            return(closestenemy);
        }
Beispiel #2
0
        public void UnitGeneration()
        {
            int randomXposition;
            int randomYposition;

            //generating melee units (Team 1)
            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, "oP", false, "Warrior");
                meleeUnits.Add(M);
                units.Add(M);
            }
            //generating ranged units (Team 2)
            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);
            }
            //generating wizard units (Team 3)
            for (int i = 0; i < wizard_unit_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);
                WizardUnit W = new WizardUnit(randomXposition, randomYposition, 50, 10, 4, 3, "o/*", false, "Wizard");
                wizardUnits.Add(W);
                units.Add(W);
            }
        }
Beispiel #3
0
        public override bool Can_AttackW(WizardUnit 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);
            }
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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);
     }
 }
Beispiel #6
0
 public override void CombatW(WizardUnit enemytofight)
 {
     enemytofight.Health -= this.attack;
     Attacking            = true;
 }
Beispiel #7
0
 public override void B_CombatW(WizardUnit buildingtofight)
 {
     buildingtofight.Health -= this.attack;
     Attacking = true;
 }
Beispiel #8
0
 public abstract bool Can_AttackW(WizardUnit enemycanattack);
Beispiel #9
0
 public abstract void B_CombatW(WizardUnit enemytofight);
Beispiel #10
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++;
        }