/** * AutoBasicVehicle.java * * @author Zuo Yan * @version 1.0 */ package vehicle; import world.World; /** * An AutoBasicVehicle demostrates the correct usage of the update() method * to automatically update the state of this vehicle.
* An AutoBasicVehicle will automatically move left to right on the world and * return to the left side of the world once it passes the right side. */ public class AutomaticRightMovingV extends BasicVehicle { /** * Creates a automatically moving vehicle * * @param world the World this vehicle is in */ public AutomaticRightMovingV(World theWorld) { super(theWorld); } /** * Called by World when it's time to update. * Moves to the right by 1 unit. */ public void update() { if (getX() > super.theWorld.getSize().width) { moveTo(0, getY()); } else { moveBy(1, 0); } } }