Use arrow for ship placement

This commit is contained in:
Eideen 2021-04-29 11:41:43 +02:00
parent 725a7b25d9
commit abc02f94e7
2 changed files with 18 additions and 6 deletions

View File

@ -10,6 +10,7 @@ public class WindowKeyboardListener implements KeyListener {
private final Window window;
public boolean requestInput = false;
public char keyTyped = KeyEvent.CHAR_UNDEFINED;
public int keyTypedArrow = KeyEvent.VK_UNDEFINED;
public WindowKeyboardListener(Window window) {
this.window = window;
@ -20,6 +21,9 @@ public class WindowKeyboardListener implements KeyListener {
if(requestInput) {
if(e.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
keyTyped = e.getKeyChar();
if(e.getKeyCode() != KeyEvent.VK_UNDEFINED)
System.out.println(e.getKeyCode());
keyTypedArrow = e.getKeyCode();
}
}

View File

@ -1,21 +1,25 @@
package battleship.model;
import battleship.utils.Pair;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public enum Direction {
RIGHT(new Pair<>(0, 1), "D"),
LEFT(new Pair<>(0,-1), "G"),
UP(new Pair<>(-1,0), "H"),
DOWN(new Pair<>(1,0), "B"),
DEFAULT(new Pair<>(-1,-1), null);
RIGHT(new Pair<>(0, 1), "D", KeyEvent.VK_RIGHT),
LEFT(new Pair<>(0,-1), "G", KeyEvent.VK_LEFT),
UP(new Pair<>(-1,0), "H", KeyEvent.VK_UP),
DOWN(new Pair<>(1,0), "B", KeyEvent.VK_DOWN),
DEFAULT(new Pair<>(-1,-1), null, KeyEvent.VK_UNDEFINED);
private final Pair<Integer, Integer> direction;
private final String keyword;
private final int arrow;
<K, U> Direction(Pair<Integer, Integer> ukPair, String keyword) {
<K, U> Direction(Pair<Integer, Integer> ukPair, String keyword, int arrow) {
this.direction = ukPair;
this.keyword = keyword;
this.arrow = arrow;
}
public Pair<Integer, Integer> getDirection() {
@ -25,4 +29,8 @@ public enum Direction {
public String getKeyword() {
return keyword;
}
public int getArrow() {
return arrow;
}
}