Esempio n. 1
0
 public void setImageScreenFile() {
   bufImage =
       new BufferedImage(this.getSize().width, this.getSize().height, BufferedImage.TYPE_INT_RGB);
   this.paint(bufImage.createGraphics());
   screenStatusOfTheGame = bufImage;
   FileProvider.setCurrentStepOfTheGameImage(bufImage);
 }
Esempio n. 2
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (matchManager.getPlayer1Win() || matchManager.getPlayer2Win()) {
      if (matchManager.canPrintWinOrLose()) {
        if (matchManager.getIAmPlayingWithIa() && matchManager.getPlayer1Win())
          g.drawImage(ImageProvider.getYouWin(), 300, 300, null);
        else if (matchManager.getIAmPlayingWithIa() && matchManager.getPlayer2Win())
          g.drawImage(ImageProvider.getYouLose(), 300, 300, null);
        else g.drawImage(ImageProvider.getYouWin(), 300, 300, null);
      } else {
        principalMainFrame.returnToInitialPanel();
      }
      Graphics2D g2d = (Graphics2D) g;
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
    }

    g.drawImage(
        ImageProvider.tableImage.get(FileProvider.getCommand(CommandSetting.INDEX_TABLE_SELECTED)),
        matchManager.getTable().getX() - 49,
        matchManager.getTable().getY() - 45,
        null);
    g.setColor(Color.RED);

    long second1Match =
        ((matchManager.getMaxWaitTimeForTheTurn()
                    - matchManager.getChronometerOfTheTurn().getElapsedTime())
                - 1)
            / 10;

    long second2Match =
        ((matchManager.getMaxWaitTimeForTheTurn()
                    - matchManager.getChronometerOfTheTurn().getElapsedTime())
                - 1)
            % 10;

    if (second1Match != 0) g.drawImage(ImageProvider.getNumber((int) second1Match), 300, 100, null);
    g.drawImage(ImageProvider.getNumber((int) second2Match), 330, 100, null);

    long minute1 = matchManager.getChronometerOfTheMatch().getMinute() / 10;
    long minute2 = matchManager.getChronometerOfTheMatch().getMinute() % 10;

    long second1 = matchManager.getChronometerOfTheMatch().getElapsedTime() % 60 / 10;
    long second2 = matchManager.getChronometerOfTheMatch().getElapsedTime() % 60 % 10;

    g.drawImage(ImageProvider.getNumber((int) minute1), 640, 100, null);
    g.drawImage(ImageProvider.getNumber((int) minute2), 670, 100, null);

    g.drawImage(ImageProvider.getNumber(10), 700, 102, null);
    g.drawImage(ImageProvider.getNumber((int) second1), 730, 100, null);
    g.drawImage(ImageProvider.getNumber((int) second2), 760, 100, null);

    if (matchManager.getIsThirdStepOfTheGame()) {
      if (matchManager.getPlayerA().getColorBall() == ColorBall.YELLOW) {
        if (matchManager.getYellowBall().size() < MatchManager.MAX_SIZE_SET_OF_BALL_PLAYER)
          g.drawImage(
              ImageProvider.containerYellowBall.get(matchManager.getYellowBall().size()),
              150,
              700,
              null);
        else if (matchManager.getYellowBall().size() == MatchManager.MAX_SIZE_SET_OF_BALL_PLAYER)
          g.drawImage(ImageProvider.getContainerBlackBall(), 150, 700, null);
        if (matchManager.getRedBall().size() < MatchManager.MAX_SIZE_SET_OF_BALL_PLAYER)
          g.drawImage(
              ImageProvider.containerRedBall.get(matchManager.getRedBall().size()), 800, 700, null);
        else if (matchManager.getRedBall().size() == MatchManager.MAX_SIZE_SET_OF_BALL_PLAYER)
          g.drawImage(ImageProvider.getContainerBlackBall(), 800, 700, null);
      } else {
        if (matchManager.getYellowBall().size() < MatchManager.MAX_SIZE_SET_OF_BALL_PLAYER)
          g.drawImage(
              ImageProvider.containerYellowBall.get(matchManager.getYellowBall().size()),
              800,
              700,
              null);
        else if (matchManager.getYellowBall().size() == MatchManager.MAX_SIZE_SET_OF_BALL_PLAYER)
          g.drawImage(ImageProvider.getContainerBlackBall(), 800, 700, null);
        if (matchManager.getRedBall().size() < MatchManager.MAX_SIZE_SET_OF_BALL_PLAYER)
          g.drawImage(
              ImageProvider.containerRedBall.get(matchManager.getRedBall().size()), 150, 700, null);
        else if (matchManager.getRedBall().size() == MatchManager.MAX_SIZE_SET_OF_BALL_PLAYER)
          g.drawImage(ImageProvider.getContainerBlackBall(), 150, 700, null);
      }
    }
    if (matchManager.getIsPlayer1Turn()) {
      g.setColor(Color.RED);
      if (matchManager.getPlayerA().getColorBall() == ColorBall.RED)
        g.drawString("Player 1 Turn Color RED", 50, 50);
      if (matchManager.getPlayerA().getColorBall() == ColorBall.YELLOW)
        g.drawString("Player 1 Turn Color YELLOW", 50, 50);
      if (matchManager.getPlayerA().getColorBall() == ColorBall.NOTHING)
        g.drawString("Player 1 Turn Color NOTHING", 50, 50);
    }
    if (matchManager.getIsPlayer2Turn()) {
      g.setColor(Color.BLUE);
      if (matchManager.getPlayerB().getColorBall() == ColorBall.RED)
        g.drawString("Player 2 Turn Color RED", 50, 50);
      if (matchManager.getPlayerB().getColorBall() == ColorBall.YELLOW)
        g.drawString("Player 2 Turn Color YELLOW", 50, 50);
      if (matchManager.getPlayerB().getColorBall() == ColorBall.NOTHING)
        g.drawString("Player 2 Turn Color NOTHING", 50, 50);
    }
    if (matchManager.getIsFisrtStepOfTheGame()) g.drawString("First Step", 100, 100);
    else if (matchManager.getIsSecondStepOfTheGame()) g.drawString("Second Step", 100, 100);
    else if (matchManager.getIsThirdStepOfTheGame()) g.drawString("Third Step", 100, 100);
    g.setColor(Color.ORANGE.darker().darker());
    if (matchManager.getWhiteBallReposition() && !flag) {
      if (matchManager.getIsPlayer1Turn() && matchManager.getIAmPlayingWithIa())
        g.drawString(
            "PLEASE REPOSITION WHITE BALL, WHEN YOU FINISH TO REPOSITION PRESS SPACE", 400, 100);
      else if (matchManager.getIsPlayer2Turn() && matchManager.getIAmPlayingWithIa())
        g.drawString("THE ARTIFICIAL PLAYER IS REPOSITIONING WHITE BALL", 400, 100);
      else if (!matchManager.getIAmPlayingWithIa())
        g.drawString(
            "PLEASE REPOSITION WHITE BALL, WHEN YOU FINISH TO REPOSITION PRESS SPACE", 400, 100);
    }
    for (Ball b : matchManager.getBalls()) {
      if (!b.getIsPocketed()) {
        if (b.getIdentificativeNumber() == 0)
          g.drawImage(ImageProvider.getWhiteBall(), b.getX(), b.getY(), null);
        if (b.getIdentificativeNumber() == 8)
          g.drawImage(ImageProvider.getBlackBall(), b.getX(), b.getY(), null);
        if (b.getIdentificativeNumber() >= 1 && b.getIdentificativeNumber() <= 7)
          g.drawImage(ImageProvider.getYellowBall(), b.getX(), b.getY(), null);
        if (b.getIdentificativeNumber() >= 9 && b.getIdentificativeNumber() <= 15)
          g.drawImage(ImageProvider.getRedBall(), b.getX(), b.getY(), null);
      }
    }
    g.drawImage(
        ImageProvider.getPowerIndicator(),
        matchManager.getPowerIndicator().getX(),
        matchManager.getPowerIndicator().getY(),
        null);
    g.drawImage(
        ImageProvider.getArrow(),
        matchManager.getPowerIndicator().getArrowIndicator().getX(),
        matchManager.getPowerIndicator().getArrowIndicator().getY(),
        null);
    g.setColor(Color.GRAY.brighter().brighter().brighter());
    g.setColor(Color.RED);
    if (matchManager.getFoulBallHitTheOppositeColor() && matchManager.canPrintFoul()) {
      g.drawImage(
          ImageProvider.firstBallTouchedIsTheOppositeColorFoul.get(matchManager.getIndexTable()),
          400,
          700,
          null);
    }
    if (matchManager.getFoulWhiteBallPocketed() && matchManager.canPrintFoul()) {
      g.drawImage(
          ImageProvider.whiteBallFoulImage.get(matchManager.getIndexTable()), 400, 700, null);
    }
    if (matchManager.getFoulNoneBallTouched() && matchManager.canPrintFoul()) {
      g.drawImage(
          ImageProvider.noneBallTouchedFoulImage.get(matchManager.getIndexTable()), 400, 700, null);
    }
    if (matchManager.getPhysicsBallMovement().everyBallStopped(matchManager.getBalls())
        && !matchManager.getWhiteBallReposition()) {
      stickPaint.paint(
          g,
          matchManager.getStick().getAngle(),
          matchManager.getStick().getX(),
          matchManager.getStick().getY());
      if (matchManager.getIsPlayer1Turn() && matchManager.getIAmPlayingWithIa()
          || !matchManager.getIAmPlayingWithIa())
        directionPaint.paint(
            g,
            matchManager.getStick().getAngle(),
            matchManager.getStick().getX(),
            matchManager.getStick().getY());
    }
  }