我正在嘗試創建基於文本的冒險遊戲,並且我正在嘗試添加一項功能,只要遊戲需要您的輸入,標記,「=>」將顯示在您輸入的位置旁邊。有了這裏的代碼,無論何時我在命令提示符(Windows 7)中運行它,輸入都會顯示,而小勾號則不會。在你輸入之後,輸入後就會顯示勾號。我希望能夠像這樣在一行上標記刻度和輸入,「=> [使用輸入]」。請幫忙!爲什麼打印聲明「=>」在您輸入掃描儀後輸入
import java.io.IOException;
import java.util.Scanner;
import org.fusesource.jansi.AnsiConsole;
public class Game {
public static String BLACK = "\u001B[0;30m";
public static String RED = "\u001B[0;31m";
public static String GREEN = "\u001B[0;32m";
public static String YELLOW = "\u001B[0;33m";
public static String BLUE = "\u001B[0;34m";
public static String MAGENTA = "\u001B[0;35m";
public static String CYAN = "\u001B[0;36m";
public static String WHITE = "\u001B[0;37m";
public final static String ESC = "\033[";
public static String name;
public static String gender;
public static void main(String[] args) {
AnsiConsole.systemInstall();
check();
}
public static void start() {
Scanner a = new Scanner(System.in);
System.out.println("###############################################################################");
System.out.println("# #");
System.out.println("# " + YELLOW + "^.^" + WHITE + " " + "Adventure Time Is Yes " + YELLOW + "^.^" + WHITE + " #");
System.out.println("# #");
System.out.println("###############################################################################");
//Get Name
System.out.print("\n");
System.out.println("Hello young lad! What is thy " + RED + "name " + WHITE + "you were given at birth?");
System.out.print("=> ");
//Global Variable for Name
name = a.next();
System.out.print("\n");
System.out.println("Hello " + RED + name + WHITE + "! Are you a Male or Female?");
System.out.print("=> ");
gender = a.next();
}
public static void check() {
Scanner a = new Scanner(System.in);
System.out.println("Can you see these colors?: ");
System.out.println(RED + "Red " + GREEN + "Green " + YELLOW + "Yellow " + BLUE + "Blue " + MAGENTA + "Magenta " + CYAN + "Cyan " + WHITE + "White");
System.out.println("Y/N");
System.out.print("=> ");
String as = a.nextLine();
as.toUpperCase();
if (as == "Y") {
System.out.println(ESC + "2J");
start();
} else {
System.out.println(ESC + "2J");
start();
//Future idea is to make it so there is an exact copy of the game but without color :D
}
}
}
/*try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
System.exit(0);*/
//System.out.println(ESC + "2J"); Clear Lines On Screen
我該如何去沖洗輸出流? – uwjklwme23584729