Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8110959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:56:30+00:00 2026-06-06T01:56:30+00:00

I am making a BrickBreaker game, and for an unknown reason I am stuck

  • 0

I am making a BrickBreaker game, and for an unknown reason I am stuck with an annoying bug, that I am unable to track down. The game’s state so far:

BrickBreaker

Here is what I want to do: Suppose I click on the Red button circled in the image above. I want the red bricks to disappear, and the ones above red to take their position appropriately.

The code so far:

private void moveBrick(BrickHolder brickHolder) {

    Point brickHolderLocation = brickHolder.getBrickHolderLocation();

    Brick containedBrick = getBrickByXAndY(brickHolderLocation.x, brickHolderLocation.y); // getting the Brick at that location

    if (containedBrick == null) {
        // If in any case there should be no brick at that position, just go on with the Brick above
        if (brickHolderLocation.y == 0) { // Should we be at the top row, there's no need to continue
            return;
        } else {
            BrickHolder nextBrickHolder = getPanelByXAndY(brickHolderLocation.x, brickHolderLocation.y - 1);
            moveBrick(nextBrickHolder);
        }
    }

    if (brickHolderLocation.y == 0) { // Should we be at the top row, there's no need to continue
        return;
    }

    // Removing the current Contained Brick
    brickHolder.remove(containedBrick);

    // Getting the Brick I want to move, normally hosted at the above Panel
    Brick theOneToBeMoved = getBrickByXAndY(brickHolderLocation.x, brickHolderLocation.y - 1);

    if (theOneToBeMoved == null) {
        // If in any case the Panel above doesn't contain a Brick, then continue with the Panel above.
        BrickHolder nextBrickHolder = getPanelByXAndY(brickHolderLocation.x, brickHolderLocation.y - 1);
        moveBrick(nextBrickHolder);
    }

    // Getting the Panel above the current one, so that we may move the Brick hosted there,
    // To the current Panel
    BrickHolder toHoldTheNewBrick = getPanelByXAndY(brickHolderLocation.x, brickHolderLocation.y - 1);

    brickHolder.add(theOneToBeMoved); // Moving the Brick at the current Panel
    toHoldTheNewBrick.remove(theOneToBeMoved); // Removing that same brick from the Panel above
    theOneToBeMoved.setBrickLocation(brickHolderLocation); // Setting the Brick's new location.

    // Since we have gotten so far, we assume that everything worked perfectly and that it's time to continue
    // with the Panel above
    BrickHolder theNextOne = getPanelByXAndY(brickHolder.getBrickHolderLocation().x, brickHolder.getBrickHolderLocation().y - 1);

    moveBrick(theNextOne);
}

From the debugging I did, I believe the issue is here somewhere:

if (brickHolderLocation.y == 0) { // Should we be at the top row, there's no need to continue
            return;
        }

Some points of interest:

  • Brick – A class I created that Extends JButton. Nothing more. Think
    of it as a plain JButton with a BackGround
  • BrickHolder – A class I
    created to host the Bricks. This class extends JPanel. The only
    addition is a (Point) location variable, added for easier
    manipulation.

EDIT: Thank you everyone! Your comments and/or answers showed me the right path to continue!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:56:31+00:00Added an answer on June 6, 2026 at 1:56 am

    I do not have enough points to comment so this is more of a suggestion, but if you were on the top row, wouldn’t you still want to remove the brick regardless? That would be in the same area as you identified as being problematic in your debugging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making a new shooter game here in the vein of Galaga (my fav shooter
Making game of life I need to a have a grid that is 30x20
making a coin flip option within an app. Here's the part that's killing me:
Making a ship game because I am incredibly original.. With that aside, I have
Making an adobe flex ui in which data that is calculated must use proprietary
Making UML sequence diagram in VS 2010RC I've observed that there is no activation
Making websites that appear correctly in IE is a big problem. Is there any
Making a form that will accept a bunch of textual data and an image
Making a flash page that can cycle through these three images on mouseclick. For
Making an Flex App. Just wondering if anyone has created something that fits automatically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.