/**
* Compilation : javac Traversal.java
* Execution : java Traversal args0 ----- GraphicsMode
* : java Traversal args0 args1 ----- TextMode
*
* Arguments : args0 - boardfilename.txt
* args1 - movesfilename.txt
*
* Controls : h - left movement
* l - right movement
* j - down movement
* k - up movement
**/
public static void main(String[] args) throws FileNotFoundException, InterruptedException {
if (args.length == 1) {
GameBoard board = Middleware.parseArgs(args[0]);
Middleware.validateBoard(board);
GraphicsMode.play(board);
}else if (args.length == 2) {
GameBoard board = Middleware.parseArgs(args[0]);
Middleware.validateBoard(board);
String moves = Middleware.readMoves(new Scanner(new File(args[1])));
TextMode.play(board, moves);
}
exit();
}
/**
* Sleep for 4000 microseconds to allow
* the final event sound to finish
* playing and then exits.
*/
public static void exit() throws InterruptedException {
Thread.sleep(4000);
System.exit(0);
}
正如您在JavaDoc中已经提到的,如果要将两个参数传递给程序,则需要从命令提示符(cmd窗口)运行此程序,如下所示:
java Traversal args0 args1
其中
args0 - boardfilename.txt
args1 - movesfilename.txt
换句话说,在命令提示符下以java Traversal boardfilename.txt movesfilename.txt
身份运行它。如果boardfilename.txt
和movesfilename.txt
不在Traversal.class
所在的位置,请提及其完整路径,即
java Traversal path-to-boardfilename.txt path-to-movesfilename.txt
如果您在日食中运行它,请右键单击Traversal.java>单击运行配置...>将值放入对话框,如屏幕快照所示>单击运行] >
在这种情况下(即,当您尝试从eclipse运行它时,请确保boardfilename.txt
的父文件夹中有movesfilename.txt
和src
。