我正在用 lanterna 制作一个简单的基于 java 文本的刽子手(主要是因为 clearscreen 和控制台中的用户输入)。
我的用户输入有问题:一旦我输入输入并通过我的代码运行它,它每次都会继续使用相同的输入,我不能再插入另一个输入。
这是我的代码:
while (hidenWord.equals(word) == false) {
//start of basic visual setup
terminal.moveCursor(0,0);
cursorPlace[0] = 0;cursorPlace[1] = 0;
normalSetup(hidenWord, kansen, choose[categorie]);
terminal.moveCursor(12, cursorPlace[1] - 3);
//end of basic visual setup
while (bool == false) {
Thread.sleep(5);
Key key = terminal.readInput();
try {
if (key.getKind() == Key.Kind.NormalKey) {
guess = (key).toString().substring(key.toString().lastIndexOf(' '));
terminal.putCharacter(key.getCharacter());
}
} catch (Exception err) {
}
try {
if (key.getKind() == Key.Kind.Backspace) {
terminal.clearScreen();
terminal.moveCursor(0, 0);
cursorPlace[0] = 0;
cursorPlace[1] = 0;
normalSetup(hidenWord, kansen, choose[categorie]);
terminal.moveCursor(12, cursorPlace[1] - 3);
}
} catch (Exception err) {
}
try {
if (key.getKind() == Key.Kind.Enter && guess != null) {
bool = true;
}
} catch (Exception err) {
}
}
if(word.contains(guess)){
guesses.add(guess);
hidenWord = addHidden(guess, word);
}else{
kansen --;
miss.add(guess);
}
//end of other visual objects
}
谢谢!