コード例 #1
0
ファイル: Snapshot.java プロジェクト: giorrrgio/JCloisterZone
	public List<Player> getPlayers() {
		List<Player> players = Lists.newArrayList();
		NodeList nl = getSecondLevelElelents("players", "player");
		for(int i = 0; i < nl.getLength(); i++) {
			Element el = (Element) nl.item(i);
			PlayerSlot slot = new PlayerSlot(Integer.parseInt(el.getAttribute("slot")));
			Player p = new Player(el.getAttribute("name"), i, slot);
			p.setPoints(Integer.parseInt(el.getAttribute("points")));
			if (el.hasAttribute("ai-class")) {
				slot.setType(SlotType.AI);
				String aiClassName = el.getAttribute("ai-class");
//				//TODO temporaty for loading old games
//				if ("com.jcloisterzone.ai.LegacyAiPlayer".equals(aiClassName)) {
//					aiClassName = LegacyAiPlayer.class.getName();
//				}
				slot.setAiClassName(aiClassName);
			} else {
				if (el.hasAttribute("local")) {
					//easy way how to mark player local - Server process result of this method
					//and can assign real onwer properly
					slot.setType(SlotType.PLAYER);
				}
			}
			players.add(p);
		}
		return players;
	}
コード例 #2
0
ファイル: Client.java プロジェクト: rudolf1/JCloisterZone
 public Color getPlayerColor() {
     Player player = game.getActivePlayer();
     if (player == null) { //awt thread is not synced
         return Color.BLACK;
     } else {
         return playerColors[player.getSlot().getNumber()];
     }
 }
コード例 #3
0
 @Override
 public void saveToSnapshot(Document doc, Element node) {
   node.setAttribute("bridgeUsed", bridgeUsed + "");
   for (Player player : game.getAllPlayers()) {
     Element el = doc.createElement("player");
     node.appendChild(el);
     el.setAttribute("index", "" + player.getIndex());
     el.setAttribute("bridges", "" + getPlayerBridges(player));
   }
 }
コード例 #4
0
  protected double pointRating() {
    double rating = 0;

    for (Player p : getGame().getAllPlayers()) {
      rating += reducePoints(p.getPoints(), p);
    }

    ScoreAllFeatureFinder scoreAll = new ScoreAllFeatureFinder();
    LegacyAiScoreAllCallback callback = new LegacyAiScoreAllCallback();
    scoreAll.scoreAll(getGame(), callback);
    rating += callback.getRanking();

    return rating;
  }
コード例 #5
0
 public Image get(Player player, String key) {
   if (player == null) {
     return scaledImages.get(key);
   } else {
     return scaledImages.get(player.getIndex() + key);
   }
 }
コード例 #6
0
  private void scaleImages(Game game) {
    for (Player player : game.getAllPlayers()) {
      Color color = player.getColors().getMeepleColor();
      scaleFigureImages(player, color, player.getFollowers());
      scaleFigureImages(player, color, player.getSpecialMeeples());
      if (game.hasCapability(TunnelCapability.class)) {
        Image tunnelA =
            rm.getLayeredImage(
                new LayeredImageDescriptor(
                    "player-meeples/tunnel", player.getColors().getMeepleColor()));
        Image tunnelB =
            rm.getLayeredImage(
                new LayeredImageDescriptor(
                    "player-meeples/tunnel", player.getColors().getTunnelBColor()));

        scaledImages.put(player.getIndex() + "tunnelA", scaleImage(tunnelA));
        scaledImages.put(player.getIndex() + "tunnelB", scaleImage(tunnelB));
      }
    }
    if (game.hasCapability(TowerCapability.class)) {
      scaledImages.put("towerpiece", scaleImage(rm.getImage("neutral/towerpiece")));
    }
    if (game.hasCapability(KingAndRobberBaronCapability.class)) {
      scaledImages.put("king", scaleImage(rm.getImage("neutral/king")));
      scaledImages.put("robber", scaleImage(rm.getImage("neutral/robber")));
    }
    if (game.hasCapability(BazaarCapability.class)) {
      scaledImages.put("bridge", scaleImage(rm.getImage("neutral/bridge")));
      scaledImages.put("castle", scaleImage(rm.getImage("neutral/castle")));
    }
    if (game.hasCapability(ClothWineGrainCapability.class)) {
      scaledImages.put("cloth", rm.getImage("neutral/cloth"));
      scaledImages.put("grain", rm.getImage("neutral/grain"));
      scaledImages.put("wine", rm.getImage("neutral/wine"));
    }
    if (game.hasCapability(BarnCapability.class)) {
      scaledImages.put("abbey", scaleImage(rm.getAbbeyImage(Rotation.R0).getImage()));
    }
    if (game.hasCapability(LittleBuildingsCapability.class)) {
      scaledImages.put("lb-tower", scaleImage(rm.getImage("neutral/lb-tower")));
      scaledImages.put("lb-house", scaleImage(rm.getImage("neutral/lb-house")));
      scaledImages.put("lb-shed", scaleImage(rm.getImage("neutral/lb-shed")));
    }
    if (game.hasCapability(GoldminesCapability.class)) {
      scaledImages.put("gold", scaleImage(rm.getImage("neutral/gold")));
    }
    if (game.hasCapability(DragonCapability.class)) {
      Image scaled =
          new ImageIcon(rm.getImage("neutral/dragon").getScaledInstance(42, 42, Image.SCALE_SMOOTH))
              .getImage();
      scaledImages.put("dragon", scaled);
    }
    if (game.hasCapability(FairyCapability.class)) {
      scaledImages.put("fairy", scaleImage(rm.getImage("neutral/fairy")));
    }
    if (game.hasCapability(MageAndWitchCapability.class)) {
      scaledImages.put("mage", scaleImage(rm.getImage("neutral/mage")));
      scaledImages.put("witch", scaleImage(rm.getImage("neutral/witch")));
    }
  }
コード例 #7
0
 private void scaleFigureImages(Player player, Color color, Collection<? extends Meeple> meeples) {
   for (Meeple f : meeples) {
     String key = player.getIndex() + f.getClass().getSimpleName();
     if (!scaledImages.containsKey(key)) {
       Image img = rm.getLayeredImage(new LayeredImageDescriptor(f.getClass(), color));
       scaledImages.put(key, scaleImage(img));
     }
   }
 }
コード例 #8
0
  protected double meepleRating() {
    double rating = 0;

    for (Player p : getGame().getAllPlayers()) {
      double meeplePoints = 0;
      int limit = 0;
      for (Follower f : p.getFollowers()) {
        if (f.isDeployed()) {
          if (f instanceof SmallFollower) {
            meeplePoints += 0.15;
          } else if (f instanceof BigFollower) {
            meeplePoints += 0.25;
          }
          if (++limit == myTurnsLeft) break;
        }
      }
      rating += reducePoints(meeplePoints, p);
    }
    return rating;
  }
コード例 #9
0
  @Override
  public void saveToSnapshot(Document doc, Element node) {
    for (Player player : game.getAllPlayers()) {
      Element el = doc.createElement("player");
      node.appendChild(el);
      el.setAttribute("index", "" + player.getIndex());
      el.setAttribute("castles", "" + getPlayerCastles(player));
    }

    for (Castle castle : scoreableCastleVicinity.keySet()) {
      node.appendChild(createCastleXmlElement(doc, castle));
    }
    for (Castle castle : newCastles) {
      Element el = createCastleXmlElement(doc, castle);
      el.setAttribute("new", "true");
      node.appendChild(el);
    }
    for (Castle castle : emptyCastles) {
      Element el = createCastleXmlElement(doc, castle);
      el.setAttribute("completed", "true");
      node.appendChild(el);
    }
  }
コード例 #10
0
 /** debug purposes highlight - it always shows basic follower (doesn't important for dbg */
 private void paintFigureHighlight(Graphics2D g2) {
   // ugly copy pasted code from Meeple but uncached here
   g2.setComposite(FIGURE_HIGHLIGHT_AREA_ALPHA_COMPOSITE);
   Tile tile = getGame().getBoard().get(selectedPosition);
   ImmutablePoint point =
       getClient()
           .getResourceManager()
           .getMeeplePlacement(tile, SmallFollower.class, selectedLocation);
   Player p = getClient().getGame().getActivePlayer();
   Image unscaled =
       getClient()
           .getFigureTheme()
           .getFigureImage(SmallFollower.class, p.getColors().getMeepleColor(), null);
   int size = (int) (getSquareSize() * MeepleLayer.FIGURE_SIZE_RATIO);
   Image scaled = unscaled.getScaledInstance(size, size, Image.SCALE_SMOOTH);
   scaled = new ImageIcon(scaled).getImage();
   ImmutablePoint scaledOffset =
       point.scale(getSquareSize(), (int) (getSquareSize() * MeepleLayer.FIGURE_SIZE_RATIO));
   g2.drawImage(
       scaled,
       getOffsetX(selectedPosition) + scaledOffset.getX(),
       getOffsetY(selectedPosition) + scaledOffset.getY(),
       gridPanel);
 }
コード例 #11
0
ファイル: Snapshot.java プロジェクト: giorrrgio/JCloisterZone
	private void createPlayerElements(Game game, long clientId) {
		Element parent = doc.createElement("players");
		parent.setAttribute("turn", "" + game.getTurnPlayer().getIndex());
		root.appendChild(parent);
		for(Player p : game.getAllPlayers()) {
			Element el = doc.createElement("player");
			el.setAttribute("name", p.getNick());
			el.setAttribute("points", "" + p.getPoints());
			el.setAttribute("slot", "" + p.getSlot().getNumber());
			if (Objects.equal(p.getOwnerId(),clientId)) {
				el.setAttribute("local", "true");
			}
			if (p.getSlot().getType() == SlotType.AI) {
				el.setAttribute("ai-class", p.getSlot().getAiClassName());
			}
			parent.appendChild(el);
		}
	}
コード例 #12
0
 private int getTunnelId(Player p, boolean isB) {
   return p.getIndex() + (isB ? 100 : 0);
 }
コード例 #13
0
ファイル: Client.java プロジェクト: rudolf1/JCloisterZone
 public Color getPlayerSecondTunelColor(Player player) {
     int slotNumber = player.getSlot().getNumber();
     return playerColors[(slotNumber + 2) % playerColors.length];
 }
コード例 #14
0
 @Override
 public void addPoints(Player player, int points, PointCategory category) {
   player.addPoints(points, category);
 }
コード例 #15
0
ファイル: Client.java プロジェクト: rudolf1/JCloisterZone
 public Color getPlayerColor(Player player) {
     return playerColors[player.getSlot().getNumber()];
 }
コード例 #16
0
 public boolean isLocalPlayer(Player player) {
   if (player == null) return false;
   return Objects.equal(clientId, player.getOwnerId());
 }
コード例 #17
0
 /** standard highlight * */
 private void paintAreaHighlight(Graphics2D g2) {
   Player p = getClient().getGame().getActivePlayer();
   g2.setColor(p.getColors().getMeepleColor());
   g2.setComposite(AREA_ALPHA_COMPOSITE);
   g2.fill(transformArea(areas.get(selectedLocation), selectedPosition));
 }
コード例 #18
0
ファイル: Client.java プロジェクト: rudolf1/JCloisterZone
 public boolean isClientActive() {
     if (activePlayer == null) return false;
     if (activePlayer.getSlot().getType() != SlotType.PLAYER) return false;
     return getClientStub().isLocalPlayer(activePlayer);
 }