![]() That is ambiguous, as it could be interpreted as being in context with time or with space (locations throughout the map). Your initial statement used the phrase 'at set intervals' when referring to the random spawning of spikes throughout your map. Still, assigning it after calling 'addSpikes', when the method needs it assigned first, is kind of pointless. If that be the case, you could just remove the 'int' at the beginning of the line thereby, not declaring a local field, but using the static field declared above. Maybe you intended that this line assign a value to your static field with the same name. It creates and assigns a variable that is local to the constructor (its scope is bound to the constructor itself) then, it is ignored that is, it is not ever referred to or utilized later within the constructor. Line 14 is what I call a 'hanger' line - it has no purpose. In fact, it is never assigned a different value EVER. The static field, 'randomNumber' has an initial value of '0' and it is never assigned a different value before the 'addSpikes' method is called in the world constructor. Line 19 compares the value of 'randomNumber' with '0' and will find it never to be greater than '0'. GETWORLD GREENFOOT CODEIt is not the same 'counter' field that is declared near the top of the class.ĭanpost wrote.The code given will never add spikes into the world, as is. Again the 'counter' variable is declared within the 'for' statement and its scope is limited to the 'for' loop. I did notice the somewhat strange use of the 'for' loop using a 'counter' variable. If (x >= myWorld.getWidth() || y >= myWorld.The code given will never add spikes into the world, as is. SetLocation(getX() - moveAmount, getY()) SetLocation(getX(), getY() - moveAmount) SetLocation(getX() + moveAmount, getY()) SetLocation(getX(), getY() + moveAmount) * Move one cell forward in the current direction. Check whether there is a leaf in the same cell as we are.Īctor leaf = getOneObjectAtOffset(0, 0, Leaf.class) ("myWorld.getHeight() :" + myWorld.getHeight()) ("myWorld.getWidth() :" + myWorld.getWidth()) this allows us to get the width and height of the world Int flipACoin = (int)(randD *2) //this multiplies the random decimal by two then cuts of the decimal here is the method that you can use to set the original locationĭouble randD = Math.random() //between 0 and. A Wombat moves forward until it can't do so anymore, at Import greenfoot.* // (World, Actor, GreenfootImage, and Greenfoot) Run the code and try to learn from what's printed out. Copy and paste all of the code below into the class. My Students: create a new subclass of Actor called person. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |