CMPT 225 : Lab 3 Correction

You will add functionalities to the Turtle created in class. You will ... The way you communicate to the window is by sending it objects through addDrawing. Since.
44KB taille 11 téléchargements 329 vues
CMPT 225 : Lab 3 Correction Mastering the Turtle I. Outline You will add functionalities to the Turtle created in class. You will be able to speak with your turtle in order to draw plants. Bonus will be awarded for the extra functionalities given at the end; the bonus will be added to your two previous labs and assignments. II. Do you speak turtle? (10 points) 1.5 pt. We may want the turtle to be able to move without drawing. For this, add in the turtle two functions: brushUp() and brushDown(). When the turtle’s brush is up, it will not draw; when the brush is down, it draws. Do it without adding any member variable to the turtle. Hint: you may modify the content of the display function. The way you communicate to the window is by sending it objects through addDrawing. Since addDrawing accepts an Object and not just lines, you can also send it a special object with two states, meaning that the brush will be up and down. Functions that set to true or false a variable of the window are not going to work. This is because they will set the whole drawing to be displayed or not, whereas we want the brush to be up and down for some parts of the drawing. For example, you should be able to draw a line with a hole: public void brushUp(){window.addDrawing("up");} // sends a String to the window public void brushDown(){window.addDrawing("down");} When you are in the window, the function that determines things that are displayed and things that aren’t is display(). So, your modifications have to take place there. Remember that the brush may be up for some time, so you should keep a state in the window standing for whether the brush is up or down. Indeed, if L denotes a line, you may have the following flow: L L L up L L L L L down L up L The only way you can know that the 5 Ls between “up” and “down” should not be displayed is by having a variable that keeps track of it. So: // in the window. True will mean down and False will mean up. private boolean brushStatus; brushStatus = true; // in the window’s constructor. for(int i = 0; i