Voila après la séance d'ISN de vendredi, je l'ai refait chez moi, et j'ai ajouté tout ce qu'il fallait !
Annuler les derniers coup et même tous les coup, dans l'ordre chronologique de leur pose !
Les couleurs des boutons !
Recommencer.
- Code: Tout sélectionner
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Label;
// Completé et édité par Mathias !
public class jeudu100 {
static Display display;
protected Shell shell;
static int numeroplace=1;
static Button [][] bouton;
static Label victoire;
static Button undo;
static Button recommencer;
static int xxl=50;
static int yyl=50;
static int [][] deja;
private Label lblNewLabel;
private Label lblNewLabel_1;
public boolean autorise(int xx, int yy) {
//fonction a completer qui retourne true uniquement si on a le droit de deposer un nouvel entier
// dans la case de coordonnees (xx,yy)
boolean autorisation=false;
if (xxl==xx || yyl==yy) //si alignés xxl==xx+3 || xxl==xx-3
{
if(Math.abs(xxl-xx)==3){ //si alignés sur ligne
autorisation=true;
}
else{
if(Math.abs(yyl-yy)==3){ // si alignés sur colonne
autorisation=true;
}
else{ //sinon c'est faux
autorisation=false;
}
}
}
else{ //si non alignés
if(Math.abs(xxl-xx)==2 && Math.abs(yyl-yy)==2){ // si en diagonale avec 1 d'écart
autorisation=true;
}
else{
if(xxl==50 && yyl==50){ // si premier coup : cas spécial
autorisation=true;
}
else{ //sinon c'est faux !
autorisation=false;
}
}
}
return(autorisation);
}
public void inutilisable(int xx,int yy) {
//procedure qui rend inutilisable la case (xx,yy) qui vient d'etre complete
bouton[xx][yy].setEnabled(false);
bouton[xx][yy].setBackground(SWTResourceManager.getColor(255, 204, 102));
if(numeroplace>1){ // on change la couleur du dernier bouton pour ne pas le perdre de vue!
bouton[xxl][yyl].setBackground(SWTResourceManager.getColor(115, 150, 202));
}
}
public boolean gagne() {
//fonction a completer qui affiche "c'est gagne" dans un label que vous dessinerez
//(et qui retourne true a ce moment la )
// lorsque l'entier 100 a reussi a etre plae
// on pourra tester cette fonction
if(numeroplace>100){
victoire.setVisible(true);
recommencer.setVisible(true);
}
return(true);
}
public static void main(String[] args) {
try {
jeudu100 window = new jeudu100();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(630, 773);
shell.setText("Jeu du 100");
/// TOUT Cela c'EST POUR CENTRER LA FENETRE
org.eclipse.swt.widgets.Monitor primary = display.getPrimaryMonitor();
org.eclipse.swt.graphics.Rectangle bounds = primary.getBounds();
org.eclipse.swt.graphics.Rectangle rect = shell.getBounds();
int mm = bounds.x + (bounds.width - rect.width) / 2;
int nn = bounds.y + (bounds.height - rect.height) / 2;
shell.setLocation(mm, nn);
///
victoire = new Label(shell, SWT.NONE);
victoire.setVisible(false);
victoire.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
victoire.setFont(SWTResourceManager.getFont("Rockwell Condensed", 15, SWT.BOLD));
victoire.setBounds(280, 10, 92, 29);
victoire.setText("Victoire !");
bouton=new Button[11][11] ;
deja=new int[101][2] ;
undo = new Button(shell, SWT.NONE); // ANNULER DERNIER COUP
undo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int x=deja[numeroplace][0];
int y=deja[numeroplace][1];
if(numeroplace<=2){ // ce qui equivaut a recommencer
recommencer.setVisible(false);
victoire.setVisible(false);
for ( int i=1;i<=10;i++) {
for ( int j=1;j<=10;j++) {
bouton[i][j].setText("");
bouton[i][j].setEnabled(true);
bouton[i][j].setBackground(SWTResourceManager.getColor(250, 250, 250));
undo.setVisible(false);
xxl=50;
yyl=50;
numeroplace=1;
}
}
}
if(numeroplace>2){
bouton[x][y].setText("");
bouton[x][y].setEnabled(true);
bouton[x][y].setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
xxl=deja[numeroplace-1][0];
yyl=deja[numeroplace-1][1];
bouton[xxl][yyl].setBackground(SWTResourceManager.getColor(255, 204, 102));
numeroplace=numeroplace-1;
}
}
});
undo.setVisible(false);
undo.setFont(SWTResourceManager.getFont("Plantagenet Cherokee", 9, SWT.BOLD));
undo.setBounds(65, 12, 148, 27);
undo.setText("Annuler dernier coup");
recommencer = new Button(shell, SWT.NONE);
recommencer.setVisible(false);
recommencer.setFont(SWTResourceManager.getFont("Plantagenet Cherokee", 11, SWT.BOLD));
recommencer.setBounds(428, 10, 134, 29);
recommencer.setText("Recommencer");
lblNewLabel = new Label(shell, SWT.NONE); //les regles + le titre
lblNewLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
lblNewLabel.setFont(SWTResourceManager.getFont("Segoe UI", 8, SWT.ITALIC));
lblNewLabel.setBounds(79, 606, 556, 102);
lblNewLabel.setText("Le but du jeu du 100 est de placer les entiers de 1 \u00E0 100 sur une grille en utilisant la r\u00E8gle Suivante : \r\n\t\tLes entiers cons\u00E9cutifs doivent \u00EAtres espac\u00E9s de : \r\n\t\t\t-2 cases horizontalement et verticalement \r\n OU\r\n\t\t\t-1 case en diagonale");
lblNewLabel_1 = new Label(shell, SWT.NONE);
lblNewLabel_1.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
lblNewLabel_1.setFont(SWTResourceManager.getFont("Segoe UI", 11, SWT.BOLD));
lblNewLabel_1.setBounds(269, 580, 92, 29);
lblNewLabel_1.setText("Jeu du 100 :\r\n");
recommencer.addSelectionListener(new SelectionAdapter() { //lors du clic de recommencer
@Override
public void widgetSelected(SelectionEvent e) {
recommencer.setVisible(false);
victoire.setVisible(false);
for ( int i=1;i<=10;i++) {
for ( int j=1;j<=10;j++) {
bouton[i][j].setText("");
bouton[i][j].setEnabled(true);
bouton[i][j].setBackground(SWTResourceManager.getColor(250, 250, 250));
numeroplace=1;
undo.setVisible(false);
xxl=50;
yyl=50;
}
}
}
});
for ( int x=1;x<=10;x++) {
for ( int y=1;y<=10;y++) {
final int xx=x;
final int yy=y;
bouton[x][y]= new Button(shell, SWT.NONE);
bouton[x][y].setBounds(10+50*x, 10+50*y, 50, 50);
bouton[x][y].setText("");
bouton[x][y].addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Color couleur=new Color(display, 255,0,0);
bouton[xx][yy].setForeground(couleur);
if (autorise(xx,yy)) {
if(numeroplace>=1){
undo.setVisible(true);
}
bouton[xx][yy].setText(""+numeroplace);
inutilisable(xx,yy);
numeroplace++;
gagne();
deja[numeroplace][0]=xx;
deja[numeroplace][1]=yy;
xxl=xx; //on recupère les position du dernier bouton
yyl=yy; //en xxl et yyl
System.out.println("Num: "+numeroplace);
}
}
});
}
}
}
}
Voila !

et voila mon exécutable personnalisé avec couleurs et tout le reste
(le code n'est pas le même pour mon exécutable car il y a des ajouts de couleurs et labels )
http://www.mediafire.com/download/xwp77 ... u100v2.jarD'ailleurs, quelle est l'astuce pour gagner?

Car je n'ai jamais reussi
