Ich komme nicht weiter:
Theoretisch dürfte der PC, das auf den Schirm geblitete Bild "Fliege" nur darstellen aber nie bewegen, da die Dinge innerhalb des Whilezweiges nie "true" werden.
Tut er aber doch: Warum?!?!!?
cya
David
Theoretisch dürfte der PC, das auf den Schirm geblitete Bild "Fliege" nur darstellen aber nie bewegen, da die Dinge innerhalb des Whilezweiges nie "true" werden.
Tut er aber doch: Warum?!?!!?
cya
David
Code:
....
public void run()
{
while(true)
{
zufall2= (int)(Math.random()*10+1);
switch(zufall2)
{
case 1:
while(zufall!=1||zufall!=2||zufall!=3||zufall!=4||zufall!=5||zufall!=6||zufall!=7||zufall!=8||zufall!=9||zufall!=10)
{
posx++;
posy++;
//Fliege neu bliten:
try{
Flieg.sleep(500);
}
catch(InterruptedException e)
{
}
repaint();
}
break;
case 2:
while(zufall!=1||zufall!=2||zufall!=3||zufall!=4||zufall!=5||zufall!=6||zufall!=7||zufall!=8||zufall!=9||zufall!=10)
{
posx++;
posy--;
//Fliege neu bliten:
try{
Flieg.sleep(zeit);
}
catch(InterruptedException e)
{
}
repaint();
}
break;
case 3:
while(zufall!=1||zufall!=2||zufall!=3||zufall!=4||zufall!=5||zufall!=6||zufall!=7||zufall!=8||zufall!=9||zufall!=10)
{
posx--;
posy--;
//Fliege neu bliten:
try{
Flieg.sleep(zeit);
}
catch(InterruptedException e)
{
}
repaint();
}
break;
case 4:
while(zufall!=1||zufall!=2||zufall!=3||zufall!=4||zufall!=5||zufall!=6||zufall!=7||zufall!=8||zufall!=9||zufall!=10)
{
posx--;
posy++;
//Fliege neu bliten:
try{
Flieg.sleep(zeit);
}
catch(InterruptedException e)
{
}
repaint();
}
zufall = (int)(Math.random()*10);
break;
case 5:
while(zufall!=1||zufall!=2||zufall!=3||zufall!=4||zufall!=5||zufall!=6||zufall!=7||zufall!=8||zufall!=9||zufall!=10)
{
posx--;
//Fliege neu bliten:
try{
Flieg.sleep(zeit);
}
catch(InterruptedException e)
{
}
repaint();
}
break;
case 6:
while(zufall!=1||zufall!=2||zufall!=3||zufall!=4||zufall!=5||zufall!=6||zufall!=7||zufall!=8||zufall!=9||zufall!=10)
{
posy++;
//Fliege neu bliten:
try{
Flieg.sleep(zeit);
}
catch(InterruptedException e)
{
}
repaint();
}
break;
case 7:
while(zufall!=1||zufall!=2||zufall!=3||zufall!=4||zufall!=5||zufall!=6||zufall!=7||zufall!=8||zufall!=9||zufall!=10)
{
posy=posy+2;
//Fliege neu bliten:
try{
Flieg.sleep(zeit);
}
catch(InterruptedException e)
{
}
repaint();
}
break;
case 8:
while(zufall!=1||zufall!=2||zufall!=3||zufall!=4||zufall!=5||zufall!=6||zufall!=7||zufall!=8||zufall!=9||zufall!=10)
{
posy=posy-2;
//Fliege neu bliten:
try{
Flieg.sleep(zeit);
}
catch(InterruptedException e)
{
}
repaint();
}
break;
case 9:
while(zufall!=1||zufall!=2||zufall!=3||zufall!=4||zufall!=5||zufall!=6||zufall!=7||zufall!=8||zufall!=9||zufall!=10)
{
posx=posx+2;
//Fliege neu bliten:
try{
Flieg.sleep(zeit);
}
catch(InterruptedException e)
{
}
repaint();
}
break;
case 10:
while(zufall!=1||zufall!=2||zufall!=3||zufall!=4||zufall!=5||zufall!=6||zufall!=7||zufall!=8||zufall!=9||zufall!=10)
{
posx=posx-2;
//Fliege neu bliten:
try{
Flieg.sleep(zeit);
}
catch(InterruptedException e)
{
}
repaint();
}
break;
default: break;
}
}
}
public void paint(Graphics g)
{
Image fly = getImage(getCodeBase(),"fliege.jpg");
g.drawImage(fly,posx,posy,this);
zufall = (int)(Math.random()*10+1);
ausgabe.setText(""+zufall);
}
public void start()
{
Flieg = new Thread(this);
Flieg.start();
}
}