ecco ilmetodo gioca partita....
public void giocaPartita(int primo, Thread th){
try {
Thread.sleep(2000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
int incr = 1;
int i = primo;
current = scartaPrima(giocatori[i]);
if (current.getSimbolo().equals("+4CambiaColore") ||
current.getSimbolo().equals("CambiaColore")) {
JOptionPane.showMessageDialog(Tavolo.this,
"Il colore scelto da " + giocatori[i].getName() +
" è: " + current.getColore());
}
partita.addCartaScartate(current);
this.repaintTavolo(i);
boolean operazioneEseguita = false;
Thread tr=new Thread();
while (true) {
try {
int tempo=(int)(Math.random()*2000)+2000;
Thread.sleep(tempo);
}
catch (InterruptedException e) {e.printStackTrace();}
if (!operazioneEseguita && current.getSimbolo().equals("CambiaGiro")) {
incr = -incr;
operazioneEseguita = true;
}
i += incr;
if (!operazioneEseguita && current.getSimbolo().equals("Stop")) {
i += incr;
operazioneEseguita = true;
}
if (i < 0)
i = 4 + i;
if (i > 3)
i = i % 4;
primo=i;
Carta c = scarta(giocatori[i]);
if (c != null) {
current = c;
operazioneEseguita = false;
partita.addCartaScartate(current);
}
System.out.print("Carte: ");
for (int j = 0; j < giocatori.length; j++) {
System.out.print("" + giocatori[j].getNumCarte());
}
System.out.println();
this.repaintTavolo(i);
if ( (current.getSimbolo().equals("+4CambiaColore") ||
current.getSimbolo().equals("CambiaColore")) && c != null) {
JOptionPane.showMessageDialog(Tavolo.this,
"Il colore scelto da " +
giocatori[i].getName() +
" è: " + current.getColore());
}
if (partita.mazzoFinito()) partita.rigeneraMazzo();
if (giocatori[i].getNumCarte() == 1) {
AnnunciaUno an = new AnnunciaUno(giocatori[i].getName());
an.setVisible(true);
Thread t= new Thread(an);
t.start();
}
if (giocatori[i].getNumCarte() == 0) {
if (giocatori[0].getNumCarte() == 0) {
this.dispose();
//System.exit(0);
Finestra fin1 = new Finestra(giocatori[0].getName());
fin1.setVisible(true);
break;
}
else {
this.dispose();
//System.exit(0);
Finestra fin1 = new Finestra(giocatori[i].getName());
fin1.setVisible(true);
break;
}
}
}
}