⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urrobot.java

📁 是有关解释器的.用JAVA编写.可以解释一般的JAVA程序.
💻 JAVA
字号:
/**
 * The ur_Robot is the origin of all robots. It handles the communication with the World the robot
 * is in. It also defines the base functionality of a robot. That is some query methods like avenue()
 * or areYouHere() and commands like turnLeft(). The commands take some time to be fulfilled (depending
 * p.e. on the delay of the World). The query functions, though, return immediately.
 */
public class UrRobot implements KarelJConstants
{
	Integer robotId;
	
	/**
	 * The class UrRobot contains only one constructor. It expects parameters where to place the robot,
	 * wihch direction it shows in and how many beepers it has.
	 * @param street The parameter street gives the street where the robot should be placed.
	 * @param avenue The parameter avenue gives the avenue where the robot should be placed.
	 * @param direction The parameter direction gives the direction which the robot looks in.
	 * @param beepers The parameter beepers gives the numbers of beepers the robot carries.
	 */
	/**/public UrRobot( int street, int avenue, int beepers, direction dir )
	{
		robotId = World.getWorld().getNewRobot( street, avenue, beepers, dir );
	}
	
	/**
	 * Shows if a robot can be found at a particular point.
	 * @param street Street ist the street of this point.
	 * @param avenue Avenue ist the avenue of this point.
	 * @return Returns true if the robot can be fount at this point
	 *  and false if it can not be found at this point.
	 */
	/**/public boolean areYouHere( int street, int avenue ) 
	{
		return ( World.getWorld().getAvenue( robotId ) == avenue ) && ( World.getWorld().getStreet( robotId ) == street );
	}
	
	/**
	 * @return Returns the current avenue of a robot.
	 */
	/**/public int avenue() 
	{
		return World.getWorld().getAvenue( robotId );
	}
	
	/**
	 * @return Returns the current street of a robot.
	 */
	/**/public int street() 
	{
		return World.getWorld().getStreet( robotId );
	}
	
	/**
	 * @return  Returns the current direction a robotlooks in.
	 */
	/**/public direction direction() 
	{
		switch(World.getWorld().getDirection( robotId )) {
			case direction.NORTH_VALUE:
				return North;
			case direction.EAST_VALUE:
				return East;
			case direction.SOUTH_VALUE:
				return South;
			case direction.WEST_VALUE:
				return West;
			default:
				throw new IllegalStateException();
		}
	}
	
	/**
	 * Moves the robot one block into the direction it looks.
	 */
	/**/public synchronized void move() 
	{
		World.getWorld().move( robotId );
	}
	
	/**
	 * The robot picks up a beeper.
	 */
	/**/public synchronized void pickBeeper()
	{
		World.getWorld().pickBeeper( robotId );
	}
	
	/**
	 * The robot puts a beeper.
	 */
	/**/public synchronized void putBeeper()
	{
		World.getWorld().putBeeper( robotId );
	}
	
	/**
	 * The robot turns left.
	 */
	/**/public synchronized void turnLeft()
	{
		World.getWorld().turnLeft( robotId );
	}
	
	/**
	 * The robot turns off.
	 */
	/**/public synchronized void turnOff()
	{
		World.getWorld().turnOff( robotId );
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -