public bool MoveTroops(TroopInventory destination, TroopType troopType, int amount) { if (this.Troops[troopType] - amount >= 0 && destination.GetTroopCount() + amount <= destination.TroopLimit) { //Move troops this.Troops[troopType] -= amount; destination.Troops[troopType] += amount; return(true); } return(false); }
public bool Fight(TroopInventory defender) { TroopInventory attacker = this; Troop attackerTroop = attacker.GetInitialTroop(); Troop defenderTroop = defender.GetInitialTroop(); while (attackerTroop != null && defenderTroop != null) { attackerTroop.Fight(defenderTroop); if (attackerTroop.health <= 0) { attacker.RemoveUnit(attackerTroop.type, 1); attackerTroop = attacker.GetNextTroop(attackerTroop.type); } if (defenderTroop.health <= 0) { defender.RemoveUnit(defenderTroop.type, 1); defenderTroop = defender.GetNextTroop(defenderTroop.type); } } return(defender.GetTroopCount() > 0 ? false : true); }