Quantcast
Channel: Memory game - comparing if same card - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Memory game - comparing if same card

$
0
0

I'm trying to create a memory game with pokemon cards. It seems to work half of the time. When two pictures are the same it does seem to work but sometimes when i click another time, it hides only one of the pictures or sometimes it hides the wrong one. Do I need to post my whole code ? If not, here's my actionPerformed where I compare if it's the same card or not. tableauChoisi is my array that contains the numbers of pokemons. jbtnTout is my array of buttons

// ------------------------------------------------------------------------
    public void actionPerformed(ActionEvent e) {
// ------------------------------------------------------------------------
        Object src = e.getSource();
         int tamponImage = 0;
        final int temp = tamponImage;
        int tamponIndice = 0;


        for (int i = 0; i < jbtnTout.length; i++) {
            final int ii = i;
            if (src == jbtnTout[i]) {
                click++;
                if (click == 1) {
                    jbtnTout[i].setIcon(icon[tableauChoisi[i]]);
                    tamponImage = (int) (tableauChoisi[i]);
                    tamponIndice = i;
                }

                if (click == 2) {
                    jbtnTout[i].setIcon(icon[tableauChoisi[i]]);
                    click = 0;
                    if (tableauChoisi[tamponImage] == tableauChoisi[i]) {

                        jbtnTout[temp]
                                .setIcon(icon[tableauChoisi[ii]]);
                        jbtnTout[ii]
                                .setIcon(icon[tableauChoisi[ii]]);
                    } else if (tableauChoisi[tamponImage] != tableauChoisi[i]) {

                        new Thread(){
                            public void run(){
                                jbtnTout[temp].setIcon(icon[0]);
                                jbtnTout[ii].setIcon(icon[0]);
                            try{
                            Thread.sleep(5);
                        }catch(InterruptedException e){

                        }

                            }
                    }.start();
                    }
                }
            }
        }
    }

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images