public class Orga extends Thread{
private int aus_x;
private int aus_y;
private GuiFeld guifeld;
private PrimFeld primfeld;
private App app;
private Menue menue;
private Schachputer wcomp;
private Schachputer scomp;
private int zuganz;
public Orga() {
}
public Orga(App app) {
this.app=app;
this.primfeld=new PrimFeld();
this.menue= new Menue(this);
this.guifeld=new GuiFeld(this);
this.aus_x=-1;
this.aus_y=-1;
this.zuganz=0;
this.setComp();
}
public void setComp() {
int wc=this.menue.Player(true);
switch(wc) {
case 0:{
wcomp=null;
break;
}
case 1:{
this.wcomp=new Randomchess();
break;
}
default:wcomp=null;
}
int sc=this.menue.Player(false);
switch(sc) {
case 0:{
scomp=null;
break;
}
case 1:{
this.scomp=new Randomchess();
break;
}
default:scomp=null;
}
// if(bug) {
// System.out.println(sc);
// }
if(this.wcomp!=null && this.scomp!=null) {
this.start();
}else if(this.wcomp!=null) {
this.lasscompziehen();
}
}
public void run() {
while(this.zuganz<100) {
this.lasscompziehen();
try
{
Thread.sleep(500);
}
catch(InterruptedException ie)
{
}
}
}
private void lasscompziehen() {
int[] zug=null;
if(this.primfeld.weißamzug())zug=this.wcomp.getZug();
else zug=this.scomp.getZug();
this.aus_x=zug[0];
this.aus_y=zug[1];
this.ziehen( zug[2], zug[3] );
}
public void ziehen(int x, int y) {
this.zuganz++;
LinkedList<int[]> zuege= new LinkedList();
zuege.add(new int[] {this.aus_x,this.aus_y, x, y});
zuege.add(this.primfeld.ziehen(this.aus_x,this.aus_y, x, y));
Iterator<int[]> i= zuege.iterator();
while(i.hasNext()) {
int[] ar=i.next();
this.guifeld.setFig(ar[0], ar[1]);
this.guifeld.setFig(ar[2], ar[3]);
}
boolean amzug=this.primfeld.weißamzug();
if(this.wcomp!=null) {
this.wcomp.ziehen(this.aus_x,this.aus_y, x, y);
}
if(this.scomp!=null) {
this.scomp.ziehen(this.aus_x,this.aus_y, x, y);
}
this.guifeld.addButtons();
}
...
}
public class GuiFeld extends JPanel{
private boolean bug=false;
private JButton[][] button;
private Orga org;
public GuiFeld(Orga org) {
this.setLayout(new GridLayout(8,8));
//his.button= new SchachButton[8][8];
this.button=new JButton[8][8];
this.org=org;
for(int i =0; i<8;i++) {
for (int k=0;k<8;k++) {
this.button[i][k]=new JButton();
this.button[i][k].addActionListener(new FrameBut(i,k,this.org));
}
}
this.setFiguren();
this.addButtons();
}
public void addButtons() {
this.removeAll();
for(int i =7; i>=0;i--) {
for (int k=0;k<8;k++) {
this.add(button[i][k]);
}
}
this.repaint();
}
...
}