本文整理汇总了Java中com.googlecode.lanterna.input.Key.Kind类的典型用法代码示例。如果您正苦于以下问题:Java Kind类的具体用法?Java Kind怎么用?Java Kind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Kind类属于com.googlecode.lanterna.input.Key包,在下文中一共展示了Kind类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: show
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Override
public void show() {
_terminal.clearScreen();
while (true) {
Key key = _terminal.readInput();
if (_presenter.isGameOver())
return;
if(key != null && key.getCharacter() == Space){
isStoped = !isStoped;
}
if (key != null && key.getKind() == Kind.Escape){
if(isStoped)_presenter.saveState();
return;
}
if(!isStoped)
_presenter.tick(convertToDirection(key));
Sleep();
}
}
示例2: handleInput
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
public void handleInput(Key key) {
////// The part below handles everything controlled by hotkeys and should not be changed (unless a bug is found)
if (currentInputHandler == null){
return;
}
Key.Kind keyKind = key.getKind();
if (keyKind == Key.Kind.ArrowDown || keyKind == Key.Kind.ArrowLeft || keyKind == Key.Kind.ArrowRight || keyKind == Key.Kind.ArrowUp) {
currentInputHandler.arrowPressed(keyKind);
}
else if (keyKind == Key.Kind.Enter){
currentInputHandler.enterPressed();
}
else if (keyKind == Key.Kind.Backspace || keyKind == Key.Kind.Delete || keyKind == Key.Kind.End || keyKind == Key.Kind.Home || keyKind == Key.Kind.Insert || keyKind == Key.Kind.PageUp || keyKind == Key.Kind.PageDown || keyKind == Key.Kind.Tab || keyKind == Key.Kind.Escape){
currentInputHandler.specialKeyPressed(keyKind);
}
else if (keyKind == Kind.NormalKey){
currentInputHandler.normalKeyPressed(key.getCharacter());
}
else if (keyKind == Kind.F1 || keyKind == Kind.F2 || keyKind == Kind.F3 || keyKind == Kind.F4 || keyKind == Kind.F5 || keyKind == Kind.F6 || keyKind == Kind.F7 || keyKind == Kind.F8 || keyKind == Kind.F9 || keyKind == Kind.F10 || keyKind == Kind.F11 || keyKind == Kind.F12){
currentInputHandler.FbuttonPressed(keyKind);
}
}
示例3: show
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Override
public void show() {
_terminal.clearScreen();
String[] names = { " Game Over ",
"Do you want to play again?", " Press Y to play again.",
" Press N or ESC to quit." };
TerminalSize screenSize = _terminal.getTerminalSize();
for (int i = 0; i < names.length; i++) {
_terminal.moveCursor(screenSize.getColumns() / 2 - 15,
screenSize.getRows() / 2 - 2 + i);
writeLine(String.format("%s", names[i]));
}
_terminal.flush();
while (true) {
Key p = _terminal.readInput();
if (p == null)
continue;
char ch = p.getCharacter();
if (p.getKind() == Kind.Escape || ch == 'n')
break;
if (ch == 'y') {
_continueGame = true;
break;
}
}
}
示例4: testShowWithUserAsnwerNoEscape
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Test
public void testShowWithUserAsnwerNoEscape() {
// First this boolean should be false
assertFalse(gameOver.continueGameOrNot());
// Stub key to return no
Mockito.when(key.getKind()).thenReturn(Kind.Escape);
Mockito.when(terminal.readInput()).thenReturn(key);
gameOver.show();
// Second call of this boolean should be false
assertFalse(gameOver.continueGameOrNot());
}
示例5: testNewHighScore
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Test
public void testNewHighScore() {
TerminalHighScoreView v=new TerminalHighScoreView(presenter, terminal);
when(presenter.getScore()).thenReturn(100);
//return normal key kind twice to enter a name containing two characters then retrun Kind.Enter to break
when(key.getKind()).thenReturn(Kind.NormalKey).thenReturn(Kind.NormalKey).thenReturn(Kind.Enter);
when(key.getCharacter()).thenReturn('M').thenReturn('E');
//first return null to check the continue if, then returns key
when(terminal.readInput()).thenReturn(null).thenReturn(key);
when(presenter.checkNewScore(100)).thenReturn(true);
v.show();
Mockito.verify(terminal,atLeastOnce()).putCharacter('M');
Mockito.verify(terminal,atLeastOnce()).putCharacter('E');
}
示例6: testConvertToDirectionDown
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Test
public void testConvertToDirectionDown() {
Mockito.when(presenter.isGameOver()).thenReturn(false).thenReturn(true);
Mockito.when(terminal.readInput()).thenReturn(key);
Mockito.when(key.getKind()).thenReturn(Kind.ArrowDown);
mazeView.show();
Mockito.verify(presenter).tick(DirectionKey.Down);
}
示例7: testConvertToDirectionUp
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Test
public void testConvertToDirectionUp() {
Mockito.when(presenter.isGameOver()).thenReturn(false).thenReturn(true);
Mockito.when(terminal.readInput()).thenReturn(key);
Mockito.when(key.getKind()).thenReturn(Kind.ArrowUp);
mazeView.show();
Mockito.verify(presenter).tick(DirectionKey.Up);
}
示例8: testConvertToDirectionLeft
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Test
public void testConvertToDirectionLeft() {
Mockito.when(presenter.isGameOver()).thenReturn(false).thenReturn(true);
Mockito.when(terminal.readInput()).thenReturn(key);
Mockito.when(key.getKind()).thenReturn(Kind.ArrowLeft);
mazeView.show();
Mockito.verify(presenter).tick(DirectionKey.Left);
}
示例9: testConvertToDirectionRight
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Test
public void testConvertToDirectionRight() {
Mockito.when(presenter.isGameOver()).thenReturn(false).thenReturn(true);
Mockito.when(terminal.readInput()).thenReturn(key);
Mockito.when(key.getKind()).thenReturn(Kind.ArrowRight);
mazeView.show();
Mockito.verify(presenter).tick(DirectionKey.Right);
}
示例10: testConvertToDirectionNone
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Test
public void testConvertToDirectionNone() {
Mockito.when(presenter.isGameOver()).thenReturn(false).thenReturn(true);
Mockito.when(terminal.readInput()).thenReturn(key);
Mockito.when(key.getKind()).thenReturn(Kind.Enter);
mazeView.show();
Mockito.verify(presenter).tick(DirectionKey.None);
}
示例11: testResumeAfterStop
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Test
public void testResumeAfterStop(){
Mockito.when(presenter.isGameOver()).thenReturn(false).thenReturn(false).thenReturn(true);
Mockito.when(terminal.readInput()).thenReturn(key);
Mockito.when(key.getKind()).thenReturn(Kind.ArrowDown);
Mockito.when(key.getCharacter()).thenReturn(' ');
mazeView.show();
Mockito.verify(presenter, Mockito.times(1)).tick(DirectionKey.Down);
}
示例12: testQuitStopped
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Test
public void testQuitStopped(){
Mockito.when(presenter.isGameOver()).thenReturn(false);
Mockito.when(terminal.readInput()).thenReturn(key);
//send stop character on first iteration and something different on second
Mockito.when(key.getCharacter()).thenReturn(' ').thenReturn('\0');
//send something different kind on first iteration and escape key on second
Mockito.when(key.getKind()).thenReturn(Kind.Enter).thenReturn(Kind.Escape);
mazeView.show();
//check if state is saved
Mockito.verify(presenter).saveState();
//check that loop iterated twice
Mockito.verify(terminal, Mockito.times(2)).readInput();
}
示例13: testQuitNotStopped
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Test
public void testQuitNotStopped(){
Mockito.when(presenter.isGameOver()).thenReturn(false);
Mockito.when(terminal.readInput()).thenReturn(key);
Mockito.when(key.getKind()).thenReturn(Kind.Escape);
mazeView.show();
//check that loop iterated only once
Mockito.verify(terminal, Mockito.times(1)).readInput();
}
示例14: addGeneralShortcuts
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
private void addGeneralShortcuts() {
this.addWindowListener(new WindowAdapter() {
@Override
public void onUnhandledKeyboardInteraction(Window window, Key key) {
if (key.getKind() == Kind.Escape)
close();
}
});
}
示例15: getActionForKey
import com.googlecode.lanterna.input.Key.Kind; //导入依赖的package包/类
@Override
public GameAction getActionForKey(Key k) {
if(k.getKind() == Kind.NormalKey && k.getCharacter() == ' ') {
return new GameAction(7,1);
}
else {
app.getLayers().pop();
Layer layerBelow = app.getLayers().peek();
app.getLayers().push(this);
return layerBelow.getActionForKey(k);
}
}