本文整理汇总了Java中com.googlecode.lanterna.input.Key.getKind方法的典型用法代码示例。如果您正苦于以下问题:Java Key.getKind方法的具体用法?Java Key.getKind怎么用?Java Key.getKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.lanterna.input.Key
的用法示例。
在下文中一共展示了Key.getKind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: show
import com.googlecode.lanterna.input.Key; //导入方法依赖的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: convertToDirection
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
private DirectionKey convertToDirection(Key key) {
if (key == null)
return DirectionKey.None;
switch (key.getKind()) {
case ArrowDown:
return DirectionKey.Down;
case ArrowUp:
return DirectionKey.Up;
case ArrowLeft:
return DirectionKey.Left;
case ArrowRight:
return DirectionKey.Right;
default:
return DirectionKey.None;
}
}
示例3: handleInput
import com.googlecode.lanterna.input.Key; //导入方法依赖的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);
}
}
示例4: show
import com.googlecode.lanterna.input.Key; //导入方法依赖的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;
}
}
}
示例5: show
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
@Override
public void show() {
_terminal.clearScreen();
String[] names = _presenter.getLevelNames();
_lvlCount = names.length;
for (int i = 0; i < names.length; i++) {
_terminal.moveCursor(6, 6 + i);
writeLine(String.format("[%1$s] - %2$s", i+1, names[i]));
}
_terminal.flush();
boolean isAccepted = false;
boolean isSelected = false;
while (!isAccepted) {
Key p = _terminal.readInput();
if (p == null) continue;
if (p.getKind() == Key.Kind.Enter && isSelected) {
isAccepted = true;
break;
}
char ch = p.getCharacter();
if (!Character.isDigit(ch)) continue;
int index = Character.getNumericValue(ch) - 1;
updateIndexTracker(index);
isSelected = _presenter.setSelection(index);
}
}
示例6: getActionForKey
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
@Override
public GameAction getActionForKey(Key k) {
switch (k.getKind()) {
case NormalKey:
switch (k.getCharacter()) {
case ' ':
return new GameAction(2, 1); //next page
default:
return new GameAction(2, 0); // do nothing
}
default:
return new GameAction(2, 0); // do nothing
}
}
示例7: getActionForKey
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
@Override
public GameAction getActionForKey(Key k) {
switch (k.getKind()) {
case NormalKey: {
switch (k.getCharacter()) {
case 'N':
return new GameAction(1, 1); // generate new level
case 'S':
return new GameAction(1, 2); // save current level
case 'L':
return new GameAction(1, 3); // load saved level
case 'q':
return new GameAction(1, 4); // quit
case 'h':
return new GameAction(1, 5); // Move left
case 'j':
return new GameAction(1, 7); // Move down
case 'k':
return new GameAction(1, 6); // Move up
case 'l':
return new GameAction(1, 8); // Move right
default:
return new GameAction(1, 0); // do nothing
}
}
case ArrowLeft:
return new GameAction(1, 5); // Move left
case ArrowUp:
return new GameAction(1, 6); // Move up
case ArrowDown:
return new GameAction(1, 7); // Move down
case ArrowRight:
return new GameAction(1, 8); // Move right
default:
return new GameAction(1, 0); // do nothing
}
}
示例8: getActionForKey
import com.googlecode.lanterna.input.Key; //导入方法依赖的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);
}
}
示例9: getActionForKey
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
public GameAction getActionForKey(Key k) {
switch (k.getKind()) {
case NormalKey: {
switch (k.getCharacter()) {
case 'h':
return new GameAction(1, 1); // Move left
case 'j':
return new GameAction(1, 2); // Move down
case 'k':
return new GameAction(1, 3); // Move up
case 'l':
return new GameAction(1, 4); // Move right
case ' ':
return new GameAction(1, 5); // Close
default:
return new GameAction(1, 0); // do nothing
}
}
case ArrowLeft:
return new GameAction(1, 1); // Move left
case ArrowDown:
return new GameAction(1, 2); // Move down
case ArrowUp:
return new GameAction(1, 3); // Move up
case ArrowRight:
return new GameAction(1, 4); // Move right
case Escape:
return new GameAction(1,5); //Close
default:
return new GameAction(1, 0); // do nothing
}
}
示例10: getActionForKey
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
@Override
public GameAction getActionForKey(Key k) {
switch (k.getKind()) {
case NormalKey: return new GameAction(0, 1);
default: return new GameAction(0, 2);
}
}
示例11: handleGlobalKeyPressed
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
public boolean handleGlobalKeyPressed(final Window sender, final Key key)
{
if (key.getCharacter() == 'q' || key.getKind() == Kind.Escape)
{
shutdown();
return true;
}
else if (key.getCharacter() == '?')
{
helpPopup.show();
return true;
}
return false;
}
示例12: keyboardInteraction
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
@Override
public Result keyboardInteraction(Key key)
{
final Displayable selectedItem = (Displayable) getSelectedItem();
switch (key.getKind())
{
case Enter:
case ArrowRight:
selectedItem.navigate();
return Result.EVENT_HANDLED;
case ArrowLeft:
selectedItem.navigateToParent();
return Result.EVENT_HANDLED;
default:
break;
}
switch (key.getCharacter())
{
case 'l':
return super.keyboardInteraction(new Key(Kind.ArrowRight));
case 'h':
return super.keyboardInteraction(new Key(Kind.ArrowLeft));
case 'k':
return super.keyboardInteraction(new Key(Kind.ArrowUp));
case 'j':
return super.keyboardInteraction(new Key(Kind.ArrowDown));
default:
break;
}
return super.keyboardInteraction(key);
}
示例13: keyboardInteraction
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
@Override
public Result keyboardInteraction(Key key) {
try {
switch (key.getKind()) {
case Tab:
return Result.NEXT_INTERACTABLE_RIGHT;
case ArrowRight:
horizontalOffset++;
break;
case ReverseTab:
return Result.PREVIOUS_INTERACTABLE_LEFT;
case ArrowLeft:
if (horizontalOffset > 0) {
horizontalOffset--;
} else {
return Result.PREVIOUS_INTERACTABLE_LEFT;
}
break;
case ArrowDown:
if (selectedIndex < rowList.size() - 1) {
selectedIndex++;
} else {
return Result.NEXT_INTERACTABLE_DOWN;
}
break;
case ArrowUp:
if (selectedIndex > 0) {
selectedIndex--;
} else {
return Result.PREVIOUS_INTERACTABLE_UP;
}
break;
default:
return Result.EVENT_NOT_HANDLED;
}
return Result.EVENT_HANDLED;
} finally {
invalidate();
}
}
示例14: getActionForKey
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
@Override
public GameAction getActionForKey(Key k) {
switch (k.getKind()) {
case NormalKey: {
switch (k.getCharacter()) {
case 'N':
return new GameAction(1, 1); // generate new level
case 'S':
return new GameAction(1, 2); // save current level
// case 'L':
// return new GameAction(1, 3); // load saved level
case 'Q':
return new GameAction(1, 4); // quit
case 'h':
return new GameAction(1, 5); // Move left
case 'j':
return new GameAction(1, 7); // Move down
case 'k':
return new GameAction(1, 6); // Move up
case 'l':
return new GameAction(1, 8); // Move right
case 'i':
return new GameAction(1, 9); // Open Inventory
case 'q':
return new GameAction(1, 10); // QuaffPotion
case 'w':
return new GameAction(1, 11); // Wield
case 'o':
return new GameAction(1, 12); // observe
case '<':
return new GameAction(1, 13); // up stairs
case '>':
return new GameAction(1, 14); // down stairs
case 'd':
return new GameAction(1, 15); // drop
case '?':
return new GameAction(1, 16); // help
default:
return new GameAction(1, 0); // do nothing
}
}
case ArrowLeft:
return new GameAction(1, 5); // Move left
case ArrowUp:
return new GameAction(1, 6); // Move up
case ArrowDown:
return new GameAction(1, 7); // Move down
case ArrowRight:
return new GameAction(1, 8); // Move right
default:
return new GameAction(1, 0); // do nothing
}
}
示例15: prepare
import com.googlecode.lanterna.input.Key; //导入方法依赖的package包/类
public void prepare() {
ScreenWriter writer = new ScreenWriter(screen);
writer.drawString(0, offsetTop, "Please enter the initial values for the " + this.tapes.length + " tapes:");
writer.drawString(0, offsetTop + 1, "(Press enter for an empty tape)");
terminal.applyBackgroundColor(Color.WHITE);
terminal.applyForegroundColor(Color.BLACK);
this.screen.refresh();
for (int i = 0; i < tapes.length; i++) {
this.screen.putString(0, offsetTop + i + 2, String.format("Tape %d: ", i + 1), Color.WHITE, Color.BLACK);
this.screen.setCursorPosition(8, offsetTop + i + 2);
this.terminal.setCursorVisible(true);
this.screen.refresh();
Key key = null;
StringBuilder builder = new StringBuilder();
while(key == null) {
key = screen.readInput();
if(key == null)
continue;
if(key.getKind() == Kind.NormalKey) {
terminal.putCharacter(key.getCharacter());
builder.append(key.getCharacter());
}
/*
else if(key.getKind() == Kind.Backspace) {
terminal.putCharacter(key.getCharacter());
builder.delete(builder.length() - 2, 1);
}
*/
else if(key.getKind() == Kind.Enter) {
// Store value on tape
// Try to parse as integer
try {
Integer number = new Integer(builder.toString());
// Parse succeeded, treat as unary number
this.tapes[i].initializeAsUnary(number, unarySymbol);
}
catch(NumberFormatException ex) {
// Parse failed, treat a pure character input
if(builder.length() == 0) builder.append(Tape.BLANK);
this.tapes[i].initialize(builder.toString().toCharArray());
}
// Exit the while loop, go to the next tape
break;
}
key = null;
}
}
this.terminal.setCursorVisible(false);
this.screen.setCursorPosition(0, 0);
this.screen.refresh();
}