From d8eef8e8c1aca7a85efcb6c6227a0c4c4fd4f38c Mon Sep 17 00:00:00 2001 From: musilto9 Date: Fri, 3 Apr 2020 16:05:37 +0200 Subject: [PATCH] code clean-up --- .../ruscz/game/gameOfProd/Cells/Cell.java | 1 - .../gameOfProd/Cells/EventMoveToCell.java | 9 ++-- .../gameOfProd/Cells/InteractionCell.java | 4 -- .../java/ruscz/game/gameOfProd/Cells/Npc.java | 10 ++-- .../game/gameOfProd/Image/ImagePerson.java | 2 - .../java/ruscz/game/gameOfProd/Map/Map.java | 2 - .../Map/{MapPainter.java => MapManager.java} | 4 +- .../ruscz/game/gameOfProd/Windows/Camera.java | 20 +++---- .../gameOfProd/Windows/WindowOfFreeMove.java | 52 +++++++++---------- 9 files changed, 43 insertions(+), 61 deletions(-) rename src/main/java/ruscz/game/gameOfProd/Map/{MapPainter.java => MapManager.java} (97%) diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Cell.java b/src/main/java/ruscz/game/gameOfProd/Cells/Cell.java index 2958e80..6a5bb8d 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Cell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Cell.java @@ -32,6 +32,5 @@ public class Cell { public void paint(Graphics2D g) { g.setColor(color); -// g.fillOval(x*size, y*size, size, size); } } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java index 6bda25b..87bfb85 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/EventMoveToCell.java @@ -33,10 +33,9 @@ public class EventMoveToCell extends Cell { public int getDirectionOut() { return directionOut; } public void moveToMap() { - //window.getMap().getPerson().stopPerson(); - window.getMapPainter().getActualMap().setIdExit(id); - window.setMapPainter(this.map); - window.getMapPainter().getActualMap().setIdExit(id); + window.getMapManager().getActualMap().setIdExit(id); + window.setMapManager(this.map); + window.getMapManager().getActualMap().setIdExit(id); window.paintMapOnWindow(); window.repaintCanvas(); window.setCanPersonMove(true); @@ -45,7 +44,7 @@ public class EventMoveToCell extends Cell { @Override public void paint(Graphics2D g) { super.paint(g); - g.drawImage(window.getMapPainter().getActualMap().getImageCell().getImagesOfTiles().get(277), getX() * WindowOfFreeMove.CELL_SIZE, + g.drawImage(window.getMapManager().getActualMap().getImageCell().getImagesOfTiles().get(277), getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); g.drawString(Integer.toString(getId()), getX()* WindowOfFreeMove.CELL_SIZE, getY()* WindowOfFreeMove.CELL_SIZE); } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index 250abb9..03189fc 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -3,8 +3,6 @@ package ruscz.game.gameOfProd.Cells; import ruscz.game.gameOfProd.Dialog.Dialog; import ruscz.game.gameOfProd.Image.ImageCell; import ruscz.game.gameOfProd.Image.ImageDialog; -import ruscz.game.gameOfProd.Map.Map; -import ruscz.game.gameOfProd.Map.MapPainter; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import java.awt.*; @@ -12,8 +10,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; -import static ruscz.game.gameOfProd.Windows.WindowOfFreeMove.*; - public class InteractionCell extends Cell { private String message; private ruscz.game.gameOfProd.Dialog.Dialog dialog; diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java index b0afa4d..7455e41 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java @@ -1,7 +1,7 @@ package ruscz.game.gameOfProd.Cells; import ruscz.game.gameOfProd.Map.Map; -import ruscz.game.gameOfProd.Map.MapPainter; +import ruscz.game.gameOfProd.Map.MapManager; import ruscz.game.gameOfProd.Scripts.Direction; import ruscz.game.gameOfProd.Scripts.PathFinder; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; @@ -9,11 +9,11 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import java.awt.*; public class Npc extends Person { - private MapPainter mapPainter; + private MapManager mapManager; - public Npc(int x, int y, Map map, MapPainter mapPainter) { + public Npc(int x, int y, Map map, MapManager mapManager) { super(x, y, map); - this.mapPainter = mapPainter; + this.mapManager = mapManager; setColor(Color.cyan); } @@ -35,7 +35,7 @@ public class Npc extends Person { moveRight(); break; } - mapPainter.repaintCanvas(); + mapManager.repaintCanvas(); } } diff --git a/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java b/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java index 66ddf38..4f3fac1 100644 --- a/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java +++ b/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java @@ -14,8 +14,6 @@ public class ImagePerson { private BufferedImage[] imagesOfDirection; private int subimageWidth; private int subimageHeight; - private Dimension imgSize = new Dimension(subimageWidth, subimageHeight); - private Dimension boundary = new Dimension(WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE); public void setAllImagesOfDirection(Rectangle[] rectangles){ imagesOfDirection = new BufferedImage[12]; diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index 72eb5e9..8385817 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -5,10 +5,8 @@ import ruscz.game.gameOfProd.Dialog.Dialog; import ruscz.game.gameOfProd.Image.ImageCell; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; -import java.awt.image.BufferedImage; import java.io.File; import java.io.FileNotFoundException; -import java.lang.reflect.Type; import java.util.LinkedList; import java.util.Scanner; diff --git a/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java b/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java similarity index 97% rename from src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java rename to src/main/java/ruscz/game/gameOfProd/Map/MapManager.java index eab454a..d26c1b1 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java @@ -10,12 +10,12 @@ import java.util.LinkedList; import static ruscz.game.gameOfProd.Windows.WindowOfFreeMove.*; -public class MapPainter { +public class MapManager { private WindowOfFreeMove.Canvas canvas; private LinkedList maps; private Map actualMap; - public MapPainter(LinkedList maps, WindowOfFreeMove.Canvas canvas) { + public MapManager(LinkedList maps, WindowOfFreeMove.Canvas canvas) { this.canvas = canvas; this.maps = maps; } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java b/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java index 35cd469..487331a 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java @@ -32,10 +32,10 @@ public class Camera { } public void moveBoundCamera() { - int cameraOffsetX = (-1) * CELL_SIZE * (window.getMapPainter().getActualMap().getPerson().getX() - WINDOW_WIDTH / 2); - int cameraOffsetY = (-1) * CELL_SIZE * (window.getMapPainter().getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2); - int direction = window.getMapPainter().getActualMap().getPerson().getDirectionMoveLast(); - int size = (-1) * window.getMapPainter().getActualMap().getPerson().getSize(); + int cameraOffsetX = (-1) * CELL_SIZE * (window.getMapManager().getActualMap().getPerson().getX() - WINDOW_WIDTH / 2); + int cameraOffsetY = (-1) * CELL_SIZE * (window.getMapManager().getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2); + int direction = window.getMapManager().getActualMap().getPerson().getDirectionMoveLast(); + int size = (-1) * window.getMapManager().getActualMap().getPerson().getSize(); int Ysize = 0; int Xsize = 0; switch (direction) { @@ -52,7 +52,7 @@ public class Camera { Ysize -= size; break; } - if (!window.getMapPainter().getActualMap().getPerson().getIsMoving()) { + if (!window.getMapManager().getActualMap().getPerson().getIsMoving()) { Xsize = 0; Ysize = 0; } @@ -123,8 +123,8 @@ public class Camera { public void returnFreeCamera() { setCameraStart(); - endX = (-1) * CELL_SIZE * (window.getMapPainter().getActualMap().getPerson().getX() - WINDOW_WIDTH / 2); - endY = (-1) * CELL_SIZE * (window.getMapPainter().getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2); + endX = (-1) * CELL_SIZE * (window.getMapManager().getActualMap().getPerson().getX() - WINDOW_WIDTH / 2); + endY = (-1) * CELL_SIZE * (window.getMapManager().getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2); if (endX > 0) { endX = 0; } @@ -141,15 +141,11 @@ public class Camera { isReturning = true; } - public void stopCamera() { - - } - public void boundCamera() { isBound = true; isReturning = false; window.setCanPersonMove(true); - window.getMapPainter().getActualMap().getPerson().setInEvent(false); + window.getMapManager().getActualMap().getPerson().setInEvent(false); } public void setCameraStart() { diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index dd8882e..eda6c3d 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -3,7 +3,7 @@ package ruscz.game.gameOfProd.Windows; import ruscz.game.gameOfProd.Cells.*; import ruscz.game.gameOfProd.Dialog.DialogBar; import ruscz.game.gameOfProd.Map.Map; -import ruscz.game.gameOfProd.Map.MapPainter; +import ruscz.game.gameOfProd.Map.MapManager; import ruscz.game.gameOfProd.Sounds.MusicManager; import javax.swing.*; @@ -35,15 +35,15 @@ public class WindowOfFreeMove extends JFrame { private Canvas canvas; private DialogBar dialogBar; - private MapPainter mapPainter; + private MapManager mapManager; private Camera camera; private Timer inputTimer; private MusicManager musicManager; private LinkedList mapLinkedList; - public MapPainter getMapPainter() { - return mapPainter; + public MapManager getMapManager() { + return mapManager; } public void repaintCanvas() { @@ -58,12 +58,12 @@ public class WindowOfFreeMove extends JFrame { WindowOfFreeMove.canPersonMove = canPersonMove; } - public void setMapPainter(Map mapPainter) { - this.mapPainter.setMap(mapPainter); + public void setMapManager(Map mapManager) { + this.mapManager.setMap(mapManager); } public void paintMapOnWindow() { - this.mapPainter.createMap(); + this.mapManager.createMap(); } public static void setNextMove(int nextMove) { @@ -103,16 +103,16 @@ public class WindowOfFreeMove extends JFrame { dialogBar.setLayout(null); inputTimer = new Timer(10, actionEvent -> { - if (!mapPainter.getActualMap().getPerson().getIsMoving() && canPersonMove && nextMove != KEY_EVENT) { - mapPainter.getActualMap().getPerson().setDirectionMove(nextMove); + if (!mapManager.getActualMap().getPerson().getIsMoving() && canPersonMove && nextMove != KEY_EVENT) { + mapManager.getActualMap().getPerson().setDirectionMove(nextMove); } }); addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { - if (!mapPainter.getActualMap().getPerson().getIsMoving() && canPersonMove || nextMove == KEY_EVENT) { - mapPainter.getActualMap().getPerson().setDirectionMove(nextMove); + if (!mapManager.getActualMap().getPerson().getIsMoving() && canPersonMove || nextMove == KEY_EVENT) { + mapManager.getActualMap().getPerson().setDirectionMove(nextMove); } } }); @@ -138,10 +138,6 @@ public class WindowOfFreeMove extends JFrame { nextMove = e.getKeyCode(); inputTimer.start(); } -// if (canPersonMove && !map.getPerson().getIsMoving() && preventDoubleMove) { -// map.getPerson().setDirectionMove(e.getKeyCode()); -// } -// preventDoubleMove = !map.getPerson().getIsMoving(); } }); @@ -214,27 +210,27 @@ public class WindowOfFreeMove extends JFrame { m5.linkMaps(m5, this); m6.linkMaps(m6, this); - mapPainter = new MapPainter(mapLinkedList, canvas); + mapManager = new MapManager(mapLinkedList, canvas); int startX = 1; int startY = 1; int endX = 8; int endY = 8; - setMapPainter(m5); + setMapManager(m5); camera.moveCamera(); - mapPainter.createMap(); + mapManager.createMap(); isReadyToPaint = true; canvas.repaint(); - Npc npc2 = new Npc(startX, startY, m6, mapPainter); + Npc npc2 = new Npc(startX, startY, m6, mapManager); m6.setNpcs(npc2); musicManager = new MusicManager("Town1.wav"); musicManager.playMusic(); Timer timer = new Timer(10, actionEvent -> { - mapPainter.getActualMap().getPerson().move(); + mapManager.getActualMap().getPerson().move(); camera.moveCamera(); canvas.repaint(); dialogBar.repaint(); @@ -255,22 +251,22 @@ public class WindowOfFreeMove extends JFrame { Graphics2D g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - for (int i = 0; i < mapPainter.getActualMap().getCanvasSize()[0]; i++) { - for (int j = 0; j < mapPainter.getActualMap().getCanvasSize()[1]; j++) { - mapPainter.getActualMap().getImageCell().paintBackground(g2D, i, j); + for (int i = 0; i < mapManager.getActualMap().getCanvasSize()[0]; i++) { + for (int j = 0; j < mapManager.getActualMap().getCanvasSize()[1]; j++) { + mapManager.getActualMap().getImageCell().paintBackground(g2D, i, j); } } - for (Cell cell : mapPainter.getActualMap().getMoveToCells()) { + for (Cell cell : mapManager.getActualMap().getMoveToCells()) { cell.paint(g2D); } - mapPainter.getActualMap().getPerson().paint(g2D); - for (Cell cell : mapPainter.getActualMap().getBlocks()) { + mapManager.getActualMap().getPerson().paint(g2D); + for (Cell cell : mapManager.getActualMap().getBlocks()) { cell.paint(g2D); } - for (Cell cell : mapPainter.getActualMap().getInteractionEventCells()) { + for (Cell cell : mapManager.getActualMap().getInteractionEventCells()) { cell.paint(g2D); } - for (Person person : mapPainter.getActualMap().getNpcs()) { + for (Person person : mapManager.getActualMap().getNpcs()) { person.paint(g2D); } }