-
Notifications
You must be signed in to change notification settings - Fork 1
/
Screen.java
97 lines (84 loc) · 1.96 KB
/
Screen.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
87
88
89
90
91
92
93
94
95
96
97
/*
* Name: Screen
* Beschreibung: Eine Collection von GameObject's. (Sowas wie ein Canvas.)
*
*
*/
import java.util.ArrayList;
import java.util.List;
public class Screen {
private List<GameObject> objects;
private boolean visible;
/**
* no argument screen constructor;
* it creates a new ArrayList of objects and sets
* itself to invisible
* */
public Screen() {
objects = new ArrayList<>();
setVisible(false);
}
/**
* screen constructor which gets a list of objects and
* adds them to its objects ArrayList
* */
public Screen(List<GameObject> objects) {
this();
addObject(objects);
}
/**
* update method which iterates through the objects ArrayList, gets
* all GameObjects and calls their individual update methods!
* */
public void update() {
for (GameObject gameObject : objects) {
gameObject.update();
}
}
/**
* resets each GameObject and sets the screen to invisible
* */
public void reset() {
setVisible(false);
for (GameObject gameObject : objects) {
gameObject.reset();
}
}
/**
* the method used to add individual GameObjects to the ArrayList
* */
public void addObject(GameObject gameObject) {
objects.add(gameObject);
}
/**
* the method used to add Lists of GameObjects to the ArrayList
* */
public void addObject(List<GameObject> objects) {
for (GameObject gameObject : objects) {
addObject(gameObject);
}
}
/**
* returns the ArrayList of GameObjects currently used by this screen
* */
public List<GameObject> getObjects () {
return objects;
}
/**
* returns the boolean to check whether this screen should be visible or not
* */
public boolean isVisible() {
return visible;
}
/**
* sets the visibility of the screen to the desired state
* @param visibile
* boolean to which we set the screens visibility
* */
public void setVisible(boolean visibile) {
this.visible = visibile;
for (GameObject gameObject : objects) {
gameObject.setVisible(visibile);
}
}
}