70 likes | 212 Views
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 ()<5){
E N D
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()<5){ while(halo.getAvenue()<5 && halo.getAvenue()>0){ halo.move(); if (halo.getAvenue()==1) halo.turnLeft(); } halo.turnRight(); halo.move(); }
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(); }
Let the robot move then stops in a certain street while(halo.frontIsClear() && halo.getStreet()<5){ halo.move(); }
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; } }
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(); } }