-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.java
86 lines (83 loc) · 2.5 KB
/
Map.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package Game_Tank_multiplayer;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import java.util.*;
import java.io.*;
public class Map extends Pane implements Serializable{
private int size;
private char[][] map;
private Position start;
private ArrayList<ImageView> list;
private ArrayList<Brick> bricks;
public Map(Scanner input, int size){
this.size = size;
map = new char[size][size];
list = new ArrayList<>();
bricks = new ArrayList<>();
for(int i = 0; i < size; i++){
for(int j = 0; j < size; j++){
map[i][j] = input.next().charAt(0);
Rectangle layout = new Rectangle(j * 40, i * 40, 40,40);
getChildren().add(layout);
if(map[i][j] == '#'){
Rectangle rec = new Rectangle(j * 40, i * 40, 40, 40);
rec.setFill(Color.GREY);
getChildren().add(rec);
}
else if(map[i][j] == 'B'){
Brick brick = new Brick(j,i);
getChildren().add(brick.getBrick());
bricks.add(brick);
}
else if(map[i][j] == 'T'){
list.add(new Tree(j, i).getTree());
}
else if(map[i][j] =='S'){
getChildren().add(new Steel(j,i).getSteel());
}
else if(map[i][j] == 'W'){
getChildren().add(new Water(j, i).getWater());
}
}
}
}
public void setStart(Position start) {
this.start = start;
}
public void modifyMap(int i, int j, char ch){
synchronized (this) {
map[i][j] = ch;
}
}
public ArrayList<Brick> getBricks(){
return bricks;
}
public void modifyMap(int i, int j){
map[i][j] = 0;
}
public int getSize(){
return size;
}
public Position getStartPosition(){
return start;
}
public char getValueAt(int i, int j){
return map[i][j];
}
public ArrayList<ImageView> getTrees(){
return list;
}
public char[][] getMap(){
return map;
}
public void print(){
for(int i = 0; i < size; i++){
for (int j = 0; j < size; j++){
System.out.print(map[i][j] + " ");
}
System.out.println();
}
}
}