-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositeGameElement.java
More file actions
41 lines (35 loc) · 1.05 KB
/
Copy pathCompositeGameElement.java
File metadata and controls
41 lines (35 loc) · 1.05 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
package work3;
import java.util.ArrayList;
import java.util.List;
/**
* Композитний елемент, що містить інші елементи.
* Шаблон: Composite (Composite).
*/
public class CompositeGameElement implements GameElement {
private List<GameElement> children = new ArrayList<>();
private String groupName;
public CompositeGameElement(String groupName) {
this.groupName = groupName;
}
/**
* Додає елемент до групи.
*/
public void add(GameElement element) {
children.add(element);
}
/**
* Видаляє елемент з групи.
*/
public void remove(GameElement element) {
children.remove(element);
}
@Override
public double getArea() {
double totalArea = 0;
for (GameElement child : children) {
totalArea += child.getArea();
}
System.out.println("Group '" + groupName + "' total area: " + totalArea);
return totalArea;
}
}