Skip to content

Commit 8350f47

Browse files
committed
deltas
1 parent 934f79d commit 8350f47

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

src/main/java/com/game/engine/entities/Entity.java

+7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import com.game.engine.components.ControlComponent;
99
import com.game.engine.components.GraphicsComponent;
1010
import com.game.engine.components.PhysicsComponent;
11+
import com.game.engine.util.IdGenerator;
1112
public class Entity {
1213

1314
public static enum State {
1415
ALIVE,
1516
DESTROYED
1617
}
1718

19+
private String entityId;
1820
private List<Component> _components;
1921
private ControlComponent _controlComponent;
2022
private PhysicsComponent _physicsComponent;
@@ -27,6 +29,7 @@ public Entity(ControlComponent control, PhysicsComponent physics, GraphicsCompon
2729
_graphicsComponent = graphicsComponent;
2830
_components = new ArrayList<Component>();
2931
_components = List.of(control, physics, graphicsComponent);
32+
this.entityId = IdGenerator.generateIdString(8);
3033

3134
}
3235

@@ -36,6 +39,10 @@ public void update(Batch batch, float delta){
3639

3740
}
3841

42+
public String getEntityId(){
43+
return this.entityId;
44+
}
45+
3946
public void dispose(){
4047
_components.stream().forEach(Component::dispose);
4148
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.game.engine.util;
2+
3+
import java.security.SecureRandom;
4+
import java.util.stream.Collectors;
5+
import java.util.stream.IntStream;
6+
7+
public class IdGenerator {
8+
9+
public static String generateIdString(int length) {
10+
SecureRandom random = new SecureRandom();
11+
return IntStream.range(0, length)
12+
.map(i -> random.nextInt(62))
13+
.mapToObj(i -> "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".charAt(i))
14+
.map(Object::toString)
15+
.collect(Collectors.joining());
16+
}
17+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)