how should i do it to make sure it works properly


((Level1)getWorld()).getCounter().addScore();
if (getWorld() instanceof Level1) ((Level1)getWorld()).getCounter().addScore(); else if (getWorld() instanceof Level2) ((Level2)getWorld()).getCounter().addScore(); // etc.
public void destroyEnemies() { Actor enemy = getOneIntersectingObject(enemy.class); if(enemy != null) { World myWorld = getWorld(); getWorld().removeObject(enemy); Level1 level1 = (Level1)myWorld; Counter counter = level1.getCounter(); counter.addScore(); ((Level1)getWorld()).getCounter().addScore(); if (getWorld() instanceof Level1) ((Level1)getWorld()).getCounter().addScore(); else if (getWorld() instanceof Level2) ((Level2)getWorld()).getCounter().addScore(); } }
public void destroyEnemies() { if (isTouching(enemy.class)) { removeTouching(enemy.class)) if (getWorld() instanceof Level1) ((Level1)getWorld()).getCounter().addScore(); } }