To complete Challenge 22, the following code must be pasted into BlueJ™:
import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.awt.*;
public class Challenge022
{
public static void main(String[] args)
{
ActorWorld GridWorld = new ActorWorld();
Bug BUGGRN = new Bug(Color.GREEN);
Bug BUGBLU = new Bug(Color.BLUE);
Bug BUGYLW = new Bug(Color.YELLOW);
Bug BUGMAG = new Bug(Color.MAGENTA);
BUGGRN.setDirection(Location.NORTHWEST);
BUGBLU.setDirection(Location.NORTHEAST);
BUGYLW.setDirection(Location.SOUTHWEST);
BUGMAG.setDirection(Location.SOUTHEAST);
GridWorld.add(new Location(4, 4), BUGGRN);
GridWorld.add(new Location(4, 5), BUGBLU);
GridWorld.add(new Location(5, 4), BUGYLW);
GridWorld.add(new Location(5, 5), BUGMAG);
GridWorld.show();
}
}
Pasting this code into BlueJ™ will produce the same scenario as in your original blog post.
−Phoenix
Very good programming style at work here, nice job. This one statement:
ReplyDelete"ActorWorld GridWorld = new ActorWorld();"
What's happening here?
The statement “ActorWorld GridWorld = new ActorWorld();” creates a new “ActorWorld” object named “GridWorld”. Thus, when “GridWorld” is mentioned afterwords in the code, it refers to the “ActorWorld” object previously created.
ReplyDelete−Phoenix
PS: Can you comment on my response for Challenge 21? It’s been 8 days since it was posted…
Perfect, 60XPs awarded for this completion.
ReplyDelete