Пример #1
0
 private boolean estProche(Bijou bijou2) {
   int differenceX = bouton1.getPosition().getX() - bijou2.getPosition().getX();
   int differenceY = bouton1.getPosition().getY() - bijou2.getPosition().getY();
   if (((differenceX == 1 || differenceX == -1) && differenceY == 0)
       || (differenceX == 0 && (differenceY == -1 || differenceY == 1))) {
     return true;
   } else return false;
 }
Пример #2
0
  public void actionPerformed(ActionEvent e) {
    if (!model.getEstEnJeu()) {
      vue.getProgressBar().start();
      model.setEstEnJeu(true);
    }

    System.out.println(
        e.getSource().toString() + model.getBijou(((Bijou) e.getSource()).getPosition()));
    if (e.getSource().getClass() == bouton1.getClass()) {
      if (bouton1selectionne && estProche((Bijou) e.getSource())) {
        bouton2.setBackground(Color.WHITE);
        bouton2 = (Bijou) e.getSource();
        bouton2.setBackground(Color.DARK_GRAY);

        // model.permut(bouton1.getPosition(), bouton2.getPosition());
        // vue.actualiserCase(bouton1.getPosition());
        // vue.actualiserCase(bouton2.getPosition());

        model.actualiserCoupPossible();
        vue.actualiserTableau();

        if (model.estUnCoupValide(new Coup(bouton1.getPosition(), bouton2.getPosition()))) {
          controlMenu.setHintPressed(false);
          /*
          try {
              Thread.sleep(500);
          } catch (InterruptedException e1) {
              e1.printStackTrace();
          }*/
          model.permut(bouton1.getPosition(), bouton2.getPosition());
          vue.actualiserCase(bouton1.getPosition());
          vue.actualiserCase(bouton2.getPosition());

          bouton1selectionne = false;
          bouton1.setBackground(Color.WHITE);
          bouton2.setBackground(Color.WHITE);
          // model.actualiserCoupPossible();
          // vue.coloreCoupPossible();
          System.out.println("coup valide");
          /*
          try {
              Thread.sleep(500);
          } catch (InterruptedException e1) {
              e1.printStackTrace();
          }*/
          int score = 0;
          int newScore = 0;
          int progres = 0;
          ArrayList<ArrayList<Coord>> lignesCombo;
          do {
            lignesCombo = vue.coloreLigneCombo();
            newScore = compteScore(lignesCombo);
            score += newScore;
            progres += compteProgres(lignesCombo);
          } while (newScore != 0);

          model.addScore(score);
          vue.actualiserProgres(progres);
          vue.actualiserScore();

          /*
          try {
              Thread.sleep(500);
          } catch (InterruptedException e1) {
              e1.printStackTrace();
          }*/

          model.actualiserCoupPossible();
          vue.actualiserTableau();
          if (vue.getProgressBar().getValue() >= 100) {
            model.genererTableau();
            model.upLevel();
            vue.actualiserTableau();
            vue.drawMap();
            vue.setVisible(true);
            vue.getProgressBar().setValue(50);
          }
        } else {
          model.enleveUnTrie();
          vue.actualiserTries();
        }
      } else {
        bouton1.setBackground(Color.WHITE);
        bouton2.setBackground(Color.WHITE);
        bouton1 = (Bijou) e.getSource();
        bouton1.setBackground(Color.DARK_GRAY);
        bouton1selectionne = true;
      }
    }
  }