diff --git a/src/main/java/Person.java b/src/main/java/Person.java index 2eba6f5..8b9d967 100644 --- a/src/main/java/Person.java +++ b/src/main/java/Person.java @@ -37,7 +37,7 @@ public class Person extends Cell { } public void setDirectionMove(int directionMove) { - if ((directionMove >= WindowOfFreeMove.KEY_LEFT) && (directionMove <= WindowOfFreeMove.KEY_DOWN)) + if ((directionMove >= WindowOfFreeMove.KEY_LEFT) && (directionMove <= WindowOfFreeMove.KEY_EVENT)) this.directionMove = directionMove; } @@ -74,31 +74,35 @@ public class Person extends Cell { if (y == WindowOfFreeMove.CANVAS_HEIGHT) y = 0; break; + case WindowOfFreeMove.KEY_EVENT: + if (isEventInFront(x,y,directionSight)) { + System.out.println("showEvent"); + } + break; } - if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isCellEvent(x, y)) { - directionMoveLast = directionMove; - isMoving = true; - } else if (directionMove != 0 && map.isBusyCell(x, y)) { - directionMoveLast = 0; - } else if (directionMove != 0 && map.isCellEvent(x, y)) { - directionMoveLast = 0; - } - if (map.isCellMoveTo(x, y)) { - set(x, y); - WindowOfFreeMove.setCanPersonMove(false); - if (!isMoving) { - map.findEventByXY(x, y).moveToMap(); + if (directionMove != 69) { + if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isCellEvent(x, y)) { + directionMoveLast = directionMove; + isMoving = true; + } else if (directionMove != 0 && map.isBusyCell(x, y)) { + directionMoveLast = 0; + } else if (directionMove != 0 && map.isCellEvent(x, y)) { + directionMoveLast = 0; } - } else { - if (!map.isBusyCell(x, y) && !map.isCellEvent(x,y)) { + if (map.isCellMoveTo(x, y)) { set(x, y); + WindowOfFreeMove.setCanPersonMove(false); + if (!isMoving) { + map.findEventByXY(x, y).moveToMap(); + } + } else { + if (!map.isBusyCell(x, y) && !map.isCellEvent(x, y)) { + set(x, y); + } } } - directionMove = 0; - if (isEventInFront(x,y,directionSight)) { - System.out.println("showEvent"); - } + directionMove = 0; } } diff --git a/src/main/java/WindowOfFreeMove.java b/src/main/java/WindowOfFreeMove.java index 1246175..de33408 100644 --- a/src/main/java/WindowOfFreeMove.java +++ b/src/main/java/WindowOfFreeMove.java @@ -18,6 +18,7 @@ public class WindowOfFreeMove extends JFrame { static final int KEY_UP = 38; static final int KEY_RIGHT = 39; static final int KEY_DOWN = 40; + static final int KEY_EVENT = 69; private Canvas canvas; private static JPanel dialogBar; @@ -74,7 +75,7 @@ public class WindowOfFreeMove extends JFrame { inputTimer = new Timer(10, new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { - if (!map.getPerson().getIsMoving() && canPersonMove) { + if (!map.getPerson().getIsMoving() && canPersonMove && nextMove != KEY_EVENT) { map.getPerson().setDirectionMove(nextMove); } }