You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: update-method/README.md
+55-14Lines changed: 55 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ public class World {
49
49
entities =newArrayList<>();
50
50
isRunning =false;
51
51
}
52
-
// ...
52
+
//Other properties and methods...
53
53
}
54
54
```
55
55
@@ -124,23 +124,64 @@ public void addEntity(Entity entity) {
124
124
In the `App` class, we can see how the `World` class and its methods are used to create a game world, add entities to it, and start the game loop.
125
125
126
126
```java
127
-
var world =newWorld();
128
-
var skeleton1 =newSkeleton(1, 10);
129
-
var skeleton2 =newSkeleton(2, 70);
130
-
var statue =newStatue(3, 20);
131
-
world.addEntity(skeleton1);
132
-
world.addEntity(skeleton2);
133
-
world.addEntity(statue);
134
-
world.run();
135
-
Thread.sleep(GAME_RUNNING_TIME);
136
-
world.stop();
127
+
@Slf4j
128
+
publicclassApp {
129
+
130
+
privatestaticfinalintGAME_RUNNING_TIME=2000;
131
+
132
+
publicstaticvoidmain(String[] args) {
133
+
try {
134
+
var world =newWorld();
135
+
var skeleton1 =newSkeleton(1, 10);
136
+
var skeleton2 =newSkeleton(2, 70);
137
+
var statue =newStatue(3, 20);
138
+
world.addEntity(skeleton1);
139
+
world.addEntity(skeleton2);
140
+
world.addEntity(statue);
141
+
world.run();
142
+
Thread.sleep(GAME_RUNNING_TIME);
143
+
world.stop();
144
+
} catch (InterruptedException e) {
145
+
LOGGER.error(e.getMessage());
146
+
}
147
+
}
148
+
}
137
149
```
138
150
139
-
This is a basic implementation of the Update Method pattern. In a real-world application, the `Entity` class would likely have additional methods and properties, and the `update` method would contain more complex logic to simulate the entity's behavior.
151
+
Console output:
140
152
141
-
## Class diagram
153
+
```
154
+
14:46:33.181 [main] INFO com.iluwatar.updatemethod.World -- Start game.
155
+
14:46:33.280 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 11.
156
+
14:46:33.281 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 71.
157
+
14:46:33.452 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 12.
158
+
14:46:33.452 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 72.
159
+
14:46:33.621 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 13.
160
+
14:46:33.621 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 73.
161
+
14:46:33.793 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 14.
162
+
14:46:33.793 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 74.
163
+
14:46:33.885 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 15.
164
+
14:46:33.885 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 75.
165
+
14:46:34.113 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 16.
166
+
14:46:34.113 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 76.
167
+
14:46:34.324 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 17.
168
+
14:46:34.324 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 77.
169
+
14:46:34.574 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 18.
170
+
14:46:34.575 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 78.
171
+
14:46:34.730 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 19.
172
+
14:46:34.731 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 79.
173
+
14:46:34.803 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 20.
174
+
14:46:34.803 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 80.
175
+
14:46:34.979 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 21.
176
+
14:46:34.979 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 81.
177
+
14:46:35.045 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 22.
178
+
14:46:35.046 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 82.
179
+
14:46:35.187 [main] INFO com.iluwatar.updatemethod.World -- Stop game.
180
+
14:46:35.288 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 1 is on position 23.
181
+
14:46:35.289 [Thread-0] INFO com.iluwatar.updatemethod.Skeleton -- Skeleton 2 is on position 83.
182
+
```
142
183
143
-

184
+
This is a basic implementation of the Update Method pattern. In a real-world application, the `Entity` class would likely have additional methods and properties, and the `update` method would contain more complex logic to simulate the entity's behavior.
0 commit comments