-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.java
More file actions
81 lines (72 loc) · 1.74 KB
/
Factory.java
File metadata and controls
81 lines (72 loc) · 1.74 KB
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
import java.util.*;
public class Factory {
private Tile[][] factoryTiles;
private Center center;
private int y,x;
//Constructor
public Factory(Center center) {
factoryTiles = new Tile[2][2];
this.center = center;
}
//returns array of tiles of the factory
public Tile[][] getFactoryTiles() {return factoryTiles;}
//sets the factory's tiles
public void setTiles(ArrayList<Tile> newTiles) {
for(int r = 0; r<factoryTiles.length;r++) {
for(int c = 0; c<factoryTiles[r].length;c++) {
if(!newTiles.isEmpty()) {
factoryTiles[r][c] = newTiles.remove(0);
}
}
}
}
public void drawFactoryTiles(String color){
ArrayList<Tile> extraTiles = new ArrayList<>();
for(int r = 0; r<factoryTiles.length;r++) {
for(int c = 0; c<factoryTiles[r].length; c++) {
if(!(factoryTiles[r][c]==null)) {
factoryTiles[r][c].deselect();
if(!(factoryTiles[r][c].getColor().equals(color))) {
extraTiles.add(factoryTiles[r][c]);
}
}
factoryTiles[r][c] = null;
}
}
center.addCenterTiles(extraTiles);
}
public ArrayList<Tile> selectOfColor(String color) {
ArrayList<Tile> tilesOfColor = new ArrayList<>();
for(int r = 0; r<factoryTiles.length;r++) {
for(int c = 0; c<factoryTiles[r].length;c++) {
if(factoryTiles[r][c]!=null){
if(factoryTiles[r][c].getColor().equals(color)) {
factoryTiles[r][c].select();
tilesOfColor.add(factoryTiles[r][c]);
}
}
}
}
return tilesOfColor;
}
public int getY() {
return y;
}
public int getX() {
return x;
}
public void setCoords(int x, int y) {
this.x = x;
this.y = y;
}
public boolean isEmpty() {
for(Tile[] row:factoryTiles) {
for(Tile t:row) {
if(!(t==null)) {
return false;
}
}
}
return true;
}
}