jeudi 4 février 2016

java bean drop game ball only going to right

The Ball only goes of to right Dependencies Std.java a marble picture and a background arena image thank you for the help I believe the issue to be in the transition from The LR method to the main game loop method i created a variable and it takes the LR method and runs it it is inside the loop that refreshes and clears the canvas as a frame every second The question maker requires more explanination so im going to fill the rest with random lorem ipsum jfkadhfkjhfljkashfjkdhsfjdhsfljkdhsafjlhdjkfhdsjkfhdjaskfhkjahfljhdkfjhdaslfjkhdfkjdhsfkjdsflh

    package cats;

public class BeanDrop {

public static void main(String[] args) throws InterruptedException {
    mainGameLoop();
    }
public static void mainGameLoop() throws InterruptedException{
    double x = .5;
    double y = .9;
    while (true){
    int choice = LR();
    arena();
    ball(x , y);
    if (choice == 1){
        // right outcome
        x = x + .1;
    }
    else if(choice == 2){
        //left outcome
        x = x -.1;
    }
    y = y - .1;
    Thread.sleep(1000);
    StdDraw.clear();
    }
}
public static void arena(){
    StdDraw.picture(.5, .5, "balldrop.jpeg");
}

private static int LR(){
    int choice = ((int) Math.random() * 2 + 1);
    return choice;
}
public static void ball(double x , double y){
    StdDraw.picture(x, y, "ball.jpeg",.05,.05);
}
}




Aucun commentaire:

Enregistrer un commentaire