Exemple #1
0
  public void getCellsInfos() {
    nbPredateurs = 0;
    nbProies = 0;

    for (int i = 0; i < GUI.getRows(); i++)
      for (int j = 0; j < GUI.getCols(); j++) {
        if (GUI.getTheGame().getEnv().getCellAt(i, j) instanceof Predateur) nbPredateurs++;
        else nbProies++;
      }
  }
  @Override
  public void actionPerformed(ActionEvent e) {

    if (e.getActionCommand().equals("Start")) {
      if (Reconstruct.demarre == 0) {
        if (!GUI.getTxtCycles().getText().equals(""))
          GUI.iterer(Integer.parseInt(GUI.getTxtCycles().getText()));
        else GUI.iterer(0);
      }
    } else if (e.getActionCommand().equals("Stop")) {

      if (Reconstruct.demarre == 1) {
        Reconstruct.demarre = 0;
      }
    } else if (e.getActionCommand().equals("Générer")) {
      for (int i = 0; i < GUI.getRows(); i++)
        for (int j = 0; j < GUI.getCols(); j++) {

          if (MyRand()) {
            GUI.getTheGame().getEnv().setCellAt(i, j, new Predateur(i, j));
            GUI.getBtnList().get(i * GUI.getCols() + j).setBackground(Color.WHITE);
          }
        }
    } else {
      JButton temp = (JButton) e.getSource();
      int position = GUI.getBtnList().indexOf(temp);
      if (temp.getBackground() == Color.WHITE) {
        GUI.getTheGame()
            .getEnv()
            .setCellAt(
                position / GUI.getCols(),
                position % GUI.getRows(),
                new Proie(position / GUI.getCols(), position % GUI.getRows()));
        // GUI.getTheGame().getEnv().setCellAt(position/GUI.getCols(), position%GUI.getRows(),
        // false);
        temp.setBackground(Color.BLACK);
      } else {
        GUI.getTheGame()
            .getEnv()
            .setCellAt(
                position / GUI.getCols(),
                position % GUI.getRows(),
                new Predateur(position / GUI.getCols(), position % GUI.getRows()));
        // GUI.getTheGame().getEnv().setCellAt(position/GUI.getCols(), position%GUI.getRows(),
        // true);
        temp.setBackground(Color.WHITE);
      }
    }
  }