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

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

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

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

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

  1. private static void printString(String text, int speed) {
  2. int counter=0;
  3. for(int i = 0; i < text.length(); i++) {
  4. char character = text.charAt(i);
  5. counter++;
  6. System.out.printf("%c", character);
  7. //goes to next line if the text is too long
  8. if(Character.compare('\n',character)==0) counter=0;
  9. if(counter>=60 && text.length()-i>50 && Character.compare(' ',character)==0) {
  10. counter=0; System.out.println("");
  11. }
  12. coolDown(speed); //Cooldown between letters
  13. }
  14. }

暂无答案!

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

相关问题