1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
public void choixAleatoire() {
int tempsChoisi=2;
t=new Timer(tempsChoisi, new ActionListener() {
int cpt=0;
public void actionPerformed(ActionEvent arg0) {
int a=(int)(grille.getNbLignes()*Math.random());
int b=(int)(grille.getNbColonnes()*Math.random());
final Joueur joueur=grille.grille[grille.getNbLignes()-a-1][b];
JButton bouton=joueur.bouton;
System.out.println("num="+joueur.numero);
bouton.setBackground(violetclair);
cpt++;
if(cpt < (int)grille.nbJoueurs/3) {
t.setDelay(500);
}
else if(cpt > (int)grille.nbJoueurs/3 && cpt < (int)2*grille.nbJoueurs/3) {
t.setDelay(800);
}
else if(cpt > (int)2*grille.nbJoueurs/3 && cpt < grille.nbJoueurs-4){
t.setDelay(1100);
}
else {
if(cpt==grille.nbJoueurs-4) {
t.setDelay(1250);
}
if(cpt==grille.nbJoueurs-3) {
t.setDelay(1500);
}
if(cpt==grille.nbJoueurs-2) {
t.setDelay(1750);
}
if(cpt==grille.nbJoueurs-1) {
t.setDelay(2000);
}
if(cpt==grille.nbJoueurs-0) {
t.stop();
JOptionPane.showMessageDialog(null, "Le joueur choisi est le joueur numéro "+joueur.numero);
}
}
//bouton.setBackground(bleu);
}
});
t.start();
} |
Partager