public int getAvailableTotalPrice() { if (number_units == 0 || unit.getPrice() == 0) return 0; int amount = castle.getOwner().gold / unit.getPrice(); if (amount < number_units) return amount * unit.getPrice(); else return number_units * unit.getPrice(); }
/** * Buy 'x' number of units and add it to castle army * * @param amount number of units to buy */ public void buy(int amount) { if (canBuy(amount)) { castle.getOwner().gold -= amount * unit.getPrice(); number_units -= amount; castle.addUnitToArmy(unit, amount); } }
public void buyAll() { int amount = castle.getOwner().gold / unit.getPrice(); if (amount >= number_units) buy(number_units); else buy(amount); }
/** * Check if player can buy a certain number of this units * * @param amount number of units that player want to buy */ public boolean canBuy(int amount) { int price = amount * unit.getPrice(); return number_units >= amount && castle.getOwner().gold >= price; }