0

After twice playing the game since first click of the ball or paddle, but it stops that. Why cannot repeat the game until the bricks <0, something about the waitforclick problem I think. How to fix this?


 // keep playing until game over
    while (lives > 0 && bricks > 0)
     {    
        // PADDLE MOVEMENT

        // check for mouse event
        GEvent event = getNextEvent(MOUSE_EVENT);
         // if we heard one
        if (event != NULL)
        {

            // if the event was movement
            if (getEventType(event) == MOUSE_MOVED)
            {
                // ensure follows cursor
                double x = getX(event) - getWidth(paddle) / 2;
                int y = 500;
                setLocation(paddle, x, y);
            }
         }

        // BALL MOVEMENT

        // move ball (up and down and at angles)
        move(ball, velocity, velocityY);

        // bounce off right edge of window
        if (getX(ball) + getWidth(ball) >= getWidth(window))
        {
            velocity = -velocity;
        }

        // bounce off top edge of window
        else if (getY(ball) <= 0)
        {
            velocityY = -velocityY;
        }

        // bounce off left edge of window
        else if (getX(ball) <= 0)
        {
            velocity = -velocity;
        }

        // if ball hits bottom of window - lose life, re-position, keep track of lives 
        else if (getY(ball) + getHeight(ball) >= getHeight(window))
        {   
            lives = lives - 1;
            setLocation(ball,190,290);
            setLocation(paddle,200-18, 500);
            waitForClick();

        } 

        // ball to bounce off paddle
        GObject object = detectCollision (window, ball);

        if(object == paddle)
        {
            velocityY = -velocityY;
        }

        // if ball hits brick, brick disappears, scoreboard updated
        if (object != NULL)
        {
            // if object (brick) hit (not the paddle or scoreboard)
            if (strcmp(getType(object), "GRect") == 0 && object != paddle && object != label)
            {
                removeGWindow(window, object);
                velocityY = -velocityY;
                points = points + 1;
                updateScoreboard (window, label, points);
             }
        }   
        //linger before moving again
        pause(10);

        if (object != NULL)
       {
         if (strcmp(getType(object), "GLabel") == 0 && object != label)
         {
          // TODO(6)


         }
       } 

     }     

     // wait for click before exiting
    waitForClick();
    // game over
    closeGWindow(window);
    return 0;
}
  • What is the initial value of lives? – Cliff B Sep 1 '15 at 4:02
  • Guys, it is two to three times previously with the staff solution, so I am done with this. – user5231181 Sep 1 '15 at 4:05

You must log in to answer this question.

Browse other questions tagged .