I'm developing a game in LibGDX and I have a static int named TILE_ID that is assigned to every tile everytime a tile is created, like this:
{loop in Level.class}
Tile t = null;
switch (material) {
case HOME: {
t = new Home(x, y);
break;
}
case WALL_IRON:
case WALL_BRICK: {
t = new Tile(x, y, material, type);
break;
}
}
if (t != null) {
if (t instanceof Home) {
this.home = t;
}
t.tileID = TILE_ID++;
tileArray.add(t);
}
{loop-end in Level.class}
So when I start a new game, the first instance says:
private final Listener clientListener = new Listener() {
@Override
public void connected(Connection connection) {
PacketEntity p = (PacketEntity) Packet.createPacket(
PacketEntity.class, Packet.TYPE.CONNECTED);
p.name = pTank.getName();
connection.sendTCP(p);
System.out.println("MAX TILES: " + Level.TILE_ID);
System.out.println("connected to server!");
}
The output is:
:desktop:run
new manager
disposed main menu!
Initializing local server...
Client connected! ID# 1
MAX TILES: 76
connected to server!
And then I run a second instance, connect to the localhost server and the output is:
:desktop:run
new manager
disposed main menu!
A server is already running on localhost. Trying to connect....
MAX TILES: 152
connected to server!
I don't understand why this happens. If I connect a third client and so on, the max tiles is always 152.
The only place the tileid increases is inside the Level.class which is local to every player (not sent over the network).
Can someone help me out with this?