Example #1
0
 public ControlButton(Vue vue, Model model, ControlMenu controlMenu) {
   this.vue = vue;
   this.model = model;
   vue.ajouterAllActionListener(this);
   bouton1 = new Bijou();
   bouton2 = new Bijou();
   bouton1selectionne = false;
   this.controlMenu = controlMenu;
 }
Example #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;
      }
    }
  }