Пример #1
0
  // ---------makes the animation for the remote player's (computer) bead---------
  private void startRemoteMoving(String position) {

    System.out.println("procesing " + position);
    if (isWin(position)) {

      winner = parseWinner(position);
      if (winner == 1) startImageLoader(WIN_IMAGE_FILE);
      else {

        isWinLoseTimer = new Timer(IMAGE_LOADERS_TIMER, this);
        isWinLoseTimer.setActionCommand("is win_lose");
        isWinLoseTimer.setRepeats(false); // occurs only one time
        isWinLoseTimer.start();
      }
      repaint();
      return;
    }
    if (isDraw(position)) {
      winner = 0;
      startImageLoader(TIE_IMAGE_FILE);
      repaint();
      return;
    }

    insertedInPegNum = mapPosToPeg(position);

    availableBeads[currentBead].setX(
        PEG_INITIAL_X[insertedInPegNum - 1]
            - (int) (availableBeads[currentBead].getBounds().getWidth() / 2));
    availableBeads[currentBead].setY(PEG_INITIAL_Y[insertedInPegNum - 1]);

    pegs[insertedInPegNum - 1].addBead(availableBeads[currentBead]);

    remoteBeadAnimTimer = new Timer(ANIMATION_REFRESH_RATE, this);
    remoteBeadAnimTimer.setActionCommand("remote bead animator");

    // sets the peg
    remoteBeadAnimTimer.setRepeats(true);
    remoteBeadAnimTimer.start();
    // creates and inserts new bead
    currentBead++;

    // System.out.println( "Type of game: " + typeOfGame );
    if (typeOfGame.equals("Gertrudis vs Computer")) {

      if (currentBead % 2 != 0) {
        availableBeads[currentBead] = new Bead(BEAD_INITIAL_X, BEAD_INITIAL_Y, 'b');
        availableBeads[currentBead].setImage(board.getBlackBeadImage());
      } else {
        availableBeads[currentBead] = new Bead(BEAD_INITIAL_X, BEAD_INITIAL_Y, 'w');
        availableBeads[currentBead].setImage(board.getWhiteBeadImage());
      }

    } else {
      availableBeads[currentBead] = new Bead(BEAD_INITIAL_X, BEAD_INITIAL_Y, 'w');
      availableBeads[currentBead].setImage(board.getWhiteBeadImage());
    }
  }
Пример #2
0
  @Override
  public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    displayNames(g);
    displayWinner(g);
    g2d.drawImage(board.getImage(), board.getX(), board.getY(), null, null);

    for (int i = 0; i < 16; i++) {
      g2d.drawImage(pegs[i].getImage(), pegs[i].getX(), pegs[i].getY(), null, null);
      for (int j = 0; j < pegs[i].amountOfBeads2(); j++) {
        g2d.drawImage(
            pegs[i].beadAt(j).getImage(),
            pegs[i].beadAt(j).getX(),
            pegs[i].beadAt(j).getY(),
            null,
            null);
      }
    }

    if (availableBeads[currentBead].getImage() == null) {
      availableBeads[currentBead].loadImage();
    }

    g2d.drawImage(
        availableBeads[currentBead].getImage(),
        availableBeads[currentBead].getX(),
        availableBeads[currentBead].getY(),
        null,
        null);

    if (beadMustAnimate) {
      animationTimer = new Timer(ANIMATION_REFRESH_RATE, this); // every
      // REFRESH_RATE
      // ms
      animationTimer.setActionCommand("animation");
      animationTimer.start();
      beadMustAnimate = false;
      currentBead++;
      // creates next new bead
      availableBeads[currentBead] = new Bead(BEAD_INITIAL_X, BEAD_INITIAL_Y, 'b');
      availableBeads[currentBead].setImage(board.getBlackBeadImage());
    }
  }