Per the (below) instructions I did all this & my results were as they should be EXCEPT I am having difficulty with the "for loop" and my book kinda confuses me...well....a lot actually
but I cant figure outhow to place the 16 objects (8 faces straight across at the top & 8 "Me" images straight across at the bottom) using "for" loops with them being equally spaced horizontally using the getWidth() method. I am also confused where or how to declare the image int (based off the books guidance) since I already placed them in the World to make all the other functions work and my code doesnt address the placement of "Me"...would I do this in the World twice? or just put "addObject(new Me(), x,y); again for the "Me"...if so do I have to delete all the images I manually placed???
To begin, there are 8 frowning faces lined up in a row at the top of the world and 8 "Me" objects arranged at the bottom, also in a row. The faces began moving in random directions. At the same time the Me's also started moving, but they moved straight ahead, turning only when the user pressed one of two keys...one key made them turn left and another key made them turn right...you may use any two keys you wish to implement this feature. When a Me object crossed the path of a Face object the Face's frown changed to a smile.
In a somewhat unorthodox manner we have chosen to let the Face and Me sub-classes be Animals. The main reason for this was to expedite getting access to Actor methods and Animal methods. In real practice we would have made another class which would have replaced the Animal class with one which might be more pertinent to objects like Face and Me...maybe a Gliders class...but if we did that we would have many of the same methods in it as is in the new hypothetical Gliders class...so we are fudging the environment a little for the sake of simplicity. The same can be said for re-using the CrabWorld sub-class.
In the CrabWorld constructor you will need to place the 16 objects. To get full credit you will need to use "for" loops. To equally space these objects horizontally you can call the getWidth() method and divide it by 8...this would be your starting placement...then your loop could add that same amount to arrive at the next 7 placements.
To change frowny faces you have two possible options:
1.The Face looks for a Me object. Use the setImage method along with the canSee method. This is the easier approach.
2.The Me looks for the Face object. Inside Me's Act method you would declare an Actor object, say Friend, by calling the getOneObjectAtOffset method. Then you would use a statement like... friend.setImage("smiley2.png")...but this is the much harder concept to visualize and to pull off
I thought the code should look something like this based on the book
public void placeFace()
{
for (int i = 1; i < 8; i++)
{
int x = Greenfoot.getRandomNumber(getWidth()/8);
int y = Greenfoot.getRandomNumber (getHeight()/8);
addObject(new Face(), x, y);
}
}
