mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Lagt til getPositionOfTileOnBoard metoder og generisk metode makeTileList
This commit is contained in:
parent
b03270203e
commit
54ada72297
@ -1,10 +1,9 @@
|
|||||||
package inf112.fiasko.roborally.objects;
|
package inf112.fiasko.roborally.objects;
|
||||||
|
|
||||||
import inf112.fiasko.roborally.element_properties.Direction;
|
import inf112.fiasko.roborally.element_properties.*;
|
||||||
import inf112.fiasko.roborally.element_properties.Position;
|
import inf112.fiasko.roborally.utility.TextureConverterUtil;
|
||||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
|
||||||
import inf112.fiasko.roborally.element_properties.TileType;
|
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -310,4 +309,36 @@ public class Board {
|
|||||||
}
|
}
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public List<BoardElementContainer<Tile>> getPositionsOfTileOnBoard(TileType tile) {
|
||||||
|
return makeTileList(tile, tiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BoardElementContainer<Wall>> getPositionsOfTileOnBoard(WallType tile) {
|
||||||
|
return makeTileList(tile, walls);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <K,T> List<BoardElementContainer<T>> makeTileList(K type, IGrid<T> grid) {
|
||||||
|
List<BoardElementContainer<T>> objList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int y = grid.getHeight() - 1; y >= 0; y--) {
|
||||||
|
for (int x = 0; x < grid.getWidth(); x++) {
|
||||||
|
T gridElement = grid.getElement(x, y);
|
||||||
|
if (gridElement.getClass().isAssignableFrom(Tile.class)) {
|
||||||
|
Tile tile = (Tile) gridElement;
|
||||||
|
if (tile.getTileType() == type) {
|
||||||
|
objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
|
||||||
|
}
|
||||||
|
} else if (gridElement.getClass().isAssignableFrom(Wall.class)) {
|
||||||
|
Wall wall = (Wall) gridElement;
|
||||||
|
if (wall.getWallType() == type) {
|
||||||
|
objList.add(new BoardElementContainer<>(gridElement, new Position(x,y)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Grid has unknown type.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return objList;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user