Reseter une grille de jeu

olihya
Reseter une grille de jeu

Bonjour à vous,
Bonjour NIROKEN
Bonjour FREDERICMAZUE
Encore merci à NIROKEN pour ta participation exceptionnelle.
Voici ma question.
Je suis toujours sur mon jeu de REVERSO (cf: mes autres topics).
J'ai avancé mais je bloque en voulant reseter ma grille de pions.
J'aimerai pouvoir reseter la grille et continuer sur le niveau en cours.
Si vous avez une idée, elle est la bienvenue.
Une autre question, j'aimerai que une fois que le pion est joué, que la grille pivote sur un axe vertical passant en son centre.
Mais je pense qu'il aurait fallut que je fasse un tableau à 2 dimensions pour faire cela.
Qu'en pensez vous?
J'attend vos conseils d'expert.
Bonne journée.
Voici le code:

package reverso;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Fenetre extends JFrame implements ActionListener, Icon {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel pan = new JPanel();
	private JMenuBar barreMenus;
	private JMenu niveaux;
	private JMenu raz0;
	private JMenuItem raz;
	private JMenuItem niveau1, niveau2, niveau3, niveau4;
	protected ImageIcon b1;
	protected ImageIcon b2;
	protected JButton[] b;
	private String selectedNiveau;

	public Fenetre() {

		this.setTitle("Reverso");
		this.setSize(450, 500);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setResizable(true);
		this.setLocationRelativeTo(null);
		barreMenus = new JMenuBar();
		setJMenuBar(barreMenus);
		niveaux = new JMenu("Niveaux");
		raz0 = new JMenu("Reset");
		barreMenus.add(niveaux);
		barreMenus.add(raz0);
		raz = new JMenuItem("Raz");
		raz0.add(raz);
		raz.addActionListener(this);
		niveau1 = new JMenuItem("Niveau1");
		niveaux.add(niveau1);
		niveau1.addActionListener(this);
		niveau2 = new JMenuItem("Niveau2");
		niveaux.add(niveau2);
		niveau2.addActionListener(this);
		niveau3 = new JMenuItem("Niveau3");
		niveaux.add(niveau3);
		niveau3.addActionListener(this);
		niveau4 = new JMenuItem("Niveau4");
		niveaux.add(niveau4);
		niveau4.addActionListener(this);

		setLayout(new GridLayout(5, 5, 0, 0));
		JOptionPane
				.showMessageDialog(pan,
						"<html>BIENVENU DANS LE JEU <BR>VEUILLEZ SELECTIONNER UN NIVEAU.</html>");
		JButton[] b = new JButton[25];
		this.b = b;
		for (int i = 0; i < b.length; i++) {
			b1 = new ImageIcon("b1.gif");
			b2 = new ImageIcon("b2.gif");
			b[i] = new JButton(b1);
			b[i].setSelectedIcon(b2); 
			b[i].addActionListener(this);
			pan.setLayout(new GridLayout(5, 5));
			pan.add(b[i]);
		}
		setContentPane(pan);
	}

	{

		this.setContentPane(pan);
		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		Object source = e.getSource();
		if (source instanceof JMenuItem) {
			if (source == raz) {
				for (int i = 0; i < b.length; i++) {
					b1 = new ImageIcon("b1.gif");
					b[i].setSelectedIcon(b1);
					b[i].addActionListener(this);
					
				}
			}
		}
		if (source instanceof JMenuItem) {
			if (source == niveau1) {
				selectedNiveau = "niveau1";
				JOptionPane
						.showMessageDialog(
								niveau1,
								"<html>NIVEAU 1<br>VOUS DEVEZ RETOURNER TOUT LES PIONS.<br>SACHANT QUE LORSQUE VOUS CLIQUEZ SUR UN PION, <BR>LES PIONS AU DESSUS, EN DESSOUS ET SUR LES CÔTES SE RETOURNENT AUSSI.</html>");

			} else if (source == niveau2) {
				selectedNiveau = "niveau2";
				JOptionPane
						.showMessageDialog(
								niveau2,
								"<html>NIVEAU 2<br>VOUS DEVEZ RETOURNER TOUT LES PIONS.<br>LORSQUE VOUS CLIQUEZ SUR UN PION, <BR>C'EST LE PION OPPOSE SELON L'AXE HORIZONTAL <BR>AINSI QUE LES PIONS AU DESSUS, EN DESSOUS ET SUR LES CÔTES QUI SE RETOURNENT.</html>");

			} else if (source == niveau3) {
				selectedNiveau = "niveau3";
				JOptionPane
						.showMessageDialog(
								niveau3,
								"<html>NIVEAU 3<br>VOUS DEVEZ RETOURNER TOUT LES PIONS.<br>LORSQUE VOUS CLIQUEZ SUR UN PION, <BR>C'EST LE PION OPPOSE SELON L'AXE VERTICAL <BR>AINSI QUE LES PIONS AU DESSUS, EN DESSOUS ET SUR LES CÔTES QUI SE RETOURNENT.</html>");

			} else if (source == niveau4) {
				selectedNiveau = "niveau4";
				JOptionPane
						.showMessageDialog(
								niveau4,
								"<html>NIVEAU 4<br>VOUS DEVEZ RETOURNER TOUT LES PIONS.<br>LORSQUE VOUS CLIQUEZ SUR UN PION, <BR>C'EST LE PION OPPOSE SELON LA DIAGONALE PARTANT DU HAUT A DROITE VERS LA BAS A GAUCHE <BR>AINSI QUE LES PIONS AU DESSUS, EN DESSOUS ET SUR LES CÔTES QUI SE RETOURNENT.</html>");

			}
		} else if (source instanceof JButton) {

			if (selectedNiveau.equals("niveau1")) {
				for (int i = 6; i <= 8; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				for (int i = 11; i <= 13; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}

				for (int i = 16; i <= 18; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				for (int i = 0; i <= 0; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
					}
				}
				for (int i = 4; i <= 4; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
					}
				}
				for (int i = 20; i <= 20; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				for (int i = 24; i <= 24; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				for (int i = 1; i <= 3; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
					}
				}
				for (int i = 5; i <= 5; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				for (int i = 10; i <= 10; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				for (int i = 15; i <= 15; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				for (int i = 21; i <= 23; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				for (int i = 9; i <= 9; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
					}
				}
				for (int i = 14; i <= 14; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
					}
				}
				for (int i = 19; i <= 19; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
					}
				}
				if ((b[0].isSelected()) && (b[1].isSelected())

				&& (b[2].isSelected()) && (b[3].isSelected())

				&& (b[4].isSelected()) && (b[5].isSelected())

				&& (b[6].isSelected()) && (b[7].isSelected())

				&& (b[8].isSelected()) && (b[9].isSelected())

				&& (b[10].isSelected()) && (b[11].isSelected())

				&& (b[12].isSelected()) && (b[13].isSelected())

				&& (b[14].isSelected()) && (b[15].isSelected())

				&& (b[16].isSelected()) && (b[17].isSelected())

				&& (b[18].isSelected()) && (b[19].isSelected())

				&& (b[20].isSelected()) && (b[21].isSelected())

				&& (b[22].isSelected()) && (b[23].isSelected())

				&& (b[24].isSelected())) {

					JOptionPane
							.showMessageDialog(niveau1,
									"<html>BRAVO, C'EST GAGNE!!!<br>ESSAYEZ LE NIVEAU 2.</html>");
				}
			}
			if (selectedNiveau.equals("niveau2")) {
				for (int i = 6; i <= 8; i++) {
					if (source == b[i]) {
						b[i + 10].setSelected(!b[i + 10].isSelected());
						b[i + 9].setSelected(!b[i + 9].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i + 11].setSelected(!b[i + 11].isSelected());
						b[i + 15].setSelected(!b[i + 15].isSelected());
					}
				}
				for (int i = 11; i <= 13; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}

				for (int i = 16; i <= 18; i++) {
					if (source == b[i]) {
						b[i - 10].setSelected(!b[i - 10].isSelected());
						b[i - 9].setSelected(!b[i - 9].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
						b[i - 11].setSelected(!b[i - 11].isSelected());
						b[i - 15].setSelected(!b[i - 15].isSelected());
					}
				}
				for (int i = 0; i <= 0; i++) {
					if (source == b[i]) {
						b[i + 20].setSelected(!b[i + 20].isSelected());
						b[i + 21].setSelected(!b[i + 21].isSelected());
						b[i + 15].setSelected(!b[i + 15].isSelected());
					}
				}
				for (int i = 4; i <= 4; i++) {
					if (source == b[i]) {
						b[i + 20].setSelected(!b[i + 20].isSelected());
						b[i + 19].setSelected(!b[i + 19].isSelected());
						b[i + 15].setSelected(!b[i + 15].isSelected());
					}
				}
				for (int i = 20; i <= 20; i++) {
					if (source == b[i]) {
						b[i - 20].setSelected(!b[i - 20].isSelected());
						b[i - 19].setSelected(!b[i - 19].isSelected());
						b[i - 15].setSelected(!b[i - 15].isSelected());
					}
				}
				for (int i = 24; i <= 24; i++) {
					if (source == b[i]) {
						b[i - 20].setSelected(!b[i - 20].isSelected());
						b[i - 21].setSelected(!b[i - 21].isSelected());
						b[i - 15].setSelected(!b[i - 15].isSelected());
					}
				}
				for (int i = 1; i <= 3; i++) {
					if (source == b[i]) {
						b[i + 20].setSelected(!b[i + 20].isSelected());
						b[i + 19].setSelected(!b[i + 19].isSelected());
						b[i + 21].setSelected(!b[i + 21].isSelected());
						b[i + 15].setSelected(!b[i + 15].isSelected());
					}
				}
				for (int i = 5; i <= 5; i++) {
					if (source == b[i]) {
						b[i + 10].setSelected(!b[i + 10].isSelected());
						b[i + 11].setSelected(!b[i + 11].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i + 15].setSelected(!b[i + 15].isSelected());
					}
				}
				for (int i = 9; i <= 9; i++) {
					if (source == b[i]) {
						b[i + 10].setSelected(!b[i + 10].isSelected());
						b[i + 9].setSelected(!b[i + 9].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i + 15].setSelected(!b[i + 15].isSelected());
					}
				}
				for (int i = 10; i <= 10; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i + 1].setSelected(!b[i + 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				for (int i = 15; i <= 15; i++) {
					if (source == b[i]) {
						b[i - 10].setSelected(!b[i - 10].isSelected());
						b[i - 15].setSelected(!b[i - 15].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
						b[i - 9].setSelected(!b[i - 9].isSelected());
					}
				}
				for (int i = 21; i <= 23; i++) {
					if (source == b[i]) {
						b[i - 20].setSelected(!b[i - 20].isSelected());
						b[i - 21].setSelected(!b[i - 21].isSelected());
						b[i - 19].setSelected(!b[i - 19].isSelected());
						b[i - 15].setSelected(!b[i - 15].isSelected());
					}
				}
				for (int i = 14; i <= 14; i++) {
					if (source == b[i]) {
						b[i].setSelected(!b[i].isSelected());
						b[i - 1].setSelected(!b[i - 1].isSelected());
						b[i + 5].setSelected(!b[i + 5].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				for (int i = 19; i <= 19; i++) {
					if (source == b[i]) {
						b[i - 10].setSelected(!b[i - 10].isSelected());
						b[i - 15].setSelected(!b[i - 15].isSelected());
						b[i - 11].setSelected(!b[i - 11].isSelected());
						b[i - 5].setSelected(!b[i - 5].isSelected());
					}
				}
				if ((b[0].isSelected()) && (b[1].isSelected())

				&& (b[2].isSelected()) && (b[3].isSelected())

				&& (b[4].isSelected()) && (b[5].isSelected())

				&& (b[6].isSelected()) && (b[7].isSelected())

				&& (b[8].isSelected()) && (b[9].isSelected())

				&& (b[10].isSelected()) && (b[11].isSelected())

				&& (b[12].isSelected()) && (b[13].isSelected())

				&& (b[14].isSelected()) && (b[15].isSelected())

				&& (b[16].isSelected()) && (b[17].isSelected())

				&& (b[18].isSelected()) && (b[19].isSelected())

				&& (b[20].isSelected()) && (b[21].isSelected())

				&& (b[22].isSelected()) && (b[23].isSelected())

				&& (b[24].isSelected())) {

					JOptionPane
							.showMessageDialog(niveau2,
									"<html>BRAVO, C'EST GAGNE!!!<br>ESSAYEZ LE NIVEAU 3.</html>");
				}
			}
		}
		if (selectedNiveau.equals("niveau3")) {

			for (int i = 6; i <= 6; i++) {
				if (source == b[i]) {
					b[i + 2].setSelected(!b[i + 2].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
					b[i + 7].setSelected(!b[i + 7].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
				}
			}
			for (int i = 11; i <= 11; i++) {
				if (source == b[i]) {
					b[i + 2].setSelected(!b[i + 2].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
					b[i + 7].setSelected(!b[i + 7].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
				}
			}

			for (int i = 16; i <= 16; i++) {
				if (source == b[i]) {
					b[i + 2].setSelected(!b[i + 2].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
					b[i + 7].setSelected(!b[i + 7].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
				}
			}
			for (int i = 17; i <= 17; i++) {
				if (source == b[i]) {
					b[i].setSelected(!b[i].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
				}
			}
			for (int i = 12; i <= 12; i++) {
				if (source == b[i]) {
					b[i].setSelected(!b[i].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
				}
			}
			for (int i = 7; i <= 7; i++) {
				if (source == b[i]) {
					b[i].setSelected(!b[i].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
				}
			}
			for (int i = 8; i <= 8; i++) {
				if (source == b[i]) {
					b[i - 2].setSelected(!b[i - 2].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i - 7].setSelected(!b[i - 7].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
				}
			}
			for (int i = 13; i <= 13; i++) {
				if (source == b[i]) {
					b[i - 2].setSelected(!b[i - 2].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i - 7].setSelected(!b[i - 7].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
				}
			}
			for (int i = 18; i <= 18; i++) {
				if (source == b[i]) {
					b[i - 2].setSelected(!b[i - 2].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i - 7].setSelected(!b[i - 7].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
				}
			}
			for (int i = 0; i <= 0; i++) {
				if (source == b[i]) {
					b[i + 4].setSelected(!b[i + 4].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
					b[i + 9].setSelected(!b[i + 9].isSelected());
				}
			}
			for (int i = 4; i <= 4; i++) {
				if (source == b[i]) {
					b[i - 4].setSelected(!b[i - 4].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
				}
			}
			for (int i = 20; i <= 20; i++) {
				if (source == b[i]) {
					b[i + 4].setSelected(!b[i + 4].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
				}
			}
			for (int i = 24; i <= 24; i++) {
				if (source == b[i]) {
					b[i - 4].setSelected(!b[i - 4].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
					b[i - 9].setSelected(!b[i - 9].isSelected());
				}
			}
			for (int i = 1; i <= 1; i++) {
				if (source == b[i]) {
					b[i + 2].setSelected(!b[i + 2].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
					b[i + 7].setSelected(!b[i + 7].isSelected());
				}
			}
			for (int i = 2; i <= 2; i++) {
				if (source == b[i]) {
					b[i].setSelected(!b[i].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
				}
			}
			for (int i = 3; i <= 3; i++) {
				if (source == b[i]) {
					b[i - 2].setSelected(!b[i - 2].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
				}
			}
			for (int i = 5; i <= 5; i++) {
				if (source == b[i]) {
					b[i + 4].setSelected(!b[i + 4].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 9].setSelected(!b[i + 9].isSelected());
				}
			}
			for (int i = 10; i <= 10; i++) {
				if (source == b[i]) {
					b[i + 4].setSelected(!b[i + 4].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 9].setSelected(!b[i + 9].isSelected());
				}
			}
			for (int i = 15; i <= 15; i++) {
				if (source == b[i]) {
					b[i + 4].setSelected(!b[i + 4].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 9].setSelected(!b[i + 9].isSelected());
				}
			}
			for (int i = 9; i <= 9; i++) {
				if (source == b[i]) {
					b[i - 4].setSelected(!b[i - 4].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
					b[i - 9].setSelected(!b[i - 9].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
				}
			}
			for (int i = 14; i <= 14; i++) {
				if (source == b[i]) {
					b[i - 4].setSelected(!b[i - 4].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
					b[i - 9].setSelected(!b[i - 9].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
				}
			}
			for (int i = 19; i <= 19; i++) {
				if (source == b[i]) {
					b[i - 4].setSelected(!b[i - 4].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
					b[i - 9].setSelected(!b[i - 9].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
				}
			}
			for (int i = 21; i <= 21; i++) {
				if (source == b[i]) {
					b[i + 2].setSelected(!b[i + 2].isSelected());
					b[i + 3].setSelected(!b[i + 3].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
				}
			}
			for (int i = 22; i <= 22; i++) {
				if (source == b[i]) {
					b[i].setSelected(!b[i].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
				}
			}
			for (int i = 23; i <= 23; i++) {
				if (source == b[i]) {
					b[i - 2].setSelected(!b[i - 2].isSelected());
					b[i - 3].setSelected(!b[i - 3].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i - 7].setSelected(!b[i - 7].isSelected());
				}
			}
			if ((b[0].isSelected()) && (b[1].isSelected())

			&& (b[2].isSelected()) && (b[3].isSelected())

			&& (b[4].isSelected()) && (b[5].isSelected())

			&& (b[6].isSelected()) && (b[7].isSelected())

			&& (b[8].isSelected()) && (b[9].isSelected())

			&& (b[10].isSelected()) && (b[11].isSelected())

			&& (b[12].isSelected()) && (b[13].isSelected())

			&& (b[14].isSelected()) && (b[15].isSelected())

			&& (b[16].isSelected()) && (b[17].isSelected())

			&& (b[18].isSelected()) && (b[19].isSelected())

			&& (b[20].isSelected()) && (b[21].isSelected())

			&& (b[22].isSelected()) && (b[23].isSelected())

			&& (b[24].isSelected())) {

				JOptionPane
						.showMessageDialog(niveau3,
								"<html>BRAVO, C'EST GAGNE!!!<br>ESSAYEZ LE NIVEAU 4.</html>");
			}
		}
		if (selectedNiveau.equals("niveau4")) {
			for (int i = 6; i <= 6; i++) {
				if (source == b[i]) {
					b[i + 12].setSelected(!b[i + 12].isSelected());
					b[i + 13].setSelected(!b[i + 13].isSelected());
					b[i + 11].setSelected(!b[i + 11].isSelected());
					b[i + 7].setSelected(!b[i + 7].isSelected());
					b[i + 17].setSelected(!b[i + 17].isSelected());
				}
			}

			for (int i = 18; i <= 18; i++) {
				if (source == b[i]) {
					b[i - 12].setSelected(!b[i - 12].isSelected());
					b[i - 13].setSelected(!b[i - 13].isSelected());
					b[i - 11].setSelected(!b[i - 11].isSelected());
					b[i - 7].setSelected(!b[i - 7].isSelected());
					b[i - 17].setSelected(!b[i - 17].isSelected());
				}
			}
			for (int i = 7; i <= 7; i++) {
				if (source == b[i]) {
					b[i + 6].setSelected(!b[i + 6].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
					b[i + 11].setSelected(!b[i + 11].isSelected());
					b[i + 7].setSelected(!b[i + 7].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
				}
			}
			for (int i = 13; i <= 13; i++) {
				if (source == b[i]) {
					b[i - 6].setSelected(!b[i - 6].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
					b[i - 11].setSelected(!b[i - 11].isSelected());
					b[i - 7].setSelected(!b[i - 7].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
				}
			}
			for (int i = 8; i <= 8; i++) {
				if (source == b[i]) {
					b[i].setSelected(!b[i].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
				}
			}
			for (int i = 12; i <= 12; i++) {
				if (source == b[i]) {
					b[i].setSelected(!b[i].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
				}
			}

			for (int i = 16; i <= 16; i++) {
				if (source == b[i]) {
					b[i].setSelected(!b[i].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
				}
			}
			for (int i = 4; i <= 4; i++) {
				if (source == b[i]) {
					b[i].setSelected(!b[i].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
				}
			}
			for (int i = 20; i <= 20; i++) {
				if (source == b[i]) {
					b[i].setSelected(!b[i].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
				}
			}
			for (int i = 0; i <= 0; i++) {
				if (source == b[i]) {
					b[i + 24].setSelected(!b[i + 24].isSelected());
					b[i + 23].setSelected(!b[i + 23].isSelected());
					b[i + 19].setSelected(!b[i + 19].isSelected());
				}
			}
			for (int i = 24; i <= 24; i++) {
				if (source == b[i]) {
					b[i - 24].setSelected(!b[i - 24].isSelected());
					b[i - 23].setSelected(!b[i - 23].isSelected());
					b[i - 19].setSelected(!b[i - 19].isSelected());
				}
			}
			for (int i = 11; i <= 11; i++) {
				if (source == b[i]) {
					b[i + 6].setSelected(!b[i + 6].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
					b[i + 11].setSelected(!b[i + 11].isSelected());
					b[i + 7].setSelected(!b[i + 7].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
				}
			}
			for (int i = 17; i <= 17; i++) {
				if (source == b[i]) {
					b[i - 6].setSelected(!b[i - 6].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
					b[i - 11].setSelected(!b[i - 11].isSelected());
					b[i - 7].setSelected(!b[i - 7].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
				}
			}
			for (int i = 1; i <= 1; i++) {
				if (source == b[i]) {
					b[i + 18].setSelected(!b[i + 18].isSelected());
					b[i + 17].setSelected(!b[i + 17].isSelected());
					b[i + 23].setSelected(!b[i + 23].isSelected());
					b[i + 13].setSelected(!b[i + 13].isSelected());
				}
			}
			for (int i = 19; i <= 19; i++) {
				if (source == b[i]) {
					b[i - 18].setSelected(!b[i - 18].isSelected());
					b[i - 17].setSelected(!b[i - 17].isSelected());
					b[i - 19].setSelected(!b[i - 19].isSelected());
					b[i - 13].setSelected(!b[i - 13].isSelected());
				}
			}
			for (int i = 2; i <= 2; i++) {
				if (source == b[i]) {
					b[i + 12].setSelected(!b[i + 12].isSelected());
					b[i + 11].setSelected(!b[i + 11].isSelected());
					b[i + 17].setSelected(!b[i + 17].isSelected());
					b[i + 7].setSelected(!b[i + 7].isSelected());
				}
			}
			for (int i = 14; i <= 14; i++) {
				if (source == b[i]) {
					b[i - 12].setSelected(!b[i - 12].isSelected());
					b[i - 11].setSelected(!b[i - 11].isSelected());
					b[i - 13].setSelected(!b[i - 13].isSelected());
					b[i - 7].setSelected(!b[i - 7].isSelected());
				}
			}
			for (int i = 3; i <= 3; i++) {
				if (source == b[i]) {
					b[i + 5].setSelected(!b[i + 5].isSelected());
					b[i + 6].setSelected(!b[i + 6].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
					b[i + 11].setSelected(!b[i + 11].isSelected());
				}
			}
			for (int i = 9; i <= 9; i++) {
				if (source == b[i]) {
					b[i - 5].setSelected(!b[i - 5].isSelected());
					b[i - 6].setSelected(!b[i - 6].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
					b[i - 7].setSelected(!b[i - 7].isSelected());
				}
			}
			for (int i = 5; i <= 5; i++) {
				if (source == b[i]) {
					b[i + 17].setSelected(!b[i + 17].isSelected());
					b[i + 18].setSelected(!b[i + 18].isSelected());
					b[i + 19].setSelected(!b[i + 19].isSelected());
					b[i + 13].setSelected(!b[i + 13].isSelected());
				}
			}
			for (int i = 23; i <= 23; i++) {
				if (source == b[i]) {
					b[i - 17].setSelected(!b[i - 17].isSelected());
					b[i - 18].setSelected(!b[i - 18].isSelected());
					b[i - 23].setSelected(!b[i - 23].isSelected());
					b[i - 13].setSelected(!b[i - 13].isSelected());
				}
			}
			for (int i = 10; i <= 10; i++) {
				if (source == b[i]) {
					b[i + 12].setSelected(!b[i + 12].isSelected());
					b[i + 11].setSelected(!b[i + 11].isSelected());
					b[i + 13].setSelected(!b[i + 13].isSelected());
					b[i + 7].setSelected(!b[i + 7].isSelected());
				}
			}
			for (int i = 22; i <= 22; i++) {
				if (source == b[i]) {
					b[i - 12].setSelected(!b[i - 12].isSelected());
					b[i - 11].setSelected(!b[i - 11].isSelected());
					b[i - 17].setSelected(!b[i - 17].isSelected());
					b[i - 7].setSelected(!b[i - 7].isSelected());
				}
			}
			for (int i = 15; i <= 15; i++) {
				if (source == b[i]) {
					b[i + 6].setSelected(!b[i + 6].isSelected());
					b[i + 5].setSelected(!b[i + 5].isSelected());
					b[i + 7].setSelected(!b[i + 7].isSelected());
					b[i + 1].setSelected(!b[i + 1].isSelected());
				}
			}
			for (int i = 21; i <= 21; i++) {
				if (source == b[i]) {
					b[i - 6].setSelected(!b[i - 6].isSelected());
					b[i - 5].setSelected(!b[i - 5].isSelected());
					b[i - 11].setSelected(!b[i - 11].isSelected());
					b[i - 1].setSelected(!b[i - 1].isSelected());
				}
			}

			if ((b[0].isSelected()) && (b[1].isSelected())

			&& (b[2].isSelected()) && (b[3].isSelected())

			&& (b[4].isSelected()) && (b[5].isSelected())

			&& (b[6].isSelected()) && (b[7].isSelected())

			&& (b[8].isSelected()) && (b[9].isSelected())

			&& (b[10].isSelected()) && (b[11].isSelected())

			&& (b[12].isSelected()) && (b[13].isSelected())

			&& (b[14].isSelected()) && (b[15].isSelected())

			&& (b[16].isSelected()) && (b[17].isSelected())

			&& (b[18].isSelected()) && (b[19].isSelected())

			&& (b[20].isSelected()) && (b[21].isSelected())

			&& (b[22].isSelected()) && (b[23].isSelected())

			&& (b[24].isSelected())) {

				JOptionPane
						.showMessageDialog(niveau4,
								"<html>BRAVO, C'EST GAGNE!!!<br>REVERSO N'A PLUS DE SECRET POUR VOUS.</html>");
			}
		}
	}

	@Override
	public int getIconHeight() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getIconWidth() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void paintIcon(Component c, Graphics g, int x, int y) {
		// TODO Auto-generated method stub

	}

}
Niroken

Hello Olihya,

Pour le reset c'est relativement simple, tu ajoutes une méthode privée à ta fenetre :

private void resetReverso() {
    for (int i = 0; i < b.length; i++) {
        b[i].setSelected(false);
    }
}

Ensuite, tu dois appeller cette méthode si tu cliques sur le boutton "raz" ou si tu changes de niveau en cours de jeu.

Ca donne ca :

public void actionPerformed(ActionEvent e) { 
      // TODO Auto-generated method stub 
      Object source = e.getSource(); 
      if (source instanceof JMenuItem) { 
         if (source == raz) { 
        	// APPEL DE  LA METHODE RESET 
               resetReverso();
         } 
      } 
      if (source instanceof JMenuItem) { 
    	  // APPEL DE  LA METHODE RESET 
             resetReverso();
    	  if (source == niveau1) { 
            selectedNiveau = "niveau1"; 
            JOptionPane 
                  .showMessageDialog( 
                        niveau1, 
                        "<html>NIVEAU 1<br>VOUS DEVEZ RETOURNER TOUT LES PIONS.<br>SACHANT QUE LORSQUE VOUS CLIQUEZ SUR UN PION, <BR>LES PIONS AU DESSUS, EN DESSOUS ET SUR LES CÔTES SE RETOURNENT AUSSI.</html>"); 

         }// etc etc 

Ca c'était la bonne nouvelle, la mauvaise, c'est qu'effectivemen si tu veux faire pivoter ta grille dans n'importe quel sens, il aurait mieux valu modéliser ca avec un tableau en 2D, la c'est possible, mais ca va etre sacrément casse c.....

Ensuite si je puis me permettre, il y a beaucoup de redondances de code dans ta méthode actionPerformed, par exemple :

if ((b[0].isSelected()) && (b[1].isSelected()) 

         && (b[2].isSelected()) && (b[3].isSelected()) 

         && (b[4].isSelected()) && (b[5].isSelected()) 

         && (b[6].isSelected()) && (b[7].isSelected()) 

         && (b[8].isSelected()) && (b[9].isSelected()) 

         && (b[10].isSelected()) && (b[11].isSelected()) 

         && (b[12].isSelected()) && (b[13].isSelected()) 

         && (b[14].isSelected()) && (b[15].isSelected()) 

         && (b[16].isSelected()) && (b[17].isSelected()) 

         && (b[18].isSelected()) && (b[19].isSelected()) 

         && (b[20].isSelected()) && (b[21].isSelected()) 

         && (b[22].isSelected()) && (b[23].isSelected()) 

         && (b[24].isSelected())) { 

            JOptionPane 
                  .showMessageDialog(niveau4, 
                        "<html>BRAVO, C'EST GAGNE!!!<br>REVERSO N'A PLUS DE SECRET POUR VOUS.</html>"); 
         } 

Tu imagines si ton tableau avait été de taille 10 000 :D ?
Si tu déclares une méthode qui vérifies si tous les pions de la grille sont séléctionnés par exemple :

private boolean isAllGridSelected() {
	   boolean vResult = true;
	   
	   for (int i = 0; i < b.length; i++) {
		   vResult = vResult && b[i].isSelected();
	   }
	   
	   return vResult;
   }

Du coup pour chaque niveau tu n'aurais plus qu a faire :

if (isAllGridSelected()) {
     JOptionPane 
                  .showMessageDialog(niveau4, 
                        "<html>BRAVO, C'EST GAGNE!!!<br>REVERSO N'A PLUS DE SECRET POUR VOUS.</html>"); 
}

C'est tt de même plus léger.

Il y a d'autres optimisations c'est sur mais on attendra de voir ce que tu décides pour le tableau à 2D ou pas :)

Bonne chance,
Niroken

olihya
Reseter une grille de jeu

Bonjour,
Franchement NIROKEN tu es un "oiseau rare".
Car tu répond toujours et toujours dans le mille.
Alors un grand merci à toi.
Je regarde tout ça.
Bonne soirée.