Réorganisation des fichiers
This commit is contained in:
43
src/GameController.java
Normal file
43
src/GameController.java
Normal file
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
}
|
||||
}
|
32
src/HGameController.java
Normal file
32
src/HGameController.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
public class HGameController implements KeyListener {
|
||||
private Player player;
|
||||
|
||||
public HGameController(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
int keyCode = e.getKeyCode();
|
||||
if (keyCode == KeyEvent.VK_UP) {
|
||||
player.move(-1, 0);
|
||||
} else if (keyCode == KeyEvent.VK_DOWN) {
|
||||
player.move(1, 0);
|
||||
} else if (keyCode == KeyEvent.VK_LEFT) {
|
||||
player.move(0, -1);
|
||||
} else if (keyCode == KeyEvent.VK_RIGHT) {
|
||||
player.move(0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
}
|
22
src/Player.java
Normal file
22
src/Player.java
Normal file
@@ -0,0 +1,22 @@
|
||||
public class Player {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public Player(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void move(int dx, int dy) {
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
}
|
15
src/RandomDirection.java
Normal file
15
src/RandomDirection.java
Normal file
@@ -0,0 +1,15 @@
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomDirection {
|
||||
public static final int UP = 0;
|
||||
public static final int DOWN = 1;
|
||||
public static final int LEFT = 2;
|
||||
public static final int RIGHT = 3;
|
||||
|
||||
public static int getRandomDirection() {
|
||||
Random rand = new Random();
|
||||
int direction = rand.nextInt(4);
|
||||
|
||||
return direction;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user