java.util.scanner—如何在方法执行期间跟踪用户的输入扫描器java

hfwmuf9z  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(158)

我正在用java制作一个文本冒险游戏,我有一种方法,可以一个字母一个字母地打印文本,给人一种文本正在编写的感觉。
现在我试着,如果播放器在写入文本时按enter键,那么它会打印所有左边的文本。。。比如:

if(...) speed=0;     //Because if the speed is 0 prints the text normaly

我曾尝试使用一些扫描仪方法,如hasnextline()和nextline(),但这对我xd不起作用。如果有人知道怎么做,请帮助pp:d。

private static void printString(String text, int speed) {

    int counter=0;

    for(int i = 0; i < text.length(); i++) {

        char character = text.charAt(i);
        counter++;

        System.out.printf("%c", character); 

        //goes to next line if the text is too long
        if(Character.compare('\n',character)==0) counter=0;
        if(counter>=60 && text.length()-i>50 && Character.compare(' ',character)==0) {
            counter=0; System.out.println("");
        }

        coolDown(speed); //Cooldown between letters

    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题