SAE21_2022/Controller/GameController.java

45 lines
862 B
Java
Raw Normal View History

2023-04-12 00:04:10 +02:00
package Controller;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class GameController implements KeyListener {
private int x;
private int y;
public GameController(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_UP) {
y--;
} else if (keyCode == KeyEvent.VK_DOWN) {
y++;
} else if (keyCode == KeyEvent.VK_LEFT) {
x--;
} else if (keyCode == KeyEvent.VK_RIGHT) {
x++;
}
}
@Override
public void keyReleased(KeyEvent e) {
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}