/// <summary> /// Deploys the unit based on the cell that was clicked. /// </summary> /// <returns>A new instance of a certain type of hero class</returns> /// <param name="type">Unit Type</param> public Unit DeloyHero(UnitType type) { switch (type) { case UnitType.Town: currency.Amount -= currency.PriceList [UnitType.Town]; Town town = new Town(); teamManager.AddHero(town); return(town); case UnitType.Mage: currency.Amount -= currency.PriceList [UnitType.Mage]; Mage mage = new Mage(); teamManager.AddHero(mage); return(mage); case UnitType.Ranger: currency.Amount -= currency.PriceList [UnitType.Ranger]; Ranger ranger = new Ranger(); teamManager.AddHero(ranger); return(ranger); case UnitType.Ninja: Ninja ninja = new Ninja(); teamManager.AddHero(ninja); return(ninja); case UnitType.Healer: Healer healer = new Healer(); teamManager.AddHero(healer); return(healer); case UnitType.Warrior: Warrior warrior = new Warrior(); teamManager.AddHero(warrior); return(warrior); default: return(null); } }
/// <summary> /// Handles when characters collide and when projectiles collide with characters /// </summary> private void handleCollisionBetweenEntities() { if (manager.Heroes.Count > 0 && manager.Enemies.Count > 0) { foreach (Unit heros in manager.Heroes) { Healer healer = null; if (heros.getName() == "healer") { healer = heros as Healer; foreach (Unit others in manager.Heroes) { if (healer.inRange(others)) { if (healer != others) { if (SwinGame.SpriteDX(healer.Spirte) != 0) { SwinGame.SpriteSetDX(healer.Spirte, 0); healer.Cast(others); } } } else if (!healer.inRange(others)) { if (SwinGame.SpriteDX(healer.Spirte) == 0) { SwinGame.SpriteSetDX(healer.Spirte, 0.4f); } } } } foreach (Unit enemies in manager.Enemies) { if (detectCollision(heros, enemies)) //Spoof collision detection { int hit = random.Next(2); //Battle interaction - who hit who if (hit == 0) { float dmg = heros.Dmg; healthManager.handleUnitDamage(enemies, dmg); enemies.SetLocation(SwinGame.SpriteX(enemies.Spirte) + 30.0f, Position.ENEMY_SPAWN_Y); //Knockback } else { float dmg = enemies.Dmg; healthManager.handleUnitDamage(heros, dmg); heros.SetLocation(SwinGame.SpriteX(heros.Spirte) - 30.0f, Position.HERO_SPAWN_Y); } } if (heros.getName() == "mage") { Mage mage = heros as Mage; if (mage.inRange(enemies)) { if (SwinGame.SpriteDX(mage.Spirte) != 0) { SwinGame.SpriteSetDX(mage.Spirte, 0); } mage.Cast(); if (detectCollision(mage.fireball, enemies)) { enemies.SetLocation(SwinGame.SpriteX(enemies.Spirte) + 10.0f, Position.ENEMY_SPAWN_Y); mage.fireball = null; healthManager.handleUnitDamage(enemies, mage.SpellDmg); } } else if (!mage.inRange(enemies)) { if (SwinGame.SpriteDX(mage.Spirte) == 0) { SwinGame.SpriteSetDX(mage.Spirte, 0.4f); } } } if (heros.getName() == "ranger") { Ranger ranger = heros as Ranger; if (ranger.inRange(enemies)) { if (SwinGame.SpriteDX(ranger.Spirte) != 0) { SwinGame.SpriteSetDX(ranger.Spirte, 0); } ranger.attack(); if (detectCollision(ranger.Arrow, enemies)) { enemies.SetLocation(SwinGame.SpriteX(enemies.Spirte) + 10.0f, Position.ENEMY_SPAWN_Y); ranger.Arrow = null; healthManager.handleUnitDamage(enemies, ranger.ArrowDmg); } } else if (!ranger.inRange(enemies)) { if (SwinGame.SpriteDX(ranger.Spirte) == 0) { SwinGame.SpriteSetDX(ranger.Spirte, 0.4f); } } } } } } }