Reputation: 193
I want to create a map with different properties.
So my idea is to have a createMap() function. In the createMap() function I have to do this comparision:
List<List<int>> unusableTiles = List<List<int>>();
unusableTiles = [[0,2],[1,2],[2,2]];
int tilesX=5, tilesY=5;
for(int i=0; i<tilesX; i++){
for(int j=0;j<tilesY;j++) {
if ([i,j]==unusableTiles[:]){ // How would I do this comparision?
doSomething();
}else{
doNothing();
}
}
}
I would like to call "doSomething()" if the coordinates i and j are in the List. So in that case I would like to call doSomething() if i==0&&j==2 or i==1&&j==2 or i==2&&j==2
. Else I would call doNothing().
Any suggestions for this?
Upvotes: 0
Views: 69
Reputation: 10953
You could do something like this:
unusableTiles.any((e) => e.first == i && e.last == j) ? doSomething() : doNothing();
or
unusableTiles.any((e) => e[0] == i && e[1] == j) ? doSomething() : doNothing();
Upvotes: 2