Gjør den del nødvendige forandringer for å kunne tegne det nye brettet

Oppdaterer IDrawableObject og IDrawableGame og implementerende klasser
Legger til en utility klasse for input og output
Legger til manglende metoder i TextureConverterUtil
Oppdaterer noen tester med nye datatyper
This commit is contained in:
2020-02-24 18:07:26 +01:00
parent 354542414a
commit f731ebe5cf
12 changed files with 311 additions and 73 deletions

View File

@ -81,6 +81,22 @@ public class Board {
return new ArrayList<>(robots.values());
}
/**
* Gets all the tiles from the board
* @return A list of all tiles on the board
*/
public List<Tile> getTiles() {
return getAllElementsFromGrid(tiles);
}
/**
* Gets all the walls from the board
* @return A list of all the walls on the board
*/
public List<Wall> getWalls() {
return getAllElementsFromGrid(walls);
}
/**
* Removes a dead robot from the board over to the dead robot list
* @param robot the dead robot
@ -265,4 +281,20 @@ public class Board {
throw new IllegalArgumentException("It's not possible to move in that direction.");
}
}
/**
* Gets all elements on a grid
* @param grid The grid to get elements from
* @param <K> The type of the elements int the grid
* @return A list containing all the elements in the grid
*/
private <K> List<K> getAllElementsFromGrid(IGrid<K> grid) {
List<K> elements = new ArrayList<>();
for (int x = grid.getWidth() - 1; x >= 0; x--) {
for (int y = 0; y < grid.getHeight(); y++) {
elements.add(grid.getElement(x, y));
}
}
return elements;
}
}

View File

@ -1,12 +1,12 @@
package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.element_properties.GameTexture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
/**
* This class represents an object that can be drawn using libgdx
*/
public class DrawableObject implements IDrawableObject {
private final GameTexture texture;
private final TextureRegion texture;
private final int xPos;
private final int yPos;
private int width = 64;
@ -26,7 +26,7 @@ public class DrawableObject implements IDrawableObject {
* @param flipX Whether to flip/mirror the element over the x axis
* @param flipY Whether to flip/mirror the element over the y axis
*/
public DrawableObject(GameTexture texture, int xPos, int yPos, int width, int height, int rotation, boolean flipX,
public DrawableObject(TextureRegion texture, int xPos, int yPos, int width, int height, int rotation, boolean flipX,
boolean flipY) {
this.xPos = xPos;
this.yPos = yPos;
@ -38,20 +38,38 @@ public class DrawableObject implements IDrawableObject {
this.flipY = flipY;
}
/**
* Initializes a drawable object
* @param texture The texture to use for drawing the element
* @param xPos The pixel to start drawing on for the x axis
* @param yPos The pixel to start drawing on for the y axis
* @param width The width of the element
* @param height The height of the element
* @param rotation The amount of degrees to rotate the element counterclockwise
*/
public DrawableObject(TextureRegion texture, int xPos, int yPos, int width, int height, int rotation) {
this.xPos = xPos;
this.yPos = yPos;
this.rotation = rotation;
this.texture = texture;
this.width = width;
this.height = height;
}
/**
* Initializes a new drawable object
* @param texture The texture to use for drawing the element
* @param xPos The pixel to start drawing on for the x axis
* @param yPos The pixel to start drawing on for the y axis
*/
public DrawableObject(GameTexture texture, int xPos, int yPos) {
public DrawableObject(TextureRegion texture, int xPos, int yPos) {
this.xPos = xPos;
this.yPos = yPos;
this.texture = texture;
}
@Override
public GameTexture getTexture() {
public TextureRegion getTexture() {
return texture;
}

View File

@ -77,7 +77,7 @@ public class Grid<K> implements IGrid<K> {
*/
private void makeSureCoordinatesAreWithinBounds(int x, int y) {
if (x < 0 || x >= width || y < 0 || y >= height) {
throw new IllegalArgumentException();
throw new IllegalArgumentException("Coordinates are outside the bounds of the board.");
}
}
}

View File

@ -1,6 +1,6 @@
package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.element_properties.GameTexture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
/**
* This interface describes an object drawable using libgdx
@ -11,7 +11,7 @@ public interface IDrawableObject {
* Gets the texture to use for drawing the object
* @return The texture of the object
*/
GameTexture getTexture();
TextureRegion getTexture();
/**
* Gets the x position the object should be drawn on