mickeyho
12-15-2008, 07:37 PM
public class LeaderTurtle extends Turtle
{
public LeaderTurtle(World w, int xStart, int yStart)
{
super (w);
moveTo(xStart, yStart);
}
public FollowerTurtle[] makeFollowers(World w, int xStart, int yStart)
{
/* LeaderTurtle uses this method to create 5 FollowerTurtle objects. It places
them in their initial locations – in a line, each 20 pixels apart. The first follower
should be placed at xStart, yStart. You choose whether the line is horizontal
or vertical. It returns newly created array of the 5 FollowerTurtles. */
FollowerTurtle follower1 = new FollowerTurtle(w, xStart, yStart);
FollowerTurtle follower2 = new FollowerTurtle(w, xStart, yStart+20);
FollowerTurtle follower3 = new FollowerTurtle(w, xStart, yStart+40);
FollowerTurtle follower4 = new FollowerTurtle(w, xStart, yStart+60);
FollowerTurtle follower5 = new FollowerTurtle(w, xStart, yStart+80);
FollowerTurtle[] followersArray = new FollowerTurtle[]
{follower1,follower2,follower3,follower4,follower5};
System.out.println(followersArray);
return (followersArray);
}
public void followMe()
{
for ( int index=0; index<4; index++)
{
followersArray[2].follow();
}
}
}
/* loops through all FollowerTurtle objects created in makeFollowers(), telling
them to “follow()”. Note that if this method is called before makeFollowers,
then this method should do nothing since the FollowerTurtle objects have yet
to be created.*/
public class FollowerTurtle extends Turtle
{
public FollowerTurtle(World w, int xStart, int yStart)
{
super(w);
moveTo(xStart, yStart);
}
public void follow()
{
//int x=LeaderTurtle.getXPos();
//int y=LeaderTurtle.getYPos();
//double leaderHeading = LeaderTurtle.getHeading();
//this.setHeading(leaderHeading);
/* This method moves the FollowerTurtle to mimic the difference between the
leader?s current position and its last known position. That is, if the leader
moves five to the right, and two up, then the FollowerTurtle should do the
same. Also, this method should turn the FollowerTurtle so it is facing the
same direction as the leader. */
//while(name.turnLeft()==true)
}
}
These are my two classes. for some reason method followMe() isn't recognizing followersArray. Am I not returning correctly? Also is there a way which I can get the Turtle Leader's position and such?
Thanks.
{
public LeaderTurtle(World w, int xStart, int yStart)
{
super (w);
moveTo(xStart, yStart);
}
public FollowerTurtle[] makeFollowers(World w, int xStart, int yStart)
{
/* LeaderTurtle uses this method to create 5 FollowerTurtle objects. It places
them in their initial locations – in a line, each 20 pixels apart. The first follower
should be placed at xStart, yStart. You choose whether the line is horizontal
or vertical. It returns newly created array of the 5 FollowerTurtles. */
FollowerTurtle follower1 = new FollowerTurtle(w, xStart, yStart);
FollowerTurtle follower2 = new FollowerTurtle(w, xStart, yStart+20);
FollowerTurtle follower3 = new FollowerTurtle(w, xStart, yStart+40);
FollowerTurtle follower4 = new FollowerTurtle(w, xStart, yStart+60);
FollowerTurtle follower5 = new FollowerTurtle(w, xStart, yStart+80);
FollowerTurtle[] followersArray = new FollowerTurtle[]
{follower1,follower2,follower3,follower4,follower5};
System.out.println(followersArray);
return (followersArray);
}
public void followMe()
{
for ( int index=0; index<4; index++)
{
followersArray[2].follow();
}
}
}
/* loops through all FollowerTurtle objects created in makeFollowers(), telling
them to “follow()”. Note that if this method is called before makeFollowers,
then this method should do nothing since the FollowerTurtle objects have yet
to be created.*/
public class FollowerTurtle extends Turtle
{
public FollowerTurtle(World w, int xStart, int yStart)
{
super(w);
moveTo(xStart, yStart);
}
public void follow()
{
//int x=LeaderTurtle.getXPos();
//int y=LeaderTurtle.getYPos();
//double leaderHeading = LeaderTurtle.getHeading();
//this.setHeading(leaderHeading);
/* This method moves the FollowerTurtle to mimic the difference between the
leader?s current position and its last known position. That is, if the leader
moves five to the right, and two up, then the FollowerTurtle should do the
same. Also, this method should turn the FollowerTurtle so it is facing the
same direction as the leader. */
//while(name.turnLeft()==true)
}
}
These are my two classes. for some reason method followMe() isn't recognizing followersArray. Am I not returning correctly? Also is there a way which I can get the Turtle Leader's position and such?
Thanks.