Skip to content

Commit 723b1bf

Browse files
committed
docs: update method
1 parent 790d2d6 commit 723b1bf

File tree

1 file changed

+55
-14
lines changed

1 file changed

+55
-14
lines changed

update-method/README.md

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class World {
4949
entities = new ArrayList<>();
5050
isRunning = false;
5151
}
52-
// ...
52+
// Other properties and methods...
5353
}
5454
```
5555

@@ -124,23 +124,64 @@ public void addEntity(Entity entity) {
124124
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.
125125

126126
```java
127-
var world = new World();
128-
var skeleton1 = new Skeleton(1, 10);
129-
var skeleton2 = new Skeleton(2, 70);
130-
var statue = new Statue(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+
public class App {
129+
130+
private static final int GAME_RUNNING_TIME = 2000;
131+
132+
public static void main(String[] args) {
133+
try {
134+
var world = new World();
135+
var skeleton1 = new Skeleton(1, 10);
136+
var skeleton2 = new Skeleton(2, 70);
137+
var statue = new Statue(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+
}
137149
```
138150

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:
140152

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+
```
142183

143-
![Update Method](./etc/update-method.urm.png "Update Method pattern class diagram")
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.
144185

145186
## Applicability
146187

0 commit comments

Comments
 (0)