-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShopContainerItemsPanel.java
More file actions
58 lines (49 loc) · 1.91 KB
/
Copy pathShopContainerItemsPanel.java
File metadata and controls
58 lines (49 loc) · 1.91 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
package Grafica.JavaClashOfClans;
import Grafica.JavaClashOfClans.builds.*;
import Grafica.JavaClashOfClans.builds.defenses.ArcherTower;
import Grafica.JavaClashOfClans.builds.defenses.Cannon;
import Grafica.JavaClashOfClans.builds.defenses.Wall;
import Grafica.JavaClashOfClans.builds.resources.ElixirCollector;
import Grafica.JavaClashOfClans.builds.resources.GoldMine;
import Grafica.JavaClashOfClans.builds.traps.Bomb;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class ShopContainerItemsPanel extends JPanel {
private String section;
private ArrayList<Build> builds;
private int width, rows, cols;
ShopContainerItemsPanel(String section, int width, int height, int rows, int cols, MainWindow mainWindow){
super(new GridLayout(rows,cols));
this.section = section;
this.builds = setArrayItems();
this.width = width;
this.rows = rows;
this.cols = cols;
if (builds.size() == 0) {
System.out.println("[ERROR] " + "Error while trying to set up items in the sections of the store");
} else {
for (int i = 0; i < rows*cols; i++) {
if (builds.size() > i) {
add(new ShopItemPanel(builds.get(i), width/cols, mainWindow));
} else {
add(new JPanel());
}
}
}
}
private ArrayList<Build> setArrayItems() {
ArrayList<Build> arrayItems = new ArrayList<>();
if (section.equals("defenses")){
arrayItems.add(new Cannon());
arrayItems.add(new ArcherTower());
arrayItems.add(new Wall());
} else if (section.equals("traps")) {
arrayItems.add(new Bomb());
} else if (section.equals("resources")) {
arrayItems.add(new GoldMine());
arrayItems.add(new ElixirCollector());
}
return arrayItems;
}
}