当前位置: 首页>>代码示例>>Java>>正文


Java Tile类代码示例

本文整理汇总了Java中net.sf.freecol.common.model.Tile的典型用法代码示例。如果您正苦于以下问题:Java Tile类的具体用法?Java Tile怎么用?Java Tile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Tile类属于net.sf.freecol.common.model包,在下文中一共展示了Tile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: moveExplore

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * Confirm exploration of a lost city rumour, following a move of
 * MoveType.EXPLORE_LOST_CITY_RUMOUR.
 *
 * @param unit The {@code Unit} that is exploring.
 * @param direction The direction of a rumour.
 * @return True if automatic movement of the unit can proceed (never).
 */
private boolean moveExplore(Unit unit, Direction direction) {
    // Confirm the move.
    final Tile tile = unit.getTile().getNeighbourOrNull(direction);
    if (!getGUI().confirm(unit.getTile(),
            StringTemplate.key("exploreLostCityRumour.text"), unit,
            "exploreLostCityRumour.yes", "exploreLostCityRumour.no")) {
        if (unit.getDestination() != null) askClearGotoOrders(unit);
        return false;
    }

    // Handle the mounds decision.
    if (tile.getLostCityRumour().getType() == LostCityRumour.RumourType.MOUNDS
        && !getGUI().confirm(unit.getTile(),
            StringTemplate.key("exploreMoundsRumour.text"), unit,
            "exploreLostCityRumour.yes", "exploreLostCityRumour.no")) {
        askServer().declineMounds(unit, direction); // LCR goes away
        return false;
    }

    // Always stop automatic movement as exploration always does something.
    moveTile(unit, direction);
    return false;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:32,代码来源:InGameController.java

示例2: changeWorkImprovementType

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * Changes the work type of this {@code Unit}.
 *
 * Called from ImprovementAction.
 *
 * @param unit The {@code Unit}
 * @param improvementType a {@code TileImprovementType} value
 * @return True if the improvement was changed.
 */
public boolean changeWorkImprovementType(Unit unit,
    TileImprovementType improvementType) {
    if (!requireOurTurn() || unit == null || improvementType == null
        || !unit.hasTile()
        || !unit.checkSetState(UnitState.IMPROVING)
        || improvementType.isNatural()) return false;

    // May need to claim the tile first
    final Player player = getMyPlayer();
    final Tile tile = unit.getTile();
    UnitWas unitWas = new UnitWas(unit);
    boolean ret = player.owns(tile)
        || askClaimTile(player, tile, unit, player.getLandPrice(tile));
    if (ret) {
        ret = askServer()
            .changeWorkImprovementType(unit, improvementType)
            && unit.getWorkImprovement() != null
            && unit.getWorkImprovement().getType() == improvementType;
        if (ret) {
            unitWas.fireChanges();
        }
        updateGUI(null);
    }
    return ret;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:35,代码来源:InGameController.java

示例3: adjust

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * Given an unit, a source and destination tile, and the moves
 * left, calculate actual moves left and new turns.
 *
 * @param unit The {@code Unit} to use.
 * @param oldTile The source {@code Tile}.
 * @param newTile The destination {@code Tile}.
 * @param movesLeftBefore An initial number of moves left.
 * @return The new movement cost, with this.movesLeft and this.newTurns
 *     adjusted.
 */
public int adjust(Unit unit, Tile oldTile, Tile newTile,
                  int movesLeftBefore) {
    int cost = unit.getMoveCost(oldTile, newTile, movesLeftBefore);
    if (cost <= movesLeftBefore) {
        this.movesLeft = movesLeftBefore - cost;
        this.newTurns = 0;
    } else { // This move takes an extra turn to complete:
        final int thisTurnMovesLeft = movesLeftBefore;
        int initialMoves = unit.getInitialMovesLeft();
        final int moveCostNextTurn = unit.getMoveCost(oldTile, newTile,
                                                      initialMoves);
        cost = thisTurnMovesLeft + moveCostNextTurn;
        this.movesLeft = initialMoves - moveCostNextTurn;
        this.newTurns = 1;
    }
    return cost;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:29,代码来源:BaseCostDecider.java

示例4: extractTarget

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * Extract a valid target for this mission from a path.
 *
 * @param aiUnit A {@code AIUnit} to perform the mission.
 * @param path A {@code PathNode} to extract a target from,
 *     (uses the unit location if null).
 * @return A target for this mission, or null if none found.
 */
public static Location extractTarget(AIUnit aiUnit, PathNode path) {
    if (path == null) return null;
    final Unit unit = aiUnit.getUnit();
    final Player owner = unit.getOwner();
    final Location loc = path.getLastNode().getLocation();
    Settlement settlement = loc.getSettlement();
    Tile tile = loc.getTile();
    Unit other = (tile == null) ? null : tile.getDefendingUnit(unit);
    return (loc instanceof Europe) ? loc
        : (other != null
            && invalidUnitReason(aiUnit, other) == null) ? other
        : (settlement != null
            && invalidTargetReason(settlement, owner) == null) ? settlement
        : null;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:24,代码来源:PrivateerMission.java

示例5: build

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
public Map build(){
    completeWorkingGrid();
    Map map = new Map(game, width, height);
    Region region = new Region(game);

    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            TileType tileType = tiles[x][y];
            Tile t = new Tile(game, tileType, x, y);
            t.setRegion(region);
            map.setTile(t, x, y);
        }
    }

    map.resetContiguity();
    map.resetHighSeasCount();
    if (exploredByAll) {
        map.forEachTile(t -> {
                for (Player p : game.getLiveEuropeanPlayerList()) {
                    t.setExplored(p, true);
                }
            });
    }
    return map;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:26,代码来源:FreeColTestCase.java

示例6: csEmbark

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * Embark a unit.
 *
 * @param carrier The {@code Unit} to embark on.
 * @param cs A {@code ChangeSet} to update.
 */
public void csEmbark(Unit carrier, ChangeSet cs) {
    final ServerPlayer owner = (ServerPlayer)getOwner();

    Location oldLocation = getLocation();
    Colony colony = (oldLocation instanceof WorkLocation) ? getColony()
        : null;
    if (colony != null) oldLocation.getTile().cacheUnseen();//+til
    setLocation(carrier);//-vis: only if on a different tile
                         //-til if moving from colony
    setMovesLeft(0);
    cs.add(See.only(owner), (colony != null) ? colony
        : (FreeColGameObject)oldLocation);
    if (carrier.getLocation() != oldLocation) {
        cs.add(See.only(owner), carrier);
    }
    if (oldLocation instanceof Tile) {
        if (carrier.getTile() != oldLocation) {
            cs.addMove(See.only(owner), this, oldLocation,
                       carrier.getTile());
            owner.invalidateCanSeeTiles();//+vis(serverPlayer)
        }
        cs.addDisappear(owner, (Tile)oldLocation, this);
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:31,代码来源:ServerUnit.java

示例7: clientHandler

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void clientHandler(FreeColClient freeColClient) {
    final Game game = freeColClient.getGame();
    final Player player = freeColClient.getMyPlayer();
    final Tile oldTile = getOldTile(game);
    final Tile newTile = getNewTile(game);
    final Unit unit = getUnit(game);

    if (unit == null) return;
    if (oldTile == null) {
        logger.warning("Animation for: " + player.getId()
            + " missing old Tile.");
        return;
    }
    if (newTile == null) {
        logger.warning("Animation for: " + player.getId()
            + " missing new Tile.");
        return;
    }

    // This only performs animation, if required.  It does not
    // actually change unit positions, which happens in an "update".
    igc(freeColClient).animateMoveHandler(unit, oldTile, newTile);
    clientGeneric(freeColClient);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:29,代码来源:AnimateMoveMessage.java

示例8: enterUnitOutForAnimation

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
private JLabel enterUnitOutForAnimation(final Unit unit,
                                        final Tile sourceTile) {
    Integer i = unitsOutForAnimation.get(unit);
    if (i == null) {
        final JLabel unitLabel = createUnitLabel(unit);

        i = 1;
        unitLabel.setLocation(calculateUnitLabelPositionInTile(
                unitLabel.getWidth(), unitLabel.getHeight(),
                calculateTilePosition(sourceTile)));
        unitsOutForAnimationLabels.put(unit, unitLabel);
        gui.getCanvas().add(unitLabel, JLayeredPane.DEFAULT_LAYER);
    } else {
        i++;
    }
    unitsOutForAnimation.put(unit, i);
    return unitsOutForAnimationLabels.get(unit);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:19,代码来源:MapViewer.java

示例9: setRumourType

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * Debug action to set the lost city rumour type on a tile.
 *
 * Called from tile popup menu.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param tile The {@code Tile} to operate on.
 */
public static void setRumourType(final FreeColClient freeColClient,
                                 final Tile tile) {
    final FreeColServer server = freeColClient.getFreeColServer();
    final Game sGame = server.getGame();
    final Tile sTile = sGame.getFreeColGameObject(tile.getId(),
                                                  Tile.class);
    final Predicate<RumourType> realRumourPred = r ->
        r != RumourType.NO_SUCH_RUMOUR;
    final Function<RumourType, ChoiceItem<RumourType>> mapper = r ->
        new ChoiceItem<RumourType>(r.toString(), r);
        
    RumourType rumourChoice = freeColClient.getGUI().getChoice(null,
        StringTemplate.template("prompt.selectLostCityRumour"), "cancel",
        transform(RumourType.values(), realRumourPred, mapper,
                  Comparator.naturalOrder()));
    if (rumourChoice == null) return;

    tile.getTileItemContainer().getLostCityRumour().setType(rumourChoice);
    sTile.getTileItemContainer().getLostCityRumour()
        .setType(rumourChoice);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:30,代码来源:DebugUtils.java

示例10: findTileFor

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
private Tile findTileFor(Map map, int row, int start, boolean startAtSea,
                         LogBuilder lb) {
    Tile tile = null;
    Tile seas = null;
    int offset = (start == 0) ? 1 : -1;
    for (int x = start; 0 <= x && x < map.getWidth(); x += offset) {
        tile = map.getTile(x, row);
        if (tile.isDirectlyHighSeasConnected()) {
            seas = tile;
        } else if (tile.isLand()) {
            return (startAtSea) ? seas : tile;
        } 
    }
    lb.add("No land in row ", row, ".\n");
    return null;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:17,代码来源:SimpleMapGenerator.java

示例11: animateUnitAttack

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void animateUnitAttack(Unit attacker, Unit defender,
                              Tile attackerTile, Tile defenderTile,
                              boolean success) {
    // Note: we used to focus the map on the unit even when
    // animation is off as long as the center-active-unit option
    // was set.  However IR#115 requested that if animation is off
    // that we display nothing so as to speed up the other player
    // moves as much as possible.
    final FreeColClient fcc = getFreeColClient();
    if (fcc.getAnimationSpeed(attacker.getOwner()) <= 0
        && fcc.getAnimationSpeed(defender.getOwner()) <= 0) return;

    Animations.unitAttack(fcc, attacker, defender,
                          attackerTile, defenderTile, success);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:20,代码来源:SwingGUI.java

示例12: invalidReason

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * Why would this mission be invalid with the given AI unit?
 *
 * @param aiUnit The {@code AIUnit} to check.
 * @param loc The {@code Location} to check.
 * @return A reason for mission invalidity, or null if none found.
 */
public static String invalidReason(AIUnit aiUnit, Location loc) {
    final Player owner = aiUnit.getUnit().getOwner();
    String reason = invalidMissionReason(aiUnit);
    return (reason != null)
        ? reason
        : (aiUnit.getUnit().isInEurope())
        ? null
        : (loc == null)
        ? null
        : (loc instanceof Europe)
        ? invalidTargetReason(loc, owner)
        : (loc instanceof Settlement)
        ? invalidSettlementReason(aiUnit, (Settlement)loc)
        : (loc instanceof Unit)
        ? invalidUnitReason(aiUnit, (Unit)loc)
        : (loc instanceof Tile)
        ? ((((Tile)loc).isExploredBy(owner)) ? "tile-is-explored"
            : null)
        : Mission.TARGETINVALID;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:28,代码来源:PrivateerMission.java

示例13: getHighSeasGoalDecider

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * Gets a GoalDecider to find the closest high seas tile to a target.
 * Used when arriving on the map from Europe.
 *
 * @return The high seas goal decider.
 */
public static GoalDecider getHighSeasGoalDecider() {
    return new GoalDecider() {
        private PathNode best = null;
        
        @Override
        public PathNode getGoal() { return best; }
        @Override
        public boolean hasSubGoals() { return false; }
        @Override
        public boolean check(Unit u, PathNode path) {
            Tile tile = path.getTile();
            if (tile != null
                && tile.isExploredBy(u.getOwner())
                && tile.isDirectlyHighSeasConnected()
                && (tile.getFirstUnit() == null
                    || u.getOwner().owns(tile.getFirstUnit()))) {
                if (best == null || path.getCost() < best.getCost()) {
                    best = path;
                    return true;
                }
            }
            return false;
        }
    };
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:32,代码来源:GoalDeciders.java

示例14: csNewTurn

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * New turn for this colony tile.
 *
 * @param random A {@code Random} number source.
 * @param lb A {@code LogBuilder} to log to.
 * @param cs A {@code ChangeSet} to update.
 */
@Override
public void csNewTurn(Random random, LogBuilder lb, ChangeSet cs) {
    Colony colony = getColony();
    ServerPlayer owner = (ServerPlayer)colony.getOwner();

    Tile workTile = getWorkTile();
    if (!isColonyCenterTile() && !isEmpty() && canBeWorked()) {
        for (Unit unit : getUnitList()) {
            Resource resource = expendResource(workTile, unit.getWorkType(),
                                               unit.getType());
            if (resource != null) {
                lb.add(" ", getId(), " exhausted resource ",
                       resource.getType().getSuffix());
                cs.addMessage(owner,
                    new ModelMessage(ModelMessage.MessageType.WARNING,
                                     "model.colonyTile.resourceExhausted",
                                     colony)
                        .addNamed("%resource%", resource)
                        .addName("%colony%", colony.getName()));
                cs.add(See.perhaps(), workTile);
                break;
            }
        }
    }
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:33,代码来源:ServerColonyTile.java

示例15: getClaimChoice

import net.sf.freecol.common.model.Tile; //导入依赖的package包/类
/**
 * Gets the user choice for claiming a tile.
 *
 * @param tile The {@code Tile} to claim.
 * @param player The {@code Player} that is claiming.
 * @param price An asking price, if any.
 * @param owner The {@code Player} that owns the land.
 * @return The chosen action, accept, steal or cancel.
 */
public ClaimAction getClaimChoice(Tile tile, Player player, int price,
                                  Player owner) {
    List<ChoiceItem<ClaimAction>> choices = new ArrayList<>();
    StringTemplate template;
    if (owner.hasContacted(player)) {
        template = StringTemplate.template("indianLand.text")
            .addStringTemplate("%player%", owner.getNationLabel());
        StringTemplate pay = StringTemplate.template("indianLand.pay")
            .addAmount("%amount%", price);
        choices.add(new ChoiceItem<>(Messages.message(pay),
                                     ClaimAction.CLAIM_ACCEPT,
                                     player.checkGold(price)));
    } else {
        template = StringTemplate.template("indianLand.unknown");
    }

    choices.add(new ChoiceItem<>(Messages.message("indianLand.take"),
                                 ClaimAction.CLAIM_STEAL));

    return getChoice(tile, template,
                     owner.getNation(), "indianLand.cancel", choices);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:32,代码来源:GUI.java


注:本文中的net.sf.freecol.common.model.Tile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。