Hi Leute,
Ich hab ein kleines Problem. Damit ihr versteht, wovon ich rede, hier erst mal der Quelltext^^
public void start(){
double x;
x = Math.random();
this.ball.setzeMittelpunkt (400, 300);
while(5 > 4){
if(this.bRechts.rh == true){
try{
this.rechts.verschiebenUm(0, -10);
Thread.sleep(80);
}
catch(Exception e){
System.out.println("error");
}
}
else if(this.bRechts.rr == true){
try{
this.rechts.verschiebenUm(0, 10);
Thread.sleep(80);
}
catch(Exception e){
System.out.println("error");
}
}
}
//Anstoß in drei mögliche Richtungen
if( x >= 0.33 && x <= 0.66) {
try{
for(int i=1; i<=10; i=i+1){
Thread.sleep(100);
this.ball.verschiebenUm(34, 0);
}
}
catch(Exception e){
System.out.println("error");
}
}
else if(x > 0.66) {
try{
for(int i=1; i<=10; i=i+1){
this.ball.verschiebenUm(34, 15);
Thread.sleep(100);
}
}
catch (Exception e){
System.out.println("error");
}
}
else {
try{
for(int i=1; i<=10; i=i+1){
this.ball.verschiebenUm(34, -15);
Thread.sleep(100);
}
}
catch (Exception e){
System.out.println("Error");
}
}
Es wird mir angezeigt, dass " if( x >= 0.33 && x <= 0.66) " nicht erfüllt werden kann, was mist ist, da x eine Zufallszahl zwischen 1 u. 0 ist. Ich glaub das Problem liegt bei der While Schleife. wenn ich sie entferne kann BlueJ problemlos compilieren. Hat jemand ne Idee??
Ich hab ein kleines Problem. Damit ihr versteht, wovon ich rede, hier erst mal der Quelltext^^
public void start(){
double x;
x = Math.random();
this.ball.setzeMittelpunkt (400, 300);
while(5 > 4){
if(this.bRechts.rh == true){
try{
this.rechts.verschiebenUm(0, -10);
Thread.sleep(80);
}
catch(Exception e){
System.out.println("error");
}
}
else if(this.bRechts.rr == true){
try{
this.rechts.verschiebenUm(0, 10);
Thread.sleep(80);
}
catch(Exception e){
System.out.println("error");
}
}
}
//Anstoß in drei mögliche Richtungen
if( x >= 0.33 && x <= 0.66) {
try{
for(int i=1; i<=10; i=i+1){
Thread.sleep(100);
this.ball.verschiebenUm(34, 0);
}
}
catch(Exception e){
System.out.println("error");
}
}
else if(x > 0.66) {
try{
for(int i=1; i<=10; i=i+1){
this.ball.verschiebenUm(34, 15);
Thread.sleep(100);
}
}
catch (Exception e){
System.out.println("error");
}
}
else {
try{
for(int i=1; i<=10; i=i+1){
this.ball.verschiebenUm(34, -15);
Thread.sleep(100);
}
}
catch (Exception e){
System.out.println("Error");
}
}
Es wird mir angezeigt, dass " if( x >= 0.33 && x <= 0.66) " nicht erfüllt werden kann, was mist ist, da x eine Zufallszahl zwischen 1 u. 0 ist. Ich glaub das Problem liegt bei der While Schleife. wenn ich sie entferne kann BlueJ problemlos compilieren. Hat jemand ne Idee??