示例#1
0
  private void drawPlayerInfo(Graphics2D g2) {
    if (gameStatus == null) return;

    final int fontSize = 17;
    Font font = new Font("Dialog", Font.PLAIN, fontSize);
    g2.setFont(font);

    final String header = "Name         Taxi Bus U-Ground Black Double";
    final String starDummy = "*Name         Taxi Bus U-Ground Black Double";
    final String taxiDummy = "Taxi Bus U-Ground Black Double";
    final String busDummy = "Bus U-Ground Black Double";
    final String uGroundDummy = "U-Ground Black Double";
    final String blackDummy = "Black Double";
    final String doubleDummy = "Double";

    final float starOffset =
        getWidth() - (float) g2.getFontMetrics().getStringBounds(starDummy, g2).getWidth();
    final float nameOffset =
        getWidth() - (float) g2.getFontMetrics().getStringBounds(header, g2).getWidth();
    final float taxiOffset =
        getWidth() - (float) g2.getFontMetrics().getStringBounds(taxiDummy, g2).getWidth();
    final float busOffset =
        getWidth() - (float) g2.getFontMetrics().getStringBounds(busDummy, g2).getWidth();
    final float uGroundOffset =
        getWidth() - (float) g2.getFontMetrics().getStringBounds(uGroundDummy, g2).getWidth();
    final float blackOffset =
        getWidth() - (float) g2.getFontMetrics().getStringBounds(blackDummy, g2).getWidth();
    final float doubleOffset =
        getWidth() - (float) g2.getFontMetrics().getStringBounds(doubleDummy, g2).getWidth();

    g2.setColor(Color.BLACK);
    g2.drawString(header, nameOffset, fontSize);

    for (int i = 0; i < gameStatus.getPlayers().size(); ++i) {
      Player player = gameStatus.getPlayers().get(i);

      float yOffset = fontSize * (i + 2.3f);
      g2.setColor(player.getColor());

      if (player == gameStatus.getCurrentPlayer()) g2.drawString("*", starOffset, yOffset);

      g2.drawString(player.getName(), nameOffset, yOffset);
      g2.drawString(player.getNumberOfTaxiTickets() + "", taxiOffset, yOffset);
      g2.drawString(player.getNumberOfBusTickets() + "", busOffset, yOffset);
      g2.drawString(player.getNumberOfUndergroundTickets() + "", uGroundOffset, yOffset);
      if (player instanceof MrXPlayer) {
        MrXPlayer mrX = (MrXPlayer) player;
        g2.drawString(mrX.getNumberOfBlackTickets() + "", blackOffset, yOffset);
        g2.drawString(mrX.getNumberOfDoubleMoves() + "", doubleOffset, yOffset);
      }
    }
  }
示例#2
0
  public void startGame(GameStatus gameStatus) {
    this.gameStatus = gameStatus;

    gameStatus.setGameEndCallback(
        new GameStatus.GameEndCallback() {

          @Override
          public void mrXWins() {
            JOptionPane.showMessageDialog(
                GamePlayComponent.this,
                "Mr. X was able to get away!",
                "End of Game",
                JOptionPane.DEFAULT_OPTION);
            GamePlayComponent.this.gameStatus = null;
          }

          @Override
          public void agentsWin() {
            JOptionPane.showMessageDialog(
                GamePlayComponent.this,
                GamePlayComponent.this.gameStatus.getCurrentPlayer().getName() + " caught Mr. X!",
                "End of Game",
                JOptionPane.DEFAULT_OPTION);
            GamePlayComponent.this.gameStatus = null;
          }
        });
  }
示例#3
0
  private void drawPlayerTokens(Graphics2D g2) {
    if (gameStatus == null) return;

    for (Player player : gameStatus.getPlayers()) {
      // if(!player.isVisible())
      // continue;

      Rectangle2D r = graphData.getArea(player.getCurrentStationId()).getBounds2D();
      double atY = r.getMinY() - TokenShape.getHeight() + r.getHeight();
      AffineTransform at = AffineTransform.getTranslateInstance(r.getMinX(), atY);

      Shape transformedToken = at.createTransformedShape(TokenShape.getInstance());
      at = fromImageToOuterTransform();
      transformedToken = at.createTransformedShape(transformedToken);

      Rectangle2D bb = transformedToken.getBounds2D();
      float cx = (float) bb.getCenterX();

      g2.setPaint(
          new GradientPaint(
              cx, (float) bb.getMaxY(), Color.BLACK, cx, (float) bb.getMinY(), player.getColor()));
      g2.fill(transformedToken);
    }
  }