mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +01:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
This commit is contained in:
commit
d5d87d11dd
@ -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;
|
||||||
@ -327,4 +326,62 @@ public class Board {
|
|||||||
}
|
}
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Gets a list of BoardElementContainers, containing all tiles and positions of given tile types
|
||||||
|
* @param tiles The tiles you want all positions for
|
||||||
|
* @return A list of BoardElementContainers
|
||||||
|
*/
|
||||||
|
public List<BoardElementContainer<Tile>> getPositionsOfTileOnBoard(TileType ... tiles) {
|
||||||
|
List<BoardElementContainer<Tile>> combinedList = new ArrayList<>();
|
||||||
|
for (TileType tile : tiles) {
|
||||||
|
combinedList.addAll(makeTileList(tile, this.tiles));
|
||||||
|
}
|
||||||
|
return combinedList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of BoardElementContainers, containing all tiles and positions of given wall types
|
||||||
|
* @param walls The walls you want all positions for
|
||||||
|
* @return A list of BoardElementContainers
|
||||||
|
*/
|
||||||
|
public List<BoardElementContainer<Wall>> getPositionsOfTileOnBoard(WallType ... walls) {
|
||||||
|
List<BoardElementContainer<Wall>> combinedList = new ArrayList<>();
|
||||||
|
for (WallType wall : walls) {
|
||||||
|
combinedList.addAll(makeTileList(wall, this.walls));
|
||||||
|
}
|
||||||
|
return combinedList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all position of an obj and makes a list of BoardElementContainers
|
||||||
|
* @param type Type of obj
|
||||||
|
* @param grid Grid to search
|
||||||
|
* @param <K> Type of type
|
||||||
|
* @param <T> Type of grid
|
||||||
|
* @return List of BoardElementContainers
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package inf112.fiasko.roborally.objects;
|
||||||
|
|
||||||
|
import inf112.fiasko.roborally.element_properties.Position;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a type of object and its position
|
||||||
|
* @param <K> The type of object
|
||||||
|
*/
|
||||||
|
public class BoardElementContainer <K>{
|
||||||
|
K obj;
|
||||||
|
Position pos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the BoardElementContainer
|
||||||
|
* @param obj The object
|
||||||
|
* @param pos The position
|
||||||
|
*/
|
||||||
|
BoardElementContainer(K obj, Position pos) {
|
||||||
|
this.obj = obj;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the object
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
public K getObject() {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the position
|
||||||
|
* @return position
|
||||||
|
*/
|
||||||
|
public Position getPosition() {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user