This commit is contained in:
Tobydrama 2020-03-12 11:24:25 +01:00
commit a2f861077b
4 changed files with 122 additions and 8 deletions

19
pom.xml
View File

@ -20,6 +20,13 @@
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
</properties> </properties>
<repositories>
<repository>
<id>clojars</id>
<url>http://clojars.org/repo/</url>
</repository>
</repositories>
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx --> <!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx -->
<dependency> <dependency>
@ -53,6 +60,18 @@
<classifier>natives-desktop</classifier> <classifier>natives-desktop</classifier>
</dependency> </dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>5.0.0-RC5</version>
</dependency>
<dependency>
<groupId>kryonet</groupId>
<artifactId>kryonet</artifactId>
<version>2.21</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -141,14 +141,14 @@ public class RoboRallyGame implements IDrawableGame {
sleep(); sleep();
switch (action) { switch (action) {
case MOVE_1: case MOVE_1:
moveForward(robotID); gameBoard.moveRobotForward(robotID);
break; break;
case MOVE_2: case MOVE_2:
moveForward(robotID); gameBoard.moveRobotForward(robotID);
moveForward(robotID); moveForward(robotID);
break; break;
case MOVE_3: case MOVE_3:
moveForward(robotID); gameBoard.moveRobotForward(robotID);
moveForward(robotID); moveForward(robotID);
moveForward(robotID); moveForward(robotID);
break; break;