added custom message to event cells

This commit is contained in:
musilto9 2020-03-11 22:39:53 +01:00
parent cdb5180f99
commit 1054f548a2
4 changed files with 31 additions and 3 deletions

View File

@ -1,13 +1,19 @@
import java.awt.*; import java.awt.*;
public class InteractionCell extends Cell { public class InteractionCell extends Cell {
private String message;
InteractionCell(){ InteractionCell(){
super(-1,-1, WindowOfFreeMove.CELL_SIZE, Color.ORANGE); super(-1,-1, WindowOfFreeMove.CELL_SIZE, Color.ORANGE);
} }
InteractionCell(int x, int y) { InteractionCell(int x, int y, String message) {
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.ORANGE); super(x, y, WindowOfFreeMove.CELL_SIZE, Color.ORANGE);
this.message = message;
}
public void startEvent() {
System.out.println(message);
} }
@Override @Override

View File

@ -208,6 +208,27 @@ public class Map {
return moveToCells.getFirst(); return moveToCells.getFirst();
} }
InteractionCell findInteractionByXY(int x, int y, int directionSight) {
switch (directionSight) {
case 1:
x--;
break;
case 3:
x++;
break;
case 2:
y--;
break;
case 0:
y++;
break;
}
for (InteractionCell cell : eventCells)
if (x == cell.getX() && y == cell.getY())
return cell;
return eventCells.getFirst();
}
public ImageCell getImageCell() { return imageCell; } public ImageCell getImageCell() { return imageCell; }
} }

View File

@ -76,7 +76,7 @@ public class Person extends Cell {
break; break;
case WindowOfFreeMove.KEY_EVENT: case WindowOfFreeMove.KEY_EVENT:
if (isEventInFront(x,y,directionSight)) { if (isEventInFront(x,y,directionSight)) {
System.out.println("showEvent"); map.findInteractionByXY(x, y, directionSight).startEvent();
} }
break; break;
} }

View File

@ -150,7 +150,8 @@ public class WindowOfFreeMove extends JFrame {
m1.addMoveToEvent(new EventMoveToCell(1, 1, 8, 8, m2, this)); m1.addMoveToEvent(new EventMoveToCell(1, 1, 8, 8, m2, this));
m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4, this)); m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4, this));
m1.addInteractionEvent(new InteractionCell(5, 5)); m1.addInteractionEvent(new InteractionCell(3, 5, "první zpráva"));
m1.addInteractionEvent(new InteractionCell(5, 5, "druhá zpráva"));
m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3, this)); m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3, this));
m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1, this)); m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1, this));