Ejemplo n.º 1
0
  // ---------------------Spielablauf------------------------------------------------------------
  private boolean isDone() {

    for (PuzzelHAButton[] b : buttons) {
      for (PuzzelHAButton button : b) {
        if (!button.getRight()) return false;
      }
    }
    return true;
  }
Ejemplo n.º 2
0
  // --------------------ActionEvent-------------------------------------------------------------
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() instanceof PuzzelHAButton) {
      if (firstClick) {
        firstClick = false;
        lastIcon = buttons[0][0].getIcon();
        buttons[0][0].setIcon(null);
        for (int i = 0; i < 10000; i++) {
          int zufallY = (int) ((Math.random() * YY) + 0);
          int zufallX = (int) ((Math.random() * XX) + 0);
          switchButton(zufallY, zufallX);
        }

        while (lastButtonX != 0) switchButton(lastButtonY, lastButtonX - 1);
        while (lastButtonY != 0) switchButton(lastButtonY - 1, lastButtonX);

      } else {
        PuzzelHAButton tmp = (PuzzelHAButton) e.getSource();
        int posY = tmp.getPosY();
        int posX = tmp.getPosX();

        switchButton(posY, posX);
        if (isDone()) {
          buttons[0][0].setIcon(lastIcon);
          firstClick = true;
        }
      }

    } else if (e.getSource() instanceof JMenuItem) {
      if (e.getActionCommand().equals("reset")) {
        neu(XX, YY);
      }

      if (e.getActionCommand().equals("?")) {
        JFrame inf = new JFrame("Info");
        inf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        JLabel jl = new JLabel();
        jl.setIcon(new ImageIcon("modify.jpg"));
        inf.add(jl, BorderLayout.CENTER);
        inf.setLocationRelativeTo(window);
        inf.pack();
        inf.setResizable(false);
        inf.setVisible(true);
      }

      if (e.getSource() instanceof JRadioButtonMenuItem) {
        switch (e.getActionCommand()) {
          case "g1":
            neu(2, 3);
            break;
          case "g2":
            neu(4, 3);
            break;
          case "g3":
            neu(6, 5);
            break;
          case "g4":
            neu(8, 7);
            break;
          case "b":
            JRadioButtonMenuItem temp = (JRadioButtonMenuItem) e.getSource();
            bildNr = temp.getName();
            neu(XX, YY);
            break;
          default:
            System.out.println("Test");
            break;
        }
      }
    }
  }