Lab2

7
Lab2 Move around and checking conditions

description

Lab2. Move around and checking conditions. Create a city and a robot. City Riyadh = new City(); RobotSE halo = new RobotSE (Riyadh, 0,0,Direction.EAST);. Make the robot move around in specific coordination. while( halo.getStreet ()

Transcript of Lab2

Page 1: Lab2

Lab2Move around and checking conditions

Page 2: Lab2

Create a city and a robot

City Riyadh = new City();

RobotSE halo = new RobotSE(Riyadh, 0,0,Direction.EAST);

Page 3: Lab2

Make the robot move around in specific coordination.

while(halo.getStreet()<5){

while(halo.getAvenue()<5 && halo.getAvenue()>0){

halo.move();

if (halo.getAvenue()==1)

halo.turnLeft();

}

halo.turnRight();

halo.move();

}

Page 4: Lab2

Create a wall and let the robot stops when it sense it.

Wall wa = new Wall(Riyadh,0,5,Direction.WEST);

while(halo.frontIsClear()){

halo.move();

}

Page 5: Lab2

Let the robot move then stops in a certain street

while(halo.frontIsClear() && halo.getStreet()<5){

halo.move();

}

Page 6: Lab2

Create a thing then pick it up

Thing th1 = new Thing(Riyadh,5,0);

while(halo.frontIsClear()){

halo.move();

if(halo.canPickThing())

{

halo.pickThing();

break;

}

}

Page 7: Lab2

Create a lamp and turn it off when the robot reach it

Lamp la = new Lamp(Riyadh,0,0);

while(halo.getStreet()>0){

halo.move();

if (halo.canPickThing()){

la.turnOff();

}

}