Clean up
This commit is contained in:
parent
2e028db9f0
commit
8d2416f4cf
@ -23,13 +23,6 @@ public class EventMoveToCell extends Cell {
|
|||||||
this.map = new Map(WindowOfFreeMove.CANVAS_HEIGHT, WindowOfFreeMove.CANVAS_WIDTH,false);
|
this.map = new Map(WindowOfFreeMove.CANVAS_HEIGHT, WindowOfFreeMove.CANVAS_WIDTH,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventMoveToCell(int id, int directionOut, int x, int y, String nameOfMap){
|
|
||||||
super(x,y, WindowOfFreeMove.CELL_SIZE, Color.green);
|
|
||||||
this.id = id;
|
|
||||||
this.directionOut = directionOut;
|
|
||||||
this.map = Map.findMapByName(nameOfMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventMoveToCell(int id, int directionOut, int x, int y, Map map, WindowOfFreeMove window){
|
public EventMoveToCell(int id, int directionOut, int x, int y, Map map, WindowOfFreeMove window){
|
||||||
super(x,y, WindowOfFreeMove.CELL_SIZE, Color.green);
|
super(x,y, WindowOfFreeMove.CELL_SIZE, Color.green);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|||||||
@ -93,7 +93,7 @@ public class Person extends Cell {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (directionMove != 69) {
|
if (directionMove != WindowOfFreeMove.KEY_EVENT) {
|
||||||
if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isInteractionCell(x, y)) {
|
if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isInteractionCell(x, y)) {
|
||||||
directionMoveLast = directionMove;
|
directionMoveLast = directionMove;
|
||||||
isMoving = true;
|
isMoving = true;
|
||||||
|
|||||||
@ -96,13 +96,13 @@ public class Map {
|
|||||||
person = new Person(this);
|
person = new Person(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map findMapByName(String nameOfMap) {
|
public static Map findMapByName(String nameOfMap, WindowOfFreeMove window) {
|
||||||
LinkedList<Map> mapLinkedList = WindowOfFreeMove.getMapLinkedList();
|
LinkedList<Map> mapLinkedList = window.getMapLinkedList();
|
||||||
for (Map map : mapLinkedList) {
|
for (Map map : mapLinkedList) {
|
||||||
if (map.getName().equals(nameOfMap))
|
if (map.getName().equals(nameOfMap))
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
return mapLinkedList.getFirst();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map loadMapFromFile(String name, WindowOfFreeMove window) {
|
public static Map loadMapFromFile(String name, WindowOfFreeMove window) {
|
||||||
@ -143,11 +143,11 @@ public class Map {
|
|||||||
} else if (line[x].contains("INTER")) {
|
} else if (line[x].contains("INTER")) {
|
||||||
ImageCell imageCell = new ImageCell();
|
ImageCell imageCell = new ImageCell();
|
||||||
String[] event = line[x].split(",");
|
String[] event = line[x].split(",");
|
||||||
map.addInteractionEvent(new InteractionCell(x, y, event[1], new Dialog(WindowOfFreeMove.getDialogBar()), map.getImageCell()));
|
map.addInteractionEvent(new InteractionCell(x, y, event[1], new Dialog(window.getDialogBar()), map.getImageCell()));
|
||||||
} else if (line[x].contains("TRIGGER")) {
|
} else if (line[x].contains("TRIGGER")) {
|
||||||
ImageCell imageCell = new ImageCell();
|
ImageCell imageCell = new ImageCell();
|
||||||
String[] trigger = line[x].split(",");
|
String[] trigger = line[x].split(",");
|
||||||
map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(WindowOfFreeMove.getDialogBar()), map.getImageCell()));
|
map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(window.getDialogBar()), map.getImageCell()));
|
||||||
} else if (line[x].equals("SPAWN")) {
|
} else if (line[x].equals("SPAWN")) {
|
||||||
map.setSpawnPoint(x, y);
|
map.setSpawnPoint(x, y);
|
||||||
}
|
}
|
||||||
@ -155,9 +155,9 @@ public class Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void linkMaps(Map map, String name, WindowOfFreeMove window) {
|
public void linkMaps(Map map, WindowOfFreeMove window) {
|
||||||
try {
|
try {
|
||||||
File dialogFile = new File("src/main/resources/maps/" + name + ".txt");
|
File dialogFile = new File("src/main/resources/maps/" + map.getName() + ".txt");
|
||||||
scanner = new Scanner(dialogFile);
|
scanner = new Scanner(dialogFile);
|
||||||
String firstLine = scanner.nextLine();
|
String firstLine = scanner.nextLine();
|
||||||
String[] size = firstLine.split(" ");
|
String[] size = firstLine.split(" ");
|
||||||
@ -168,7 +168,7 @@ public class Map {
|
|||||||
for (int x = 0; x < Integer.parseInt(size[0]); x++) {
|
for (int x = 0; x < Integer.parseInt(size[0]); x++) {
|
||||||
if (line[x].contains("MOVETO")) {
|
if (line[x].contains("MOVETO")) {
|
||||||
String[] moveTo = line[x].split(",");
|
String[] moveTo = line[x].split(",");
|
||||||
map.addMoveToEvent(new EventMoveToCell(Integer.parseInt(moveTo[1]), Integer.parseInt(moveTo[2]), x, y, findMapByName(moveTo[3]), window));
|
map.addMoveToEvent(new EventMoveToCell(Integer.parseInt(moveTo[1]), Integer.parseInt(moveTo[2]), x, y, findMapByName(moveTo[3], window), window));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
y++;
|
y++;
|
||||||
|
|||||||
@ -33,12 +33,11 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
public static final int KEY_EVENT = 69;
|
public static final int KEY_EVENT = 69;
|
||||||
|
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
private static DialogBar dialogBar;
|
private DialogBar dialogBar;
|
||||||
private JLayeredPane lp;
|
|
||||||
private MapPainter map;
|
private MapPainter map;
|
||||||
private Timer timer;
|
|
||||||
private Timer inputTimer;
|
private Timer inputTimer;
|
||||||
private static LinkedList<Map> mapLinkedList;
|
|
||||||
|
private LinkedList<Map> mapLinkedList;
|
||||||
|
|
||||||
public MapPainter getMap() {
|
public MapPainter getMap() {
|
||||||
return map;
|
return map;
|
||||||
@ -53,10 +52,7 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setMap(Map map) {
|
public void setMap(Map map) {
|
||||||
;
|
this.map.setMap(map);
|
||||||
this.
|
|
||||||
map.
|
|
||||||
setMap(map);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintMapOnWindow() {
|
public void paintMapOnWindow() {
|
||||||
@ -67,18 +63,18 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
WindowOfFreeMove.nextMove = nextMove;
|
WindowOfFreeMove.nextMove = nextMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DialogBar getDialogBar() {
|
public DialogBar getDialogBar() {
|
||||||
return WindowOfFreeMove.dialogBar;
|
return dialogBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LinkedList<Map> getMapLinkedList() {
|
public LinkedList<Map> getMapLinkedList() {
|
||||||
return mapLinkedList;
|
return mapLinkedList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WindowOfFreeMove() {
|
public WindowOfFreeMove() {
|
||||||
isReadyToPaint = false;
|
isReadyToPaint = false;
|
||||||
canPersonMove = true;
|
canPersonMove = true;
|
||||||
lp = getLayeredPane();
|
JLayeredPane lp = getLayeredPane();
|
||||||
|
|
||||||
canvas = new Canvas();
|
canvas = new Canvas();
|
||||||
canvas.setBackground(Color.white);
|
canvas.setBackground(Color.white);
|
||||||
@ -155,39 +151,6 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map m1 = new Map(CANVAS_HEIGHT, CANVAS_WIDTH, true);
|
|
||||||
// m1.getPerson().setImagePerson("mainpng.png", rec);
|
|
||||||
// m1.setName("1");
|
|
||||||
// m1.setSpawnPoint(1, 1);
|
|
||||||
// Map m2 = new Map(CANVAS_HEIGHT, CANVAS_WIDTH, false);
|
|
||||||
// m2.getPerson().setImagePerson("mainpng.png", rec);
|
|
||||||
// m2.setName("2");
|
|
||||||
// Map m3 = new Map(CANVAS_HEIGHT, CANVAS_WIDTH, true);
|
|
||||||
// m3.getPerson().setImagePerson("mainpng.png", rec);
|
|
||||||
// m3.setName("3");
|
|
||||||
// Map m4 = new Map(CANVAS_HEIGHT, CANVAS_WIDTH, false);
|
|
||||||
// m4.getPerson().setImagePerson("mainpng.png", rec);
|
|
||||||
// m4.setName("4");
|
|
||||||
//
|
|
||||||
// m1.addMoveToEvent(new EventMoveToCell(1, 1, 8, 8, m2, this));
|
|
||||||
// m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4, this));
|
|
||||||
// m1.addMoveToEvent(new EventMoveToCell(5, 1, 1, 8, m5, this));
|
|
||||||
// m1.addInteractionEvent(new InteractionCell(3,5,"first-dialog", new Dialog(dialogBar), m1.getImageCell()));
|
|
||||||
// m1.addInteractionEvent(new InteractionCell(5, 5, "dialog-test", new Dialog(dialogBar), m1.getImageCell()));
|
|
||||||
// m1.addInteractionEvent(new TriggerCell(4,6,"roses-are-red", new Dialog(dialogBar), m1.getImageCell()));
|
|
||||||
//
|
|
||||||
// m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3, this));
|
|
||||||
// m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1, this));
|
|
||||||
// m2.addInteractionEvent(new TriggerCell(7,2,"qa-tester", new Dialog(dialogBar), m1.getImageCell()));
|
|
||||||
//
|
|
||||||
// m3.addMoveToEvent(new EventMoveToCell(3, 1, 8, 8, m4, this));
|
|
||||||
// m3.addMoveToEvent(new EventMoveToCell(2, 3, 8, 1, m2, this));
|
|
||||||
// m3.addInteractionEvent(new TriggerCell(2,5,"boobs", new Dialog(dialogBar), m1.getImageCell()));
|
|
||||||
//
|
|
||||||
// m4.addMoveToEvent(new EventMoveToCell(4, 1, 8, 8, m1, this));
|
|
||||||
// m4.addMoveToEvent(new EventMoveToCell(3, 3, 8, 1, m3, this));
|
|
||||||
// m4.addInteractionEvent(new TriggerCell(3,3,"javascript", new Dialog(dialogBar), m1.getImageCell()));
|
|
||||||
|
|
||||||
Map m1 = Map.loadMapFromFile("m1", this);
|
Map m1 = Map.loadMapFromFile("m1", this);
|
||||||
m1.getPerson().setImagePerson("mainpng.png", rec);
|
m1.getPerson().setImagePerson("mainpng.png", rec);
|
||||||
m1.setName("m1");
|
m1.setName("m1");
|
||||||
@ -215,16 +178,11 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
mapLinkedList.add(m4);
|
mapLinkedList.add(m4);
|
||||||
mapLinkedList.add(m5);
|
mapLinkedList.add(m5);
|
||||||
|
|
||||||
// m1.getImageCell().readMapFile("m1-tileset");
|
m1.linkMaps(m1, this);
|
||||||
// m2.getImageCell().readMapFile("m1-tileset");
|
m2.linkMaps(m2, this);
|
||||||
// m3.getImageCell().readMapFile("m1-tileset");
|
m3.linkMaps(m3, this);
|
||||||
// m4.getImageCell().readMapFile("m1-tileset");
|
m4.linkMaps(m4, this);
|
||||||
|
m5.linkMaps(m5, this);
|
||||||
m1.linkMaps(m1, "m1", this);
|
|
||||||
m2.linkMaps(m2, "m2", this);
|
|
||||||
m3.linkMaps(m3, "m3", this);
|
|
||||||
m4.linkMaps(m4, "m4", this);
|
|
||||||
m5.linkMaps(m5, "m5", this);
|
|
||||||
|
|
||||||
map = new MapPainter(mapLinkedList);
|
map = new MapPainter(mapLinkedList);
|
||||||
|
|
||||||
@ -234,7 +192,7 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
isReadyToPaint = true;
|
isReadyToPaint = true;
|
||||||
canvas.repaint();
|
canvas.repaint();
|
||||||
|
|
||||||
timer = new Timer(10, new ActionListener() {
|
Timer timer = new Timer(10, new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
map.getActualMap().getPerson().move();
|
map.getActualMap().getPerson().move();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user