Commit d5273894 authored by Fournier Baptiste's avatar Fournier Baptiste

started adding handling for keyboard input

parent 143d2bf7
No preview for this file type
......@@ -21,4 +21,17 @@ public class GameController {
public int getCellValue(int l, int c) {
return engine.getCellValue(l, c);
}
public void handleUp(){
engine.up();
}
public void handleDown(){
engine.down();
}
public void handleLeft(){
engine.left();
}
public void handleRight(){
engine.right();
}
}
\ No newline at end of file
......@@ -2,44 +2,54 @@ package hmi;
import javax.swing.JFrame;
import java.awt.event.KeyListener;
import java.util.Set;
import control.GameController;
import java.awt.event.KeyEvent;
import java.awt.Dimension;
public class GameWindow extends JFrame implements KeyListener {
private Set<GamePanel> gamePanel;
private GamePanel gamePanel;
private GameController gameController;
public GamePanel frame;
public GameWindow(GameController control) {
// begin-user-code
// TODO Auto-generated constructor stub
// end-user-code
gameController = control;
gamePanel = new GamePanel(gameController);
this.add(gamePanel);
this.addKeyListener(this);
Dimension preferredSize = new Dimension(1000,1000);
this.setPreferredSize(preferredSize);
this.setTitle("Graphisme avec Swing");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.pack();
}
public void keyTyped(KeyEvent e) {
// begin-user-code
// TODO Auto-generated method stub
// end-user-code
int keyCode = e.getKeyCode();
switch( keyCode ) {
case KeyEvent.VK_UP:
gameController.handleUp();
break;
case KeyEvent.VK_DOWN:
gameController.handleDown();
break;
case KeyEvent.VK_LEFT:
gameController.handleLeft();
break;
case KeyEvent.VK_RIGHT :
gameController.handleRight();
break;
}
}
public void keyPressed(KeyEvent e) {
// begin-user-code
// TODO Auto-generated method stub
// end-user-code
}
public void keyReleased(KeyEvent e) {
// begin-user-code
// TODO Auto-generated method stub
// end-user-code
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment