Home > OS >  Android combine multiple booleans with elements from List<Integer>
Android combine multiple booleans with elements from List<Integer>

Time:12-14

Hello I am developing a game and working on collision detection. For now my method does not allow to add elements dynamically, as you can see I am adding collision nodes (11,12,13,...) manually. Here is my code:

private boolean isNotACollision(int index, int actualIndex) {
    return title.equals("shop")
            && index != 11 && index != 12 && index != 13 && index != 21 && index != 23 && index != 31 && index != 33
            && actualIndex != 11 && actualIndex != 12 && actualIndex != 13 && actualIndex != 21 && actualIndex != 23 && actualIndex != 31 && actualIndex != 33;
}

I want to dynamically build a boolean isNotCollision() depending on number of elements of collision in List. I want to rebuild it in a way that it hase List<Integer> collisionNodes as an argument.

private boolean isNotACollision(int index, int actualIndex, List<Integer> collisionNodes) {
    boolean shopMapCollision = (title.equals("shop")
            && WHAT HERE??;
    return shopMapCollision;
}

CodePudding user response:

Try :

private boolean isNotACollision(int index, int actualIndex, List<Integer> collisionNodes) {
    boolean shopMapCollision = (title.equals("shop")
            && !collisionNodes.contains(index) && !collisionNodes.contains(actualIndex));
    return shopMapCollision;
}
  • Related