Пользовательский ввод не печатается под текстом - PullRequest
0 голосов
/ 16 января 2019

Я пытаюсь получить текст, который пишет медленно, затем использую цикл do-while, но когда я запускаю код, я получаю: введите текст ниже>: когда это должно быть похоже: введите текст ниже с:> под этим, яЯ пытался изменить его с печати на печать, но ничего не получалось.Мне нужна помощь

открытый класс Quick_Time_Event_Base_Code {

public static void main(String[] args) throws InterruptedException {

    //  Creates a quick time event where if the player doesn't input the right command
    //  then you "Fail" but if you input the correct code, you break out of the loop and "Pass"
    String message = "Enter Text Below";
    char[] chars = message.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            System.out.print(chars[i]);
            Thread.sleep(100);
        }

    Scanner input = new Scanner(System.in);
        do {
        System.out.println("  >: ");
        System.out.flush();     
        String pass = input.nextLine();
        if (pass.equals("Example Input Here")) {
            break;
        }
        System.out.println(" You Failed the Quick Time Event");
        System.exit(0);
    } while (true);

1 Ответ

0 голосов
/ 16 января 2019
//[...]
char[] chars = message.toCharArray();
     for (int i = 0; i < chars.length; i++) {
         System.out.print(chars[i]);
         Thread.sleep(100);
     }
System.out.println("");


Scanner input = new Scanner(System.in);
do {
    System.out.println("  >: ");
//[...]

Попробуй вот так. Если вы закончите цикл, вы перейдете к следующей строке.

...