Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Destroy Brick

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Destroy Brick

    Destroys a (hit) brick and updates the game status accordingly
    - update the score
    - tell the brick to destroy itself
    - remove the brick from Greenfoot
    - display the new score




    What i am doing is i am showing you guys the parts that i have done and the parts i need help with.

    what i know is the remove object code.

     public void destroyBrick()
    {
    removeObject(brick);
    }

    what i need help with is getting the brick to destroy itself upon impact with the ball


  2. #2
    Junior Member
    Join Date
    Oct 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Also need help with setting up the game status.


    Checks whether we've won or not and reports the status
    - no more bricks: "You WON!!! Score: <score>" and stop the game
    - no more lives: "You LOST!!! Score: <score>" and stop the game
    - otherwise "Score: <score> Lives: <lives>"

        public void reportGameStatus()
        {
            if (numbrick ==0)
            message.setText("You Won!!!!!!");
            Greenfoot.stop();
     
            else if (lives ==0)
            message.setText("You lose!!!!!!");
            Greenfoot.stop();
     
        }

    thats what i got

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Destroy Brick

    Try and have a variable keeping track of the number of bricks left to destroy and if that number reaches zero you know the player has won the game. Just check this every time a brick is destroyed.

    The same goes for lives, however just check it every time the player looses a life. If lives is zero, player lost.

    When it comes to removing the brick from the board I guess you have some sort of array or something representing the board of bricks. Just set the coordinate in the array of the brick that was destroyed to null to represent that there is no brick here any more.

    // Json