diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java index 23b99d6..038353f 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java @@ -23,13 +23,6 @@ public class EventMoveToCell extends Cell { 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){ super(x,y, WindowOfFreeMove.CELL_SIZE, Color.green); this.id = id; diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java index 2eda704..18f893b 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java @@ -93,7 +93,7 @@ public class Person extends Cell { } break; } - if (directionMove != 69) { + if (directionMove != WindowOfFreeMove.KEY_EVENT) { if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isInteractionCell(x, y)) { directionMoveLast = directionMove; isMoving = true; diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index ffb988b..ae6acdf 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -96,13 +96,13 @@ public class Map { person = new Person(this); } - public static Map findMapByName(String nameOfMap) { - LinkedList mapLinkedList = WindowOfFreeMove.getMapLinkedList(); + public static Map findMapByName(String nameOfMap, WindowOfFreeMove window) { + LinkedList mapLinkedList = window.getMapLinkedList(); for (Map map : mapLinkedList) { if (map.getName().equals(nameOfMap)) return map; } - return mapLinkedList.getFirst(); + return null; } public static Map loadMapFromFile(String name, WindowOfFreeMove window) { @@ -143,11 +143,11 @@ public class Map { } else if (line[x].contains("INTER")) { ImageCell imageCell = new ImageCell(); 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")) { ImageCell imageCell = new ImageCell(); 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")) { 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 { - 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); String firstLine = scanner.nextLine(); String[] size = firstLine.split(" "); @@ -168,7 +168,7 @@ public class Map { for (int x = 0; x < Integer.parseInt(size[0]); x++) { if (line[x].contains("MOVETO")) { 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++; diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index 0c7589f..4da9685 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -33,12 +33,11 @@ public class WindowOfFreeMove extends JFrame { public static final int KEY_EVENT = 69; private Canvas canvas; - private static DialogBar dialogBar; - private JLayeredPane lp; + private DialogBar dialogBar; private MapPainter map; - private Timer timer; private Timer inputTimer; - private static LinkedList mapLinkedList; + + private LinkedList mapLinkedList; public MapPainter getMap() { return map; @@ -53,10 +52,7 @@ public class WindowOfFreeMove extends JFrame { } public void setMap(Map map) { - ; - this. - map. - setMap(map); + this.map.setMap(map); } public void paintMapOnWindow() { @@ -67,18 +63,18 @@ public class WindowOfFreeMove extends JFrame { WindowOfFreeMove.nextMove = nextMove; } - public static DialogBar getDialogBar() { - return WindowOfFreeMove.dialogBar; + public DialogBar getDialogBar() { + return dialogBar; } - public static LinkedList getMapLinkedList() { + public LinkedList getMapLinkedList() { return mapLinkedList; } public WindowOfFreeMove() { isReadyToPaint = false; canPersonMove = true; - lp = getLayeredPane(); + JLayeredPane lp = getLayeredPane(); canvas = new Canvas(); 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); m1.getPerson().setImagePerson("mainpng.png", rec); m1.setName("m1"); @@ -215,16 +178,11 @@ public class WindowOfFreeMove extends JFrame { mapLinkedList.add(m4); mapLinkedList.add(m5); -// m1.getImageCell().readMapFile("m1-tileset"); -// m2.getImageCell().readMapFile("m1-tileset"); -// m3.getImageCell().readMapFile("m1-tileset"); -// m4.getImageCell().readMapFile("m1-tileset"); - - 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); + m1.linkMaps(m1, this); + m2.linkMaps(m2, this); + m3.linkMaps(m3, this); + m4.linkMaps(m4, this); + m5.linkMaps(m5, this); map = new MapPainter(mapLinkedList); @@ -234,7 +192,7 @@ public class WindowOfFreeMove extends JFrame { isReadyToPaint = true; canvas.repaint(); - timer = new Timer(10, new ActionListener() { + Timer timer = new Timer(10, new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { map.getActualMap().getPerson().move();