This commit is contained in:
iryupnik 2020-03-15 11:15:53 +01:00
parent f011048ed6
commit 2e028db9f0
6 changed files with 48 additions and 42 deletions

View File

@ -27,7 +27,11 @@ public class TriggerCell extends InteractionCell {
getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null); 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;
}
} }

View File

@ -14,7 +14,6 @@ import java.util.Scanner;
public class ImageCell { public class ImageCell {
private static BufferedImage image; private static BufferedImage image;
private static LinkedList<BufferedImage> imagesOfTiles; private static LinkedList<BufferedImage> imagesOfTiles;
private Scanner scanner;
private int[] mapBackground; private int[] mapBackground;
public void readMapFile(String name) { public void readMapFile(String name) {
@ -22,14 +21,13 @@ public class ImageCell {
mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH * WindowOfFreeMove.CANVAS_HEIGHT]; mapBackground = new int[WindowOfFreeMove.CANVAS_WIDTH * WindowOfFreeMove.CANVAS_HEIGHT];
int count = 0; int count = 0;
File mapFile = new File("src/main/resources/maps/" + name + ".txt"); File mapFile = new File("src/main/resources/maps/" + name + ".txt");
scanner = new Scanner(mapFile); Scanner scanner = new Scanner(mapFile);
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
String data = scanner.nextLine(); String data = scanner.nextLine();
if (data.contains("<tileset>")) { if (data.contains("<tileset>")) {
String[] mapInfo = data.split(" "); String[] mapInfo = data.split(" ");
ImageTileset(mapInfo); ImageTileset(mapInfo);
} } else {
else {
String[] mapColumn = data.split(" "); String[] mapColumn = data.split(" ");
for (int i = 0; i < mapColumn.length; i++) { for (int i = 0; i < mapColumn.length; i++) {
mapBackground[count] = Integer.parseInt(mapColumn[i]); mapBackground[count] = Integer.parseInt(mapColumn[i]);
@ -63,8 +61,8 @@ public class ImageCell {
Rectangle[] rectangles = new Rectangle[tiles]; Rectangle[] rectangles = new Rectangle[tiles];
int count = 0; int count = 0;
for (int i = 0; i < rectangles.length/Ytiles; i++){ for (int i = 0; i < rectangles.length / Ytiles; i++) {
for (int j = 0; j < rectangles.length/Xtiles; j++) { for (int j = 0; j < rectangles.length / Xtiles; j++) {
rectangles[count] = new Rectangle(tileSize * i, tileSize * j, tileSize, tileSize); rectangles[count] = new Rectangle(tileSize * i, tileSize * j, tileSize, tileSize);
count++; count++;
} }

View File

@ -23,8 +23,8 @@ public class Map {
private boolean isBlocked; private boolean isBlocked;
private int idExit; private int idExit;
private ImageCell imageCell; private ImageCell imageCell;
private static Scanner scanner; private static Scanner scanner;
private static LinkedList<String[]> listOfMoveToCells;
public Map(int height, int width) { public Map(int height, int width) {
name = "Spawn"; name = "Spawn";
@ -115,9 +115,9 @@ public class Map {
Map map = new Map(mapArray); Map map = new Map(mapArray);
map.setName(name); map.setName(name);
map.getImageCell().readMapFile(name + "-tileset"); map.getImageCell().readMapFile(name + "-tileset");
listOfMoveToCells = new LinkedList<>(); LinkedList<String[]> listOfMoveToCells = new LinkedList<>();
int y = 0; int y = 0;
while(scanner.hasNextLine()) { while (scanner.hasNextLine()) {
loadMap(map, size, y, window); loadMap(map, size, y, window);
y++; y++;
} }
@ -133,26 +133,22 @@ public class Map {
String[] line = data.split(" "); String[] line = data.split(" ");
for (int x = 0; x < Integer.parseInt(size[0]); x++) { for (int x = 0; x < Integer.parseInt(size[0]); x++) {
TypeOfCell cellType = null; TypeOfCell cellType = null;
if (line[x].equals("BLOCK")){ if (line[x].equals("BLOCK")) {
cellType = TypeOfCell.BLOCK; cellType = TypeOfCell.BLOCK;
map.getMapArray()[x][y] = cellType; map.getMapArray()[x][y] = cellType;
map.getBlocks().add(new Block(x, y, map.getImageCell())); map.getBlocks().add(new Block(x, y, map.getImageCell()));
} } else if (line[x].equals("EMPTY")) {
else if (line[x].equals("EMPTY")) {
cellType = TypeOfCell.EMPTY; cellType = TypeOfCell.EMPTY;
map.getMapArray()[x][y] = cellType; map.getMapArray()[x][y] = cellType;
} } else if (line[x].contains("INTER")) {
else if (line[x].contains("INTER")) {
ImageCell imageCell = new ImageCell(); ImageCell imageCell = new ImageCell();
String[] event = line[x].split(","); String[] event = line[x].split(",");
map.addInteractionEvent(new InteractionCell(x, y, event[1], new Dialog(WindowOfFreeMove.getDialogBar()), map.getImageCell())); 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(); ImageCell imageCell = new ImageCell();
String[] trigger = line[x].split(","); String[] trigger = line[x].split(",");
map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(WindowOfFreeMove.getDialogBar()), map.getImageCell())); 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); map.setSpawnPoint(x, y);
} }
} }
@ -166,7 +162,7 @@ public class Map {
String firstLine = scanner.nextLine(); String firstLine = scanner.nextLine();
String[] size = firstLine.split(" "); String[] size = firstLine.split(" ");
int y = 0; int y = 0;
while(scanner.hasNextLine()) { while (scanner.hasNextLine()) {
String data = scanner.nextLine(); String data = scanner.nextLine();
String[] line = data.split(" "); String[] line = data.split(" ");
for (int x = 0; x < Integer.parseInt(size[0]); x++) { for (int x = 0; x < Integer.parseInt(size[0]); x++) {
@ -234,9 +230,13 @@ public class Map {
mapArray[x][y] = TypeOfCell.SPAWNPOINT; 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) { public boolean isBusyCell(int x, int y) {

View File

@ -11,21 +11,20 @@ public class MapPainter {
private LinkedList<Map> maps; private LinkedList<Map> maps;
private Map actualMap; private Map actualMap;
public MapPainter (LinkedList<Map> maps){ public MapPainter(LinkedList<Map> maps) {
this.maps = maps; this.maps = maps;
} }
public void setMap(Map map){ public void setMap(Map map) {
if (maps.contains(map)){ if (maps.contains(map)) {
actualMap = map; actualMap = map;
} } else {
else {
maps.add(map); maps.add(map);
actualMap = map; actualMap = map;
} }
} }
public Map getActualMap(){ public Map getActualMap() {
return actualMap; return actualMap;
} }
@ -33,7 +32,7 @@ public class MapPainter {
public void createMap() { public void createMap() {
for (int i = 0; i < actualMap.getMapArray().length; i++) { for (int i = 0; i < actualMap.getMapArray().length; i++) {
for (int j = 0; j < actualMap.getMapArray().length; j++) { 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())); actualMap.getBlocks().add(new Block(i, j, actualMap.getImageCell()));
} }
@ -84,7 +83,4 @@ public class MapPainter {
} }
} }
} }
} }

View File

@ -1,4 +1,5 @@
package ruscz.game.gameOfProd.Windows; package ruscz.game.gameOfProd.Windows;
import ruscz.game.gameOfProd.Cells.Cell; import ruscz.game.gameOfProd.Cells.Cell;
import ruscz.game.gameOfProd.Cells.EventMoveToCell; import ruscz.game.gameOfProd.Cells.EventMoveToCell;
import ruscz.game.gameOfProd.Cells.InteractionCell; import ruscz.game.gameOfProd.Cells.InteractionCell;
@ -43,7 +44,7 @@ public class WindowOfFreeMove extends JFrame {
return map; return map;
} }
public void repaintCanvas(){ public void repaintCanvas() {
canvas.repaint(); canvas.repaint();
} }
@ -52,7 +53,8 @@ public class WindowOfFreeMove extends JFrame {
} }
public void setMap(Map map) { public void setMap(Map map) {
; this. ;
this.
map. map.
setMap(map); setMap(map);
} }
@ -61,11 +63,17 @@ public class WindowOfFreeMove extends JFrame {
this.map.createMap(); 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<Map> getMapLinkedList() { return mapLinkedList; } public static LinkedList<Map> getMapLinkedList() {
return mapLinkedList;
}
public WindowOfFreeMove() { public WindowOfFreeMove() {
isReadyToPaint = false; isReadyToPaint = false;
@ -140,8 +148,8 @@ public class WindowOfFreeMove extends JFrame {
public void start() { public void start() {
Rectangle[] rec = new Rectangle[12]; Rectangle[] rec = new Rectangle[12];
int count = 0; int count = 0;
for (int i = 0; i < rec.length/4; i++){ for (int i = 0; i < rec.length / 4; i++) {
for (int j = 0; j <rec.length/3; j++) { for (int j = 0; j < rec.length / 3; j++) {
rec[count] = new Rectangle(40 * i, 40 * j, 40, 40); rec[count] = new Rectangle(40 * i, 40 * j, 40, 40);
count++; count++;
} }
@ -258,7 +266,7 @@ public class WindowOfFreeMove extends JFrame {
for (Cell cell : map.getActualMap().getBlocks()) { for (Cell cell : map.getActualMap().getBlocks()) {
cell.paint(g2D); cell.paint(g2D);
} }
for (Cell cell: map.getActualMap().getInteractionEventCells()){ for (Cell cell : map.getActualMap().getInteractionEventCells()) {
cell.paint(g2D); cell.paint(g2D);
} }
} }

View File

@ -6,7 +6,7 @@
0 0 83 95 0 0 83 95 0 0 0 0 83 95 0 0 83 95 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 153 0 0 0 0 153 0 0 0 0 153 0 0 0 0 153 0 0
0 0 0 153 153 153 153 0 0 0 0 0 153 153 153 153 153 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0