public override void CombatM(MeleeUnit enemytofight) { enemytofight.Health -= this.attack; Attacking = true; }
//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++; }
public abstract void B_CombatM(MeleeUnit enemytofight);
public abstract bool Can_AttackM(MeleeUnit enemycanattack);
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++; }