This site requires JavaScript, please enable it in your browser!
Greenfoot back
NIRO17
NIRO17 wrote ...

2016/8/4

grabing item

NIRO17 NIRO17

2016/8/4

#
can i make a senario robot1 carring a item and moving to location1 then robot2 come and get that item from that robot1 and quickly go to the location1.(asuume that robot2 movement speed> robot1)..
danpost danpost

2016/8/4

#
NIRO17 wrote...
can i make a senario robot1 carring a item and moving to location1 then robot2 come and get that item from that robot1 and quickly go to the location1.(asuume that robot2 movement speed> robot1)..
Yes -- and both robots can be created from the same class. Use an int field to track the speed of the robots and add a getter method to return the speed of a robot. Then use something like:
Robot robot = (Robot)getOneIntersectingObject(Robot.class);
if (robot != null && robot.hasBarrel() && speed > robot.getSpeed())
{
    robot.loseBarrel();
    gainBarrel();
}
You can refactor and create the 'gainBarrel' and 'loseBarrel' methods needed.
NIRO17 NIRO17

2016/8/4

#
i did not et it..can you please explain it..how can i do this step by step...
NIRO17 NIRO17

2016/8/4

#
how can i create both robots in same class?
NIRO17 NIRO17

2016/8/4

#
give me an exmple
danpost danpost

2016/8/4

#
NIRO17 wrote...
how can i create both robots in same class?
To create two robots with different speeds in your world:
Robot robot = new Robot(); // creating first robot
robot.setSpeed(2); // setting speed of first robot
addObject(robot, < wherever >); // add first robot into world
robot = new Robot(); // creating second robot
robot.setSpeed(3); // setting speed of second robot
addObject(robot, < elsewhere >);
In Robot class you would need the following:
// instance field
private int speed;

// methods
public void setSpeed(int howFast);
{
    speed = howFast;
}

public int getSpeed()
{
    return speed;
}
NIRO17 NIRO17

2016/8/4

#
ok..thanks so after that tell me how to implement loseBarrel(); gainBarrel(); methods... can you provide me like above example type example acoording to my senario
danpost danpost

2016/8/4

#
NIRO17 wrote...
ok..thanks so after that tell me how to implement loseBarrel(); gainBarrel(); methods... can you provide me like above example type example acoording to my senario
What field did you add to track whether a robot is carrying a barrel or not? Show field declaration line (instance field line) that you will be using for this.
NIRO17 NIRO17

2016/8/5

#
can i combine MADKIT or JADE with greefoot and work together?
You need to login to post a reply.