added endEvent method

This commit is contained in:
musilto9 2020-03-12 09:42:35 +01:00
parent 23c12ab711
commit 1c292ce0fd
4 changed files with 23 additions and 3 deletions

View File

@ -56,5 +56,10 @@ public class Dialog {
timer.start();
}
public void hideText() {
dialogBar.setVisible(false);
dialogBar.repaint();
}
}

View File

@ -19,10 +19,18 @@ public class InteractionCell extends Cell {
}
public void startEvent() {
WindowOfFreeMove.setCanPersonMove(false);
if (message != null)
System.out.println(message);
if (dialog != null)
if (dialog != null) {
dialog.showText();
}
}
public void endEvent() {
if (dialog != null)
dialog.hideText();
WindowOfFreeMove.setCanPersonMove(true);
}
@Override

View File

@ -8,6 +8,7 @@ public class Person extends Cell {
private int directionSight;
private int directionMoveLast;
private boolean isMoving;
private boolean isInEvent;
private int size;
public void setDirectionMoveLast(int directionMoveLast) {
@ -24,6 +25,7 @@ public class Person extends Cell {
this.map = map;
this.directionSight = 3;
this.isMoving = false;
this.isInEvent = false;
this.size = WindowOfFreeMove.CELL_SIZE;
}
@ -75,9 +77,14 @@ public class Person extends Cell {
y = 0;
break;
case WindowOfFreeMove.KEY_EVENT:
if (isEventInFront(x,y,directionSight)) {
if (isEventInFront(x,y,directionSight) && !isInEvent) {
isInEvent = true;
map.findInteractionByXY(x, y, directionSight).startEvent();
}
else if (isEventInFront(x,y,directionSight) && isInEvent) {
map.findInteractionByXY(x, y, directionSight).endEvent();
isInEvent = false;
}
break;
}
if (directionMove != 69) {

View File

@ -85,7 +85,7 @@ public class WindowOfFreeMove extends JFrame {
addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (!map.getPerson().getIsMoving() && canPersonMove) {
if (!map.getPerson().getIsMoving() && canPersonMove || nextMove == KEY_EVENT) {
map.getPerson().setDirectionMove(nextMove);
}
}