import java.awt.*; public class Person extends Cell { private int direction; public Person() { super(-1, -1, WindowOfFreeMove.CELL_SIZE, Color.RED); this.direction = 0; } public Person(int x, int y) { super(x, y, WindowOfFreeMove.CELL_SIZE, Color.RED); this.direction = 0; } public void setDirection(int direction) { if ((direction >= WindowOfFreeMove.KEY_LEFT) && (direction <= WindowOfFreeMove.KEY_DOWN)) this.direction = direction; } public void move() { int x = this.getX(); int y = this.getY(); switch (direction) { case WindowOfFreeMove.KEY_LEFT: x--; if (x < 0) x = WindowOfFreeMove.CANVAS_WIDTH - 1; break; case WindowOfFreeMove.KEY_RIGHT: x++; if (x == WindowOfFreeMove.CANVAS_WIDTH) x = 0; break; case WindowOfFreeMove.KEY_UP: y--; if (y < 0) y = WindowOfFreeMove.CANVAS_HEIGHT - 1; break; case WindowOfFreeMove.KEY_DOWN: y++; if (y == WindowOfFreeMove.CANVAS_HEIGHT) y = 0; break; } this.direction = 0; if (WindowOfFreeMove.getMap().isCellMoveTo(x, y)) { WindowOfFreeMove.getMap().findEventByXY(x, y).moveToMap(); } else { if (!WindowOfFreeMove.getMap().isBusyCell(x, y)) { set(x, y); } } } public boolean isInPerson(int x, int y) { if (this.getX() == x && this.getY() == y) return true; return false; } @Override public void paint(Graphics2D g) { super.paint(g); g.drawString(Integer.toString(WindowOfFreeMove.getMap().getIdExit()), getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE); } }