Package org.freerealm.player

Examples of org.freerealm.player.Player


        realm.setNumberOfTurns(realm.getNumberOfTurns() + 1);
        Iterator<Player> playerIterator = realm.getPlayerManager().getPlayersIterator();
        while (playerIterator.hasNext()) {
            Executor.getInstance().execute(new StartPlayerTurnCommand(playerIterator.next()));
        }
        Player firstPlayer = realm.getPlayerManager().getFirstPlayer();
        Executor.getInstance().execute(new SetActivePlayerCommand(firstPlayer));
        return new CommandResult(CommandResult.RESULT_OK, "", CommandResult.NEW_TURN_UPDATE);
    }
View Full Code Here


     * Executes command and adds captured settlement to unit's player.
     * @param realm Realm to execute the command
     * @return CommandResult
     */
    public CommandResult execute(Realm realm) {
        Player defendingPlayer = settlement.getPlayer();
        settlement.setPlayer(unit.getPlayer());
        MoveUnitCommand moveUnitCommand = new MoveUnitCommand(unit, settlement.getCoordinate());
        CommandResult result = Executor.getInstance().execute(moveUnitCommand);
        if (result.getCode() == CommandResult.RESULT_OK) {
            defendingPlayer.removeSettlement(settlement);
            unit.getPlayer().addSettlement(settlement);
            unit.setMovementPoints(0);
            CommandResult commandResult = new CommandResult(CommandResult.RESULT_OK, "", CommandResult.SETTLEMENT_CAPTURED_UPDATE);
            commandResult.addParameter(settlement);
            commandResult.addParameter(unit.getPlayer());
View Full Code Here

    public String toXML() {
        StringBuffer xml = new StringBuffer();
        xml.append("<Players>\n");
        for (Iterator<Player> iterator = playerManager.getPlayersIterator(); iterator.hasNext();) {
            Player player = iterator.next();
            String xMLConverterName = TagManager.getXMLConverterName(player.getClass());
            try {
                XMLConverter<Player> xMLConverter = (XMLConverter<Player>) Class.forName(xMLConverterName).newInstance();
                xml.append(xMLConverter.toXML(player) + "\n");
            } catch (Exception ex) {
                ex.printStackTrace();
View Full Code Here

                    activePlayerId = Integer.parseInt(subNode.getFirstChild().getNodeValue());
                } else {
                    String xMLConverterName = TagManager.getXMLConverterName(subNode.getNodeName());
                    try {
                        XMLConverter<Player> xMLConverter = (XMLConverter<Player>) Class.forName(xMLConverterName).newInstance();
                        Player player = xMLConverter.initializeFromNode(realm, subNode);
                        playerManager.addPlayer(player);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
View Full Code Here

        for (Node subNode = tileTypesNode.getFirstChild(); subNode != null; subNode = subNode.getNextSibling()) {
            if (subNode.getNodeType() == Node.ELEMENT_NODE) {
                int player1Id = Integer.parseInt(XMLConverterUtility.findNode(subNode, "player1").getFirstChild().getNodeValue());
                int player2Id = Integer.parseInt(XMLConverterUtility.findNode(subNode, "player2").getFirstChild().getNodeValue());
                int status = Integer.parseInt(XMLConverterUtility.findNode(subNode, "status").getFirstChild().getNodeValue());
                Player player1 = realm.getPlayerManager().getPlayer(player1Id);
                Player player2 = realm.getPlayerManager().getPlayer(player2Id);
                diplomacy.addPlayerRelation(player1, player2, status);
            }
        }
        return diplomacy;
    }
View Full Code Here

    public String toXML(History history) {
        StringBuffer xml = new StringBuffer();
        xml.append("<history>\n");
        Iterator<Player> iterator = history.getPlayersIterator();
        while (iterator.hasNext()) {
            Player player = iterator.next();
            PlayerHistory playerHistory = history.getPlayerHistory(player);
            xml.append(new FreeRealmPlayerHistoryXMLConverter().toXML(playerHistory));
        }
        xml.append("</history>\n");
        return xml.toString();
View Full Code Here

        WorldMap worldMap = new WorldMap();
        (new WorldMapXMLWrapper(worldMap)).initializeFromNode(realm, worldMapNode);

        Iterator<Player> playerIterator = realm.getPlayerManager().getPlayersIterator();
        while (playerIterator.hasNext()) {
            Player player = playerIterator.next();
            Iterator<Settlement> settlementsIterator = player.getSettlementsIterator();
            while (settlementsIterator.hasNext()) {
                Settlement settlement = settlementsIterator.next();
                worldMap.addSettlement(settlement);
            }
            Iterator<Unit> unitsIterator = player.getUnitsIterator();
            while (unitsIterator.hasNext()) {
                Unit unit = unitsIterator.next();
                if (unit.getCoordinate() != null) {
                    worldMap.addUnit(unit);
                }
View Full Code Here

    private void manageDiplomacy(Realm realm) {
        Vector<Coordinate> circleCoordinates = realm.normalizeCoordinates(Utility.getCircleCoordinates(coordinate, realm, 1));
        for (Coordinate checkCoordinate : circleCoordinates) {
            Tile checkTile = realm.getTile(checkCoordinate);
            if (checkTile.getSettlement() != null) {
                Player movingUnitsPlayer = unit.getPlayer();
                Player neighborTileCityPlayer = checkTile.getSettlement().getPlayer();
                setDiplomaticStatusToPeaceIfNeeded(realm, movingUnitsPlayer, neighborTileCityPlayer);
            }
            Iterator<Unit> unitIterator = checkTile.getUnitsIterator();
            while (unitIterator.hasNext()) {
                Unit checkUnit = unitIterator.next();
                Player movingUnitsPlayer = unit.getPlayer();
                Player neighborTileUnitPlayer = checkUnit.getPlayer();
                setDiplomaticStatusToPeaceIfNeeded(realm, movingUnitsPlayer, neighborTileUnitPlayer);
            }
        }
    }
View Full Code Here

    public static boolean isTileAvailable(Realm realm, Settlement settlement, Coordinate coordinate) {
        boolean result = true;
        Iterator<Player> playerIterator = realm.getPlayerManager().getPlayersIterator();
        while (playerIterator.hasNext()) {
            Player player = playerIterator.next();
            Iterator<Settlement> citiesIterator = player.getSettlementsIterator();
            while (citiesIterator.hasNext()) {
                Settlement otherSettlement = citiesIterator.next();
                if (!settlement.equals(otherSettlement)) {
                    if (otherSettlement.getCoordinate().equals(coordinate)) {
                        return false;
View Full Code Here

TOP

Related Classes of org.freerealm.player.Player

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.