Use arrow for ship placement
This commit is contained in:
parent
725a7b25d9
commit
abc02f94e7
@ -10,6 +10,7 @@ public class WindowKeyboardListener implements KeyListener {
|
|||||||
private final Window window;
|
private final Window window;
|
||||||
public boolean requestInput = false;
|
public boolean requestInput = false;
|
||||||
public char keyTyped = KeyEvent.CHAR_UNDEFINED;
|
public char keyTyped = KeyEvent.CHAR_UNDEFINED;
|
||||||
|
public int keyTypedArrow = KeyEvent.VK_UNDEFINED;
|
||||||
|
|
||||||
public WindowKeyboardListener(Window window) {
|
public WindowKeyboardListener(Window window) {
|
||||||
this.window = window;
|
this.window = window;
|
||||||
@ -20,6 +21,9 @@ public class WindowKeyboardListener implements KeyListener {
|
|||||||
if(requestInput) {
|
if(requestInput) {
|
||||||
if(e.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
|
if(e.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
|
||||||
keyTyped = e.getKeyChar();
|
keyTyped = e.getKeyChar();
|
||||||
|
if(e.getKeyCode() != KeyEvent.VK_UNDEFINED)
|
||||||
|
System.out.println(e.getKeyCode());
|
||||||
|
keyTypedArrow = e.getKeyCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,25 @@
|
|||||||
package battleship.model;
|
package battleship.model;
|
||||||
|
|
||||||
import battleship.utils.Pair;
|
import battleship.utils.Pair;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.KeyListener;
|
||||||
|
|
||||||
public enum Direction {
|
public enum Direction {
|
||||||
|
|
||||||
RIGHT(new Pair<>(0, 1), "D"),
|
RIGHT(new Pair<>(0, 1), "D", KeyEvent.VK_RIGHT),
|
||||||
LEFT(new Pair<>(0,-1), "G"),
|
LEFT(new Pair<>(0,-1), "G", KeyEvent.VK_LEFT),
|
||||||
UP(new Pair<>(-1,0), "H"),
|
UP(new Pair<>(-1,0), "H", KeyEvent.VK_UP),
|
||||||
DOWN(new Pair<>(1,0), "B"),
|
DOWN(new Pair<>(1,0), "B", KeyEvent.VK_DOWN),
|
||||||
DEFAULT(new Pair<>(-1,-1), null);
|
DEFAULT(new Pair<>(-1,-1), null, KeyEvent.VK_UNDEFINED);
|
||||||
|
|
||||||
private final Pair<Integer, Integer> direction;
|
private final Pair<Integer, Integer> direction;
|
||||||
private final String keyword;
|
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.direction = ukPair;
|
||||||
this.keyword = keyword;
|
this.keyword = keyword;
|
||||||
|
this.arrow = arrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair<Integer, Integer> getDirection() {
|
public Pair<Integer, Integer> getDirection() {
|
||||||
@ -25,4 +29,8 @@ public enum Direction {
|
|||||||
public String getKeyword() {
|
public String getKeyword() {
|
||||||
return keyword;
|
return keyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getArrow() {
|
||||||
|
return arrow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user