Added keyboard input support for moving players and box operations

This commit is contained in:
Bokros Bálint 2016-05-07 15:19:58 +02:00
parent 536081b015
commit 645028bc94
2 changed files with 69 additions and 0 deletions

50
cicaprojekt/Control.java Normal file
View File

@ -0,0 +1,50 @@
package cicaprojekt;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class Control {
private Game game;
public class KeyHandler extends KeyAdapter{
@Override
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
c = Character.toUpperCase(c);
switch(c) {
case 'W' :
game.moveONeill(Direction.NORTH);
break;
case 'A' :
game.moveONeill(Direction.WEST);
break;
case 'S' :
game.moveONeill(Direction.SOUTH);
break;
case 'D' :
game.moveONeill(Direction.EAST);
break;
case 'I' :
game.moveJaffa(Direction.NORTH);
break;
case 'J' :
game.moveJaffa(Direction.WEST);
break;
case 'K' :
game.moveJaffa(Direction.SOUTH);
break;
case 'L' :
game.moveJaffa(Direction.EAST);
break;
case 'Q' :
game.boxONeill();
break;
case 'U' :
game.boxJaffa();
break;
}
game.updateDisplay();
}
}
}

View File

@ -45,4 +45,23 @@ public class Game {
public void stopGame(GameoverCause cause) {
}
public void moveONeill(Direction direction) {
oneill.move(direction);
}
public void moveJaffa(Direction direction) {
jaffa.move(direction);
}
public void boxONeill() {
}
public void boxJaffa() {
}
public void updateDisplay() {
}
}