package ruscz.game.gameOfProd.Cells; import ruscz.game.gameOfProd.Map.Map; import ruscz.game.gameOfProd.Map.MapPainter; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import java.awt.*; public class Npc extends Person { private int[] path; private MapPainter mapPainter; int x; int y; Color color; public Npc(int x, int y, Map map, MapPainter mapPainter) { super(x, y, map); this.mapPainter = mapPainter; this.color = Color.cyan; } public void move(int endX, int endY) { x = this.getX(); y = this.getY(); path = new int[2]; path[0] = endX-x; path[1] = endY-y; for (int i = 0; i < Math.abs(path[0]); i++) { WindowOfFreeMove.sleep(500); moveX(); mapPainter.repaintCanvas(); } for (int i = 0; i < Math.abs(path[1]); i++) { WindowOfFreeMove.sleep(500); moveY(); mapPainter.repaintCanvas(); } } public void moveX() { if (path[0] > 0) { x++; set(x, y); } else { x--; set(x,y); } } public void moveY() { if (path[1] > 0) { y++; set(x, y); } else { y--; set(x,y); } } @Override public void paint(Graphics2D g) { g.setColor(color); g.fillOval(getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE); } }