Remove static properties ffor WindowOfFreeMove
This commit is contained in:
parent
d32861393c
commit
75307fe50d
@ -1,13 +1,15 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class Block extends Cell {
|
||||
private ImageCell imageCell;
|
||||
|
||||
public Block() {
|
||||
super(-1, -1, WindowOfFreeMove.CELL_SIZE, Color.BLUE);
|
||||
}
|
||||
|
||||
public Block(int x, int y) {
|
||||
public Block(int x, int y, ImageCell imageCell) {
|
||||
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.BLUE);
|
||||
this.imageCell = imageCell;
|
||||
}
|
||||
|
||||
public boolean isInBlock(int x, int y) {
|
||||
@ -19,7 +21,7 @@ public class Block extends Cell {
|
||||
public void paint(Graphics2D g) {
|
||||
super.paint(g);
|
||||
g.fillOval(getX() * WindowOfFreeMove.CELL_SIZE, getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE);
|
||||
g.drawImage(WindowOfFreeMove.getMap().getImageCell().getImagesOfTiles()[102], getX() * WindowOfFreeMove.CELL_SIZE,
|
||||
g.drawImage(imageCell.getImagesOfTiles()[102], getX() * WindowOfFreeMove.CELL_SIZE,
|
||||
getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@ import java.awt.*;
|
||||
|
||||
public class EventMoveToCell extends Cell {
|
||||
private Map map;
|
||||
private WindowOfFreeMove window;
|
||||
private int id;
|
||||
private int directionOut;
|
||||
|
||||
@ -23,23 +24,24 @@ public class EventMoveToCell extends Cell {
|
||||
this.map = Map.findMapByName(nameOfMap);
|
||||
}
|
||||
|
||||
public EventMoveToCell(int id, int directionOut, int x, int y, Map map){
|
||||
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;
|
||||
this.directionOut = directionOut;
|
||||
this.map = map;
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
public int getDirectionOut() { return directionOut; }
|
||||
|
||||
public void moveToMap() {
|
||||
WindowOfFreeMove.getMap().getPerson().stopPerson();
|
||||
WindowOfFreeMove.getMap().setIdExit(id);
|
||||
WindowOfFreeMove.setMap(this.map);
|
||||
WindowOfFreeMove.getMap().setIdExit(id);
|
||||
WindowOfFreeMove.paintMapOnWindow();
|
||||
WindowOfFreeMove.repaintCanvas();
|
||||
WindowOfFreeMove.setCanPersonMove(true);
|
||||
window.getMap().getPerson().stopPerson();
|
||||
window.getMap().setIdExit(id);
|
||||
window.setMap(this.map);
|
||||
window.getMap().setIdExit(id);
|
||||
window.paintMapOnWindow();
|
||||
window.repaintCanvas();
|
||||
window.setCanPersonMove(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,15 @@
|
||||
public class Game {
|
||||
private MapManager mm;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new WindowOfFreeMove().start();}
|
||||
WindowOfFreeMove window = new WindowOfFreeMove();
|
||||
Game game = new Game();
|
||||
game.setMapManager(window);
|
||||
window.start();
|
||||
}
|
||||
|
||||
private void setMapManager(WindowOfFreeMove window) {
|
||||
mm = new MapManager(window);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,6 @@ public class Map {
|
||||
name = "Spawn";
|
||||
idExit = 0;
|
||||
mapArray = new TypeOfCell[height][width];
|
||||
person = new Person();
|
||||
moveToCells = new LinkedList<EventMoveToCell>();
|
||||
block = new LinkedList<Block>();
|
||||
isBlocked = false;
|
||||
@ -41,12 +40,13 @@ public class Map {
|
||||
mapArray[i][0] = type;
|
||||
mapArray[i][mapArray.length - 1] = type;
|
||||
}
|
||||
|
||||
person = new Person(this);
|
||||
}
|
||||
|
||||
Map(int height, int width, Boolean isBlocked) {
|
||||
name = "Spawn";
|
||||
idExit = 0;
|
||||
person = new Person();
|
||||
moveToCells = new LinkedList<EventMoveToCell>();
|
||||
block = new LinkedList<Block>();
|
||||
mapArray = new TypeOfCell[height][width];
|
||||
@ -67,6 +67,8 @@ public class Map {
|
||||
mapArray[i][0] = type;
|
||||
mapArray[i][mapArray[0].length - 1] = type;
|
||||
}
|
||||
|
||||
person = new Person(this);
|
||||
}
|
||||
|
||||
public static Map findMapByName(String nameOfMap) {
|
||||
@ -114,7 +116,7 @@ public class Map {
|
||||
for (int i = 0; i < mapArray.length; i++) {
|
||||
for (int j = 0; j < mapArray.length; j++) {
|
||||
if (mapArray[i][j] == TypeOfCell.BLOCK) {
|
||||
block.add(new Block(i, j));
|
||||
block.add(new Block(i, j, imageCell));
|
||||
}
|
||||
|
||||
if (mapArray[i][j] == TypeOfCell.SPAWNPOINT && idExit == 0) {
|
||||
|
||||
14
src/main/java/MapManager.java
Normal file
14
src/main/java/MapManager.java
Normal file
@ -0,0 +1,14 @@
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class MapManager {
|
||||
WindowOfFreeMove window;
|
||||
LinkedList<Map> maps;
|
||||
Map actualMap;
|
||||
|
||||
MapManager(WindowOfFreeMove window){
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -2,6 +2,7 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Person extends Cell {
|
||||
private Map map;
|
||||
private ImagePerson imagePerson;
|
||||
private int directionMove;
|
||||
private int directionSight;
|
||||
@ -17,19 +18,21 @@ public class Person extends Cell {
|
||||
this.directionSight = directionSight;
|
||||
}
|
||||
|
||||
public Person() {
|
||||
public Person(Map map) {
|
||||
super(-1, -1, WindowOfFreeMove.CELL_SIZE, Color.RED);
|
||||
this.directionMove = 0;
|
||||
this.map = map;
|
||||
this.directionSight = 3;
|
||||
this.isMoving = false;
|
||||
this.size = WindowOfFreeMove.CELL_SIZE;
|
||||
}
|
||||
|
||||
public Person(int x, int y) {
|
||||
public Person(int x, int y, Map map) {
|
||||
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.RED);
|
||||
this.directionMove = 0;
|
||||
this.directionSight = 3;
|
||||
this.isMoving = false;
|
||||
this.map = map;
|
||||
this.size = WindowOfFreeMove.CELL_SIZE;
|
||||
}
|
||||
|
||||
@ -72,20 +75,20 @@ public class Person extends Cell {
|
||||
y = 0;
|
||||
break;
|
||||
}
|
||||
if (directionMove != 0 && !WindowOfFreeMove.getMap().isBusyCell(x, y)) {
|
||||
if (directionMove != 0 && !map.isBusyCell(x, y)) {
|
||||
directionMoveLast = directionMove;
|
||||
isMoving = true;
|
||||
} else if (directionMove != 0 && WindowOfFreeMove.getMap().isBusyCell(x, y)) {
|
||||
} else if (directionMove != 0 && map.isBusyCell(x, y)) {
|
||||
directionMoveLast = 0;
|
||||
}
|
||||
if (WindowOfFreeMove.getMap().isCellMoveTo(x, y)) {
|
||||
if (map.isCellMoveTo(x, y)) {
|
||||
set(x, y);
|
||||
WindowOfFreeMove.setCanPersonMove(false);
|
||||
if (!isMoving) {
|
||||
WindowOfFreeMove.getMap().findEventByXY(x, y).moveToMap();
|
||||
map.findEventByXY(x, y).moveToMap();
|
||||
}
|
||||
} else {
|
||||
if (!WindowOfFreeMove.getMap().isBusyCell(x, y)) {
|
||||
if (!map.isBusyCell(x, y)) {
|
||||
set(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,18 +19,18 @@ public class WindowOfFreeMove extends JFrame {
|
||||
static final int KEY_RIGHT = 39;
|
||||
static final int KEY_DOWN = 40;
|
||||
|
||||
private static Canvas canvas;
|
||||
private Canvas canvas;
|
||||
private static JPanel dialogBar;
|
||||
private JLayeredPane lp;
|
||||
private static Map map;
|
||||
private Map map;
|
||||
private Timer timer;
|
||||
private Timer inputTimer;
|
||||
|
||||
public static Map getMap() {
|
||||
public Map getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void repaintCanvas(){
|
||||
public void repaintCanvas(){
|
||||
canvas.repaint();
|
||||
}
|
||||
|
||||
@ -46,12 +46,12 @@ public class WindowOfFreeMove extends JFrame {
|
||||
WindowOfFreeMove.dialogBar = dialogBar;
|
||||
}
|
||||
|
||||
public static void setMap(Map map) {
|
||||
WindowOfFreeMove.map = map;
|
||||
public void setMap(Map map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public static void paintMapOnWindow() {
|
||||
WindowOfFreeMove.map.createMap();
|
||||
public void paintMapOnWindow() {
|
||||
this.map.createMap();
|
||||
}
|
||||
|
||||
public WindowOfFreeMove() {
|
||||
@ -147,17 +147,17 @@ public class WindowOfFreeMove extends JFrame {
|
||||
m4.getPerson().setImagePerson("mainpng.png", rec);
|
||||
m4.setName("4");
|
||||
|
||||
m1.addMoveToEvent(new EventMoveToCell(1, 1, 8, 8, m2));
|
||||
m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4));
|
||||
m1.addMoveToEvent(new EventMoveToCell(1, 1, 8, 8, m2, this));
|
||||
m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4, this));
|
||||
|
||||
m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3));
|
||||
m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1));
|
||||
m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3, this));
|
||||
m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1, this));
|
||||
|
||||
m3.addMoveToEvent(new EventMoveToCell(3, 1, 8, 8, m4));
|
||||
m3.addMoveToEvent(new EventMoveToCell(2, 3, 8, 1, m2));
|
||||
m3.addMoveToEvent(new EventMoveToCell(3, 1, 8, 8, m4, this));
|
||||
m3.addMoveToEvent(new EventMoveToCell(2, 3, 8, 1, m2, this));
|
||||
|
||||
m4.addMoveToEvent(new EventMoveToCell(4, 1, 8, 8, m1));
|
||||
m4.addMoveToEvent(new EventMoveToCell(3, 3, 8, 1, m3));
|
||||
m4.addMoveToEvent(new EventMoveToCell(4, 1, 8, 8, m1, this));
|
||||
m4.addMoveToEvent(new EventMoveToCell(3, 3, 8, 1, m3, this));
|
||||
|
||||
m1.getImageCell().readMapFile("map-test");
|
||||
|
||||
@ -200,7 +200,7 @@ public class WindowOfFreeMove extends JFrame {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
static class Canvas extends JPanel {
|
||||
class Canvas extends JPanel {
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
if (isReadyToPaint) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user