2
votes

Okay, I have Game, Bird, and Board classes. I have pipe creation, deletion, and movement code in my Game class. I was advised to not make a Pipe class and to create a pipe object. Without the pipe code, my game runs smoothly, although no pipes appear. When I have the pipe code, the program runs but does not make a window appear. I'll show you the Game constructor and the pipe code.

public Game(int a) {

    super("Game");
    setLayout(new BorderLayout());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setResizable(false);

    this.board = new Board(this);
    add(board, BorderLayout.CENTER);

    bird = new Bird();
    bird.setArr();
    System.out.println("Bird made");

    /*setPipeHeight(a);
    setArr1();
    setArr2();
    System.out.println("Pipe made");
    */
    //It continues, but this is the section I am looking at
}

Now the pipe code

public void setPipeHeight (int h){
    System.out.println("Set height");
    height = h;
    //Set coords
    setArr1();
    setArr2();
    /*for (int i = 0; i < arrX1.length; i++){
        for (int j = 0; j < arrY1.length; j++){

        }
    }*/
}

public void setArr1(){
    System.out.println("Set arr1");
    int x = (Board.numCols - 1) - width;
    for (int i = 0; i < width + 1; i++){
        for (int j = 0; j < height + 1; j = j + height){
            int h = height;
            while (h >= 0){
                Board.grid[x][h] = 3;
            }
        }
    }
}

public void setArr2(){
    System.out.println("Set arr2");
    int tillTop = Board.numRows - (height + separation);
    for (int i = 0; i < width + 1; i++){
        for (int j = 0; j < tillTop + 1; j = j + tillTop){
            int h = height;
            while (h >= 0){
                Board.grid[x][h] = 3;
            }
        }
    }
}

public void movePipe(){
    System.out.println("Move pipe");
    x--;
    setArr1();
    setArr2();
}

When I do not comment out anything, it says it's running, but does not create a window. In the Game class, when I comment out these lines, the window appears but the bird does not move downward.

/*setPipeHeight(a);
setArr1();
setArr2();
System.out.println("Pipe made");
*/

When I comment out the rest of the pipe code, I get a functioning game minus the pipes appearing

1

1 Answers

3
votes

while (h >= 0) is an infinite loop in your case: h is not modified within the loop.