📄 work.java
字号:
package robot;
public class Work {
private String con;
private int q1;
private int s1;
private char direction;
public Work(String num)
{
con=num;
}
public void move(Robot r)/*行进方法*/
{ q1=r.getq1();
s1=r.gets1();
char direction=r.getdirection();
switch(direction)
{case 'N': q1=q1+1; break;
case 'S': q1=q1-1; break;
case 'E': s1=s1+1; break;
case 'W': s1=s1-1; break;
}
r.setq1(q1);
r.sets1(s1);
}
public void turn(char control,Robot r)/*转向方案*/
{
direction=r.getdirection();
switch(direction)
{case 'N': if(control=='L') direction='W';
else direction='E'; break;
case 'S': if(control=='L') direction='E';
else direction='W'; break;
case 'E': if(control=='L') direction='N';
else direction='S'; break;
case 'W': if(control=='L') direction='S';
else direction='N'; break;
}
r.setdirection(direction);
}
public void moving(String num,Robot r)/*移动方案*/
{int length=num.length();
for(int z=0;length!=0;z++,length--)
{switch(num.charAt(z))
{case 'M': move(r); break;
case 'L': turn('L',r);break;
case 'R': turn('R',r);break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -