当前位置: 首页>>代码示例>>Java>>正文


Java Key类代码示例

本文整理汇总了Java中com.googlecode.lanterna.input.Key的典型用法代码示例。如果您正苦于以下问题:Java Key类的具体用法?Java Key怎么用?Java Key使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Key类属于com.googlecode.lanterna.input包,在下文中一共展示了Key类的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();
	}
}
 
开发者ID:freeuni-sdp,项目名称:snake-15,代码行数:20,代码来源:TerminalMazeView.java

示例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;
	}
}
 
开发者ID:freeuni-sdp,项目名称:snake-15,代码行数:18,代码来源:TerminalMazeView.java

示例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);
	}
}
 
开发者ID:Teascade,项目名称:Solid-Kingdom,代码行数:23,代码来源:InputHandlerManager.java

示例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;
		}
	}
}
 
开发者ID:freeuni-sdp,项目名称:snake-15,代码行数:29,代码来源:TerminalGameOverView.java

示例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);
	}
}
 
开发者ID:freeuni-sdp,项目名称:snake-15,代码行数:30,代码来源:TerminalLevelView.java

示例6: setUp

import com.googlecode.lanterna.input.Key; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	key = Mockito.mock(Key.class);
	terminal = Mockito.mock(Terminal.class);
	terminalSize = Mockito.mock(TerminalSize.class);
	presenter = Mockito.mock(GameOverPresenter.class);
	gameOver = Mockito.spy(new TerminalGameOverView(presenter, terminal));

	Mockito.when(terminalSize.getRows()).thenReturn(100);
	Mockito.when(terminalSize.getColumns()).thenReturn(100);
	Mockito.when(terminal.getTerminalSize()).thenReturn(terminalSize);
}
 
开发者ID:freeuni-sdp,项目名称:snake-15,代码行数:13,代码来源:TerminalGameOverViewTest.java

示例7: setUp

import com.googlecode.lanterna.input.Key; //导入依赖的package包/类
@Before
public void setUp(){
	terminal=Mockito.mock(Terminal.class);
	presenter = Mockito.mock(HighScorePresenter.class);
	key=Mockito.mock(Key.class);
	when(terminal.getTerminalSize()).thenReturn(new TerminalSize(1000, 1000));
	when(presenter.getHighScoreInfo()).thenReturn("");
	when(terminal.readInput()).thenReturn(key);
	
}
 
开发者ID:freeuni-sdp,项目名称:snake-15,代码行数:11,代码来源:TerminalHighScoreViewTest.java

示例8: setUp

import com.googlecode.lanterna.input.Key; //导入依赖的package包/类
@Before
	public void setUp() throws Exception {

		terminal = Mockito.mock(Terminal.class);
		presenter = Mockito.mock(MazePresenter.class);
//		mazeView = Mockito.spy(new TerminalMazeView(presenter, terminal));
		mazeView = new TerminalMazeView(presenter, terminal);
		key = Mockito.mock(Key.class);
	}
 
开发者ID:freeuni-sdp,项目名称:snake-15,代码行数:10,代码来源:TerminalMazeViewTest.java

示例9: addGeneralShortcuts

import com.googlecode.lanterna.input.Key; //导入依赖的package包/类
private void addGeneralShortcuts() {
	this.addWindowListener(new WindowAdapter() {

		@Override
		public void onUnhandledKeyboardInteraction(Window window, Key key) {
			if (key.getKind() == Kind.Escape)
				close();
		}

	});
}
 
开发者ID:frincon,项目名称:openeos,代码行数:12,代码来源:UnoWindow.java

示例10: 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
	}
}
 
开发者ID:melloc,项目名称:roguelike,代码行数:15,代码来源:InventoryLayer.java

示例11: 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
    }
}
 
开发者ID:melloc,项目名称:roguelike,代码行数:38,代码来源:DemoLayer.java

示例12: 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);
	}
}
 
开发者ID:melloc,项目名称:roguelike,代码行数:13,代码来源:AnnounceLayer.java

示例13: getActionForKey

import com.googlecode.lanterna.input.Key; //导入依赖的package包/类
@Override
public GameAction getActionForKey(Key k) {
	if (k.getCharacter() >= 'a' && k.getCharacter() <= 'z') {
		int slot = k.getCharacter() - 'a';
		return new GameAction(2,slot); //Quaff potion in slot 
	}
	else {
		return new GameAction(2,-1); //Not valid key
	}
}
 
开发者ID:melloc,项目名称:roguelike,代码行数:11,代码来源:UseItemLayer.java

示例14: 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
	}
}
 
开发者ID:melloc,项目名称:roguelike,代码行数:33,代码来源:LookLayer.java

示例15: onKeyPressed

import com.googlecode.lanterna.input.Key; //导入依赖的package包/类
@Override
protected void onKeyPressed(Key k) {
	if (!layers.isEmpty()) {
		Layer active = layers.peek();
		active.propagateAction(active.getActionForKey(k));
	}
}
 
开发者ID:melloc,项目名称:roguelike,代码行数:8,代码来源:Application.java


注:本文中的com.googlecode.lanterna.input.Key类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。