?? traveler.java
字號(hào):
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package marstraveler;import java.io.*; import java.util.*; /** * * @author Administrator */public class Traveler{ public Site location; //x,y坐標(biāo) public Site max;//高原右上角坐標(biāo) Traveler(int Mx,int My) { max=new Site(Mx,My); location=new Site(0,0); } public void getInfor() { System.out.println("目前探測(cè)器的位置為:"+location.x+","+location.y); } public void set(int x,int y) { location.x=x; //賦值方位 location.y=y; } public int moveSet(String path,String dir) { String a=new String(); try{ StringTokenizer t=new StringTokenizer(path," ");//"|"為分隔 while(true) { a=t.nextToken(); if(a.equals("L")) { if(dir.equals("N")) { dir="W"; continue; } if(dir.equals("E")) { dir="N"; continue; } if(dir.equals("S")) { dir="E"; continue; } if(dir.equals("W")) { dir="S"; continue; } } if(a.equals("R")) { if(dir.equals("N")) { dir="E"; continue; } if(dir.equals("E")) { dir="S"; continue; } if(dir.equals("S")) { dir="W"; continue; } if(dir.equals("W")) { dir="N"; continue; } } if(a.equals("M")) { int mid=0; if(dir.equals("N")) { if((mid=this.location.y+1)>max.y) { System.out.println("錯(cuò)誤:探測(cè)器移動(dòng)出了有效范圍!!"); return 1; } this.location.y++; } if(dir.equals("E")) { if((mid=this.location.x+1)>max.x) { System.out.println("錯(cuò)誤:探測(cè)器移動(dòng)出了有效范圍!!"); return 1; } this.location.x++; } if(dir.equals("S")) { if((mid=this.location.y-1)<0) { System.out.println("錯(cuò)誤:探測(cè)器移動(dòng)出了有效范圍!!"); return 1; } this.location.y--; } if(dir.equals("W")) { if((mid=this.location.x-1)<0) { System.out.println("錯(cuò)誤:探測(cè)器移動(dòng)出了有效范圍!!"); return 1; } this.location.x--; } } } } catch(Exception e) { return 0; } } /*try { String mid=new String(); while(true) { if(path.nextToken()=="L") { while(path.nextToken()=="M") } } } catch(Exception e) { e.printStackTrace(); }*/ public String siteInitial(String s) { int x=0; int y=0; String dir=new String(); //方向 StringTokenizer t=new StringTokenizer(s," ");//"|"為分隔 x=Integer.parseInt(t.nextToken()); y=Integer.parseInt(t.nextToken()); if(x>max.x||y>max.y||x<0||y<0) { System.out.print("初始坐標(biāo)越界!系統(tǒng)默認(rèn)"); return("error"); } else { set(x,y); //set初始位置 dir=t.nextToken(); return dir; } } /* if(time==2) { StringTokenizer t1=new StringTokenizer(s," ");//" "為分隔 moveSet(t1,dir); move=1; } } } catch(Exception e) { } } */}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -