I have four objects (already instantiated) triangle, square, circle and a last picture, responsible for invoking both methods of each class of the respective objects, in order to draw a house, a sun, a chimney, a window and a roof, and place them in an orderly fashion to give life to the image.
Before you forget to mention, for teaching purposes, my teacher is using blueJ
- according to him the tool provides better understanding in the IOO. So far everything is working perfectly.
While we are beginning to object orientation, we have gone through disciplines of primitive languages, so may deduce that I still know little about the subject.
My difficulties consist of:
I need to call a method " turnOnFireplace
" as the name already says to light the chimney, causing smoke to escape from the chimney in the animation;
Create another "turnOffFireplace" method to extinguish the chimney, causing it to stop smoking.
What I did:
I thought of creating a boolean variable to represent the state of the chimney (on / off), I loop do-while
to create the circle (representing the smoke), make it move as if it were coming out of the chimney, disappear and return the starting point, doing everything again until the turnOffFireplace
method is invoked to change the value of the variable from on to false by giving a " break " in the loop. is stopping the execution of the animation, however when I invoke the 'turnOffFireplace' method, by which, I would change the value of the variable on to false, and stop loop, breaking it, this does not happen ... the loop continues.
I will represent better with the following code.
public void turnOnFireplace()
{
smoke = new Circle();
on = true;
do
{
smoke.changeColor("black");
smoke.slowMoveVertical(100);
smoke.makeInvisible();
smoke.move(-100);
}while(on = true);
}
public void turnOffFireplace()
{
on = false;
}
The variable I mentioned was declared at the beginning of the class Picture
.
What happens is that the loop does not stop. I tried other variations of this logic but it did not solve. How do I resolve this?