Память игры Action Listener Отладка - PullRequest
0 голосов
/ 17 октября 2018

После долгого времени, потраченного на то, чтобы заставить мой actionlistener делать то, что я хочу, я пришел к нескольким проблемам отладки, которые я просто не понимаю.

После нахождения правильной пары в игре первая правильная пара работает правильно, отключает две выбранные кнопки и продолжает движение.После этого сравнения перестают работать.Я не могу понять, почему.После настройки System.out.print проверяет, не было ли в программе повторное нажатие, но это не позволяет выполнить другое сравнение или сбросить кнопки из оператора else.

Ниже я перечислилмой главный слушатель действий и мой слушатель пауз.Спасибо, и если вам нужно больше данных, с радостью обновите.

  ActionListener timerPause = new ActionListener() {

        public void actionPerformed(ActionEvent e) {



            for (int i = 0; i < jToggleLength; i++) {

                jToggleButtons[i].setEnabled(true);
                tempIconThree = ((ImageIcon) 
        jToggleButtons[i].getSelectedIcon()).getDescription();

                    //flip the selected buttons back over
                if(jToggleButtons[i].isSelected()){
                       jToggleButtons[i].doClick();

                    }
                }
        }
    };

    /**
     * sets the pause timer period to 1.5 seconds
     * sets it to the actionListener Timerpause
     */

    pause = new Timer(1500, timerPause);


   public void actionPerformed(ActionEvent ae) {

    //starts timer
    //increments click on each action
    pause.stop();
    timer.start();
    click++;

    //if jtogglelength = 0 the user has completed the game and the timer stops
    if (jToggleLength == 0) {

        timer.stop();
        click = 0;

    }

    //on first click the jtoggle button source is set to temp and the temp icon gets description
    if (click == 1) {

        temp = (JToggleButton) ae.getSource();
        tempIcon = ((ImageIcon) temp.getSelectedIcon()).getDescription();

    }
    // on click two the jtoggle button source is set to tempTwo and the tempTwo icon gets description
    if (click == 2) {

        tempTwo = (JToggleButton) ae.getSource();
        tempIconTwo = ((ImageIcon) tempTwo.getSelectedIcon()).getDescription();

        //if the button is the same button set click to zero and do nothing else
        if (temp == tempTwo) {

            click = 0;

        //if the temp icon descriptions are equivalent move forward
        }  else if (tempIcon.equals(tempIconTwo)) {

                click = 0;

                //this for loop sets tempIconThree in every loop to compare to my first two icon descriptions
                //if they match, disable that button and set the button to null
                //if the button is not null add it to an arraylist
                for (int j = 0; j < jToggleLength; j++) {

                    tempIconThree = ((ImageIcon) jToggleButtons[j].getSelectedIcon()).getDescription();

                    if (tempIcon.equals(tempIconThree) || tempTwo.equals(tempIconThree)) {

                        jToggleButtons[j].setEnabled(false);
                        jToggleButtons[j] = null;

                        if (jToggleButtons[j] != null) {

                            arrayEdit.add(jToggleButtons[j]);
                        }

                    }

                }
                //reduce the length of the array by 2
                //make a new version of the main jtogglebutton array with reduced length
                //add the non null elements from the arrayList to the array
                jToggleLength = -2;
                for (int k = 0; k < jToggleLength; k++) {

                    jToggleButtons = new JToggleButton[jToggleLength];
                    jToggleButtons[k] = arrayEdit.get(k);

                }

                click = 0;
            //if the icon descriptions did not match
            //disable all buttons, pause for 1.5 seconds, flip the 
            selected buttons back up
            } else {

                for (int i = 0; i < jToggleLength; i++) {

                    jToggleButtons[i].setEnabled(false);


                }

                pause.start();
                click = 0;


            }
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...