From 2e028db9f019f48a16ab1042bf930a25c27f2860 Mon Sep 17 00:00:00 2001 From: iryupnik Date: Sun, 15 Mar 2020 11:15:53 +0100 Subject: [PATCH] Clear up --- .../game/gameOfProd/Cells/TriggerCell.java | 8 +++-- .../game/gameOfProd/Image/ImageCell.java | 10 +++---- .../java/ruscz/game/gameOfProd/Map/Map.java | 30 +++++++++---------- .../ruscz/game/gameOfProd/Map/MapPainter.java | 16 ++++------ .../gameOfProd/Windows/WindowOfFreeMove.java | 24 ++++++++++----- src/main/resources/maps/m5-tileset.txt | 2 +- 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java index c23339b..be30abd 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java @@ -27,7 +27,11 @@ public class TriggerCell extends InteractionCell { getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); } - public boolean getActive() { return isActive; } + public boolean getActive() { + return isActive; + } - public void setActive(boolean isActive) { this.isActive = isActive; } + public void setActive(boolean isActive) { + this.isActive = isActive; + } } diff --git a/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java b/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java index f418e03..a28037f 100644 --- a/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java @@ -14,7 +14,6 @@ import java.util.Scanner; public class ImageCell { private static BufferedImage image; private static LinkedList imagesOfTiles; - private Scanner scanner; private int[] mapBackground; public void readMapFile(String name) { @@ -22,14 +21,13 @@ public class ImageCell { mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH * WindowOfFreeMove.CANVAS_HEIGHT]; int count = 0; File mapFile = new File("src/main/resources/maps/" + name + ".txt"); - scanner = new Scanner(mapFile); + Scanner scanner = new Scanner(mapFile); while (scanner.hasNextLine()) { String data = scanner.nextLine(); if (data.contains("")) { String[] mapInfo = data.split(" "); ImageTileset(mapInfo); - } - else { + } else { String[] mapColumn = data.split(" "); for (int i = 0; i < mapColumn.length; i++) { mapBackground[count] = Integer.parseInt(mapColumn[i]); @@ -63,8 +61,8 @@ public class ImageCell { Rectangle[] rectangles = new Rectangle[tiles]; int count = 0; - for (int i = 0; i < rectangles.length/Ytiles; i++){ - for (int j = 0; j < rectangles.length/Xtiles; j++) { + for (int i = 0; i < rectangles.length / Ytiles; i++) { + for (int j = 0; j < rectangles.length / Xtiles; j++) { rectangles[count] = new Rectangle(tileSize * i, tileSize * j, tileSize, tileSize); count++; } diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index ffde37e..ffb988b 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -23,8 +23,8 @@ public class Map { private boolean isBlocked; private int idExit; private ImageCell imageCell; + private static Scanner scanner; - private static LinkedList listOfMoveToCells; public Map(int height, int width) { name = "Spawn"; @@ -115,9 +115,9 @@ public class Map { Map map = new Map(mapArray); map.setName(name); map.getImageCell().readMapFile(name + "-tileset"); - listOfMoveToCells = new LinkedList<>(); + LinkedList listOfMoveToCells = new LinkedList<>(); int y = 0; - while(scanner.hasNextLine()) { + while (scanner.hasNextLine()) { loadMap(map, size, y, window); y++; } @@ -133,26 +133,22 @@ public class Map { String[] line = data.split(" "); for (int x = 0; x < Integer.parseInt(size[0]); x++) { TypeOfCell cellType = null; - if (line[x].equals("BLOCK")){ + if (line[x].equals("BLOCK")) { cellType = TypeOfCell.BLOCK; map.getMapArray()[x][y] = cellType; map.getBlocks().add(new Block(x, y, map.getImageCell())); - } - else if (line[x].equals("EMPTY")) { + } else if (line[x].equals("EMPTY")) { cellType = TypeOfCell.EMPTY; map.getMapArray()[x][y] = cellType; - } - else if (line[x].contains("INTER")) { + } 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())); - } - else if (line[x].contains("TRIGGER")) { + } 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())); - } - else if (line[x].equals("SPAWN")) { + } else if (line[x].equals("SPAWN")) { map.setSpawnPoint(x, y); } } @@ -166,7 +162,7 @@ public class Map { String firstLine = scanner.nextLine(); String[] size = firstLine.split(" "); int y = 0; - while(scanner.hasNextLine()) { + while (scanner.hasNextLine()) { String data = scanner.nextLine(); String[] line = data.split(" "); for (int x = 0; x < Integer.parseInt(size[0]); x++) { @@ -234,9 +230,13 @@ public class Map { mapArray[x][y] = TypeOfCell.SPAWNPOINT; } - public ImageCell getImageCell() { return imageCell; } + public ImageCell getImageCell() { + return imageCell; + } - public TypeOfCell[][] getMapArray() { return mapArray; } + public TypeOfCell[][] getMapArray() { + return mapArray; + } public boolean isBusyCell(int x, int y) { diff --git a/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java b/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java index 31a75c5..ecb5e8e 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java @@ -11,21 +11,20 @@ public class MapPainter { private LinkedList maps; private Map actualMap; - public MapPainter (LinkedList maps){ + public MapPainter(LinkedList maps) { this.maps = maps; } - public void setMap(Map map){ - if (maps.contains(map)){ + public void setMap(Map map) { + if (maps.contains(map)) { actualMap = map; - } - else { + } else { maps.add(map); actualMap = map; } } - public Map getActualMap(){ + public Map getActualMap() { return actualMap; } @@ -33,7 +32,7 @@ public class MapPainter { public void createMap() { for (int i = 0; i < actualMap.getMapArray().length; i++) { for (int j = 0; j < actualMap.getMapArray().length; j++) { - if (actualMap.getMapArray()[i][j] == TypeOfCell.BLOCK && !actualMap.isBusyCell(i,j)) { + if (actualMap.getMapArray()[i][j] == TypeOfCell.BLOCK && !actualMap.isBusyCell(i, j)) { actualMap.getBlocks().add(new Block(i, j, actualMap.getImageCell())); } @@ -84,7 +83,4 @@ public class MapPainter { } } } - - - } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index 8fa9eb9..0c7589f 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -1,4 +1,5 @@ package ruscz.game.gameOfProd.Windows; + import ruscz.game.gameOfProd.Cells.Cell; import ruscz.game.gameOfProd.Cells.EventMoveToCell; import ruscz.game.gameOfProd.Cells.InteractionCell; @@ -43,7 +44,7 @@ public class WindowOfFreeMove extends JFrame { return map; } - public void repaintCanvas(){ + public void repaintCanvas() { canvas.repaint(); } @@ -52,7 +53,8 @@ public class WindowOfFreeMove extends JFrame { } public void setMap(Map map) { -; this. + ; + this. map. setMap(map); } @@ -61,11 +63,17 @@ public class WindowOfFreeMove extends JFrame { this.map.createMap(); } - public static void setNextMove(int nextMove) { WindowOfFreeMove.nextMove = nextMove; } + public static void setNextMove(int nextMove) { + WindowOfFreeMove.nextMove = nextMove; + } - public static DialogBar getDialogBar() { return WindowOfFreeMove.dialogBar; } + public static DialogBar getDialogBar() { + return WindowOfFreeMove.dialogBar; + } - public static LinkedList getMapLinkedList() { return mapLinkedList; } + public static LinkedList getMapLinkedList() { + return mapLinkedList; + } public WindowOfFreeMove() { isReadyToPaint = false; @@ -140,8 +148,8 @@ public class WindowOfFreeMove extends JFrame { public void start() { Rectangle[] rec = new Rectangle[12]; int count = 0; - for (int i = 0; i < rec.length/4; i++){ - for (int j = 0; j