當前位置: 首頁>>代碼示例>>Java>>正文


Java MarketWas類代碼示例

本文整理匯總了Java中net.sf.freecol.common.model.MarketWas的典型用法代碼示例。如果您正苦於以下問題:Java MarketWas類的具體用法?Java MarketWas怎麽用?Java MarketWas使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MarketWas類屬於net.sf.freecol.common.model包,在下文中一共展示了MarketWas類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: askUnloadGoods

import net.sf.freecol.common.model.MarketWas; //導入依賴的package包/類
/**
 * Unload some goods from a carrier.
 *
 * @param type The {@code GoodsType} to unload.
 * @param amount The amount of goods to unload.
 * @param carrier The {@code Unit} carrying the goods.
 * @return True if the unload succeeded.
 */
private boolean askUnloadGoods(GoodsType type, int amount, Unit carrier) {
    // Do not check for trade location, unloading can include dumping
    // which can happen anywhere
    final Player player = getMyPlayer();
    final Market market = player.getMarket();
    MarketWas marketWas = (market != null) ? new MarketWas(player) : null;

    int oldAmount = carrier.getGoodsContainer().getGoodsCount(type);
    if (askServer().unloadGoods(type, amount, carrier)
        && !(carrier.isInEurope() && !player.canTrade(type))
        && carrier.getGoodsContainer().getGoodsCount(type) != oldAmount) {
        if (marketWas != null) marketWas.fireChanges(type, -amount);
        return true;
    }
    return false;
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:25,代碼來源:InGameController.java

示例2: askLoadGoods

import net.sf.freecol.common.model.MarketWas; //導入依賴的package包/類
/**
 * Load some goods onto a carrier.
 *
 * @param loc The {@code Location} to load from.
 * @param type The {@code GoodsType} to load.
 * @param amount The amount of goods to load.
 * @param carrier The {@code Unit} to load onto.
 * @return True if the load succeeded.
 */
private boolean askLoadGoods(Location loc, GoodsType type, int amount,
                             Unit carrier) {
    TradeLocation trl = carrier.getTradeLocation();
    if (trl == null) return false;

    // Size check, if there are spare holds they can be filled, but...
    int loadable = carrier.getLoadableAmount(type);
    if (amount > loadable) amount = loadable;

    final Player player = carrier.getOwner();
    final Market market = player.getMarket();
    MarketWas marketWas = (market != null) ? new MarketWas(player) : null;

    if (carrier.isInEurope()) {
        // Are the goods boycotted?
        if (!player.canTrade(type)) return false;

        // Check that the purchase is funded.
        if (!player.checkGold(market.getBidPrice(type, amount))) {
            getGUI().showInformationMessage("info.notEnoughGold");
            return false;
        }
    }

    // Try to purchase.
    int oldAmount = carrier.getGoodsContainer().getGoodsCount(type);
    if (askServer().loadGoods(loc, type, amount, carrier)
        && carrier.getGoodsContainer().getGoodsCount(type) != oldAmount) {
        if (marketWas != null) marketWas.fireChanges(type, amount);
        return true;
    }
    return false;
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:43,代碼來源:InGameController.java


注:本文中的net.sf.freecol.common.model.MarketWas類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。