import java.io.*; import java.util.*; class LittleRPG{ public static void main(String args[]){ try{ Graph g = new Graph(); System.out.println(g.you.getOccupation() + " " +g.you.getName() + " " + g.you.getPose() + " " + g.you.location.getSpot() + "\n看到" + g.you.location.toString()); String command = null; Scanner sc = new Scanner(System.in); while(true){ System.out.print(">>"); command = sc.next(); if(command.equalsIgnoreCase("quit")||command.equalsIgnoreCase("exit")){ sc.close(); break; }else if(command.equalsIgnoreCase("east")){ System.out.println(g.moveEast()); }else if(command.equalsIgnoreCase("west")){ System.out.println(g.moveWest()); }else if(command.equalsIgnoreCase("south")){ System.out.println(g.moveSouth()); }else if(command.equalsIgnoreCase("north")){ System.out.println(g.moveNorth()); }else if(command.equalsIgnoreCase("sit")){ System.out.println(g.sit()); }else if(command.equalsIgnoreCase("stand")){ System.out.println(g.stand()); }else if(command.equalsIgnoreCase("check")){ System.out.println(g.check()); }else if(command.equalsIgnoreCase("lookAround")){ System.out.println(g.look()); }else if(command.equalsIgnoreCase("save")){ String filename = g.you.getName().toLowerCase()+".txt"; BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); bw.write(g.you.getName()+"\n"); bw.write(g.you.getOccupation()+"\n"); bw.write(g.you.getLocation().getId()+"\n"); bw.flush(); bw.close(); System.out.println("<<存檔成功>>"); }else if(command.equalsIgnoreCase("help")){ System.out.println("help:幫助 east:往東 west:往西 south:往南 north:往北 lookAround:四望 stand:站起 sit:坐下 save:存檔 quit/exit:離開"); }else { System.out.println("沒這個指令,請再試一次"); } } }catch(Exception e){ e.printStackTrace(); }//catch } }