Added keyboard input support for moving players and box operations
This commit is contained in:
parent
536081b015
commit
645028bc94
50
cicaprojekt/Control.java
Normal file
50
cicaprojekt/Control.java
Normal 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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -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() {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user