Package com.jcloisterzone.feature

Examples of com.jcloisterzone.feature.Farm


            }
        }

        if (toEmpty != toFeature) {
            boolean left = toEmpty.rotateCCW(Rotation.R90) == toFeature;
            Farm farm1 = (Farm) tile2.getFeaturePartOf(left ? toEmpty.getLeftFarm() : toEmpty.getRightFarm());
            Farm farm2 = (Farm) tile2.getFeaturePartOf(left ? toFeature.rev().getRightFarm() : toFeature.rev().getLeftFarm());

            if (farm1 != null && farm2 != null) {
//                System.err.println("    " + tile1.getPosition() + " <-->" + f2Pos + " / " + farm1 + " " + farm2);
                rating +=  futureConnectionRateFeatures(game, toEmpty, toFeature, chance, farm1, farm2);
            }
View Full Code Here


    @Override
    public DeploymentCheckResult isDeploymentAllowed(Feature feature) {
        if (!(feature instanceof Farm)) {
            return new DeploymentCheckResult("The barn must be placed only on a farm.");
        }
        Farm farm = (Farm) feature;

        FarmScoreContext ctx = farm.getScoreContext();
        ctx.setCityCache(new HashMap<City, CityScoreContext>());
        farm.walk(ctx);

        if (!farm.getTile().getGame().hasRule(CustomRule.MULTI_BARN_ALLOWED)) {
            for (Special m : ctx.getSpecialMeeples()) {
                if (m instanceof Barn) {
                    return new DeploymentCheckResult("Another barn is already placed on the farm.");
                }
            }
View Full Code Here

            }
        }
    }

    private boolean isBarnCorner(Location corner, Location positionChange) {
        Farm farm = null;
        Position pos = getTile().getPosition();
        for (int i = 0; i < 4; i++) {
            Tile tile = getBoard().get(pos);
            if (tile == null) return false;
            farm = (Farm) tile.getFeaturePartOf(corner);
            if (farm == null) return false;
            corner = corner.next();
            pos = pos.add(positionChange);
            positionChange = positionChange.next();
        }

        if (!game.hasRule(CustomRule.MULTI_BARN_ALLOWED)) {
            return !farm.walk(new IsOccupied().with(Barn.class));
        }

        return true;
    }
View Full Code Here

        }
    }

    @Override
    public boolean visit(Feature feature) {
        Farm farm = (Farm) feature;
        if (farm.isAdjoiningCityOfCarcassonne()) {
            adjoiningCityOfCarcassonne = true;
        }
        if (farm.getAdjoiningCities() != null) {
            addAdjoiningCompletedCities(farm.getAdjoiningCities());
        }
        for (Meeple m : farm.getMeeples()) {
            if (m instanceof Pig) {
                pigs.add(m.getPlayer());
            }
        }
        if (farm.isPigHerd()) {
            pigHerd = true;
        }
        return super.visit(feature);
    }
View Full Code Here

                    boolean hasCity = false;
                    int[] power = new int[getGame().getAllPlayers().length];

                    @Override
                    public boolean visit(Feature feature) {
                        Farm f = (Farm) feature;
                        processed.add(f);
                        size++;
                        hasCity = hasCity || f.getAdjoiningCities() != null || f.isAdjoiningCityOfCarcassonne();
                        for (Meeple m : f.getMeeples()) {
                            if (m instanceof Follower) {
                                power[m.getPlayer().getIndex()] += ((Follower)m).getPower();
                            }
                            if (m instanceof Barn) {
                                power[m.getPlayer().getIndex()] += 1;
                            }
                        }
                        Position pos = f.getTile().getPosition();
                        if (pos.x < x) {
                            if (x != Integer.MAX_VALUE) result.area.transform(AffineTransform.getTranslateInstance(FULL_SIZE * (x-pos.x), 0));
                            x = pos.x;
                        }
                        if (pos.y < y) {
                            if (y != Integer.MAX_VALUE) result.area.transform(AffineTransform.getTranslateInstance(0, FULL_SIZE * (y-pos.y)));
                            y = pos.y;
                        }
                        Map<Location, Area> tileAreas = areas.get(f.getTile());
                        if (tileAreas != null) { //sync issue, feature can be extended in other thread, so it is not registered in areas yet
                            Area featureArea = new Area(tileAreas.get(f.getLocation()));
                            featureArea.transform(AffineTransform.getTranslateInstance(FULL_SIZE * (pos.x-x), FULL_SIZE*(pos.y-y)));
                            result.area.add(featureArea);
                        }
                        return true;
                    }
View Full Code Here

    }

    //TODO move expansion specific stuff
    private void processFarmElement(Element e) {
        String[] sides = asLocation(e);
        Farm farm = new Farm();
        farm.setId(game.idSequnceNextVal());
        if (e.hasAttribute("city")) {
            List<City> cities = new ArrayList<>();
            String[] citiesLocs = asLocations(e, "city");
            for (int j = 0; j < citiesLocs.length; j++) {
                Location d = Location.valueOf(citiesLocs[j]);
                for (Feature p : features) {
                    if (p instanceof City) {
                        if (d.isPartOf(p.getLocation())) {
                            cities.add((City) p);
                            break;
                        }
                    }
                }
            }
            farm.setAdjoiningCities(cities.toArray(new Feature[cities.size()]));
        }
        if (attributeBoolValue(e, "pig")) {
            //for river is pig herd always present
            if (game.hasRule(CustomRule.PIG_HERD_ON_GQ_FARM) || tile.getId() != "GQ.F") {
                farm.setPigHerd(true);
            }
        }
        initFromDirList(farm, sides);
        game.initFeature(tile, farm, e);
    }
View Full Code Here

        castle.setLocation(loc.rotateCCW(tile.getRotation()));
        iter.set(castle);

        for (Feature f : tile.getFeatures()) { //replace also city references
            if (f instanceof Farm) {
                Farm farm = (Farm) f;
                Feature[] adjoining = farm.getAdjoiningCities();
                if (adjoining != null) {
                    for (int i = 0; i < adjoining.length; i++) {
                        if (adjoining[i] == city) {
                            adjoining[i] = castle;
                            break;
View Full Code Here

TOP

Related Classes of com.jcloisterzone.feature.Farm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.