mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 15:19:35 +01:00
Omstrukturerer litt mens det fortsatt er enkelt
Forbedrer tester Bytter navn på noen metoder og variabler Bytter noen tall til relevante konstanter Stokker om på rekkefølgen i konstruksjonsmetodene til DrawableObject
This commit is contained in:
parent
e4784246bf
commit
4eb5b42755
@ -27,17 +27,16 @@ public class Game implements IDrawableGame {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IDrawableObject> objectsToRender() {
|
||||
public List<IDrawableObject> getObjectsToDraw() {
|
||||
List<IDrawableObject> list = new ArrayList<>();
|
||||
for (int i = 0; i < 12; i++) {
|
||||
for (int j = 0; j < 12; j++) {
|
||||
DrawableObject tileObj = new DrawableObject(i * 64, j * 64, GameTexture.TILE);
|
||||
list.add(tileObj);
|
||||
for (int i = 0; i < TILE_NUMBER; i++) {
|
||||
for (int j = 0; j < TILE_NUMBER; j++) {
|
||||
DrawableObject tile = new DrawableObject(GameTexture.TILE, i * TILE_SIZE, j * TILE_SIZE);
|
||||
list.add(tile);
|
||||
}
|
||||
}
|
||||
DrawableObject roboObj = new DrawableObject(128,128, GameTexture.ROBOT);
|
||||
list.add(roboObj);
|
||||
|
||||
DrawableObject robot = new DrawableObject(GameTexture.ROBOT, TILE_SIZE, TILE_SIZE);
|
||||
list.add(robot);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ public interface IDrawableGame {
|
||||
int getHeight();
|
||||
|
||||
/**
|
||||
* Gets a list of objects which are to be rendered
|
||||
* Gets a list of objects which are to be drawn
|
||||
* @return A list of drawable objects in the order they are to be drawn
|
||||
*/
|
||||
List<IDrawableObject> objectsToRender();
|
||||
List<IDrawableObject> getObjectsToDraw();
|
||||
|
||||
}
|
||||
|
@ -6,27 +6,28 @@ import inf112.fiasko.roborally.abstractions.GameTexture;
|
||||
* This class represents an object that can be drawn using libgdx
|
||||
*/
|
||||
public class DrawableObject implements IDrawableObject {
|
||||
private GameTexture texture;
|
||||
private int xPos;
|
||||
private int yPos;
|
||||
private int width = 64;
|
||||
private int height = 64;
|
||||
private int rotation = 0;
|
||||
private GameTexture texture;
|
||||
private boolean flipX = false;
|
||||
private boolean flipY = false;
|
||||
|
||||
/**
|
||||
* 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 texture The texture to use for drawing the element
|
||||
* @param rotation The amount of degrees to rotate the element counterclockwise
|
||||
* @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
|
||||
* @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(int xPos, int yPos, GameTexture texture, int rotation, int width, int height, boolean flipX, boolean flipY) {
|
||||
public DrawableObject(GameTexture texture, int xPos, int yPos, int width, int height, int rotation, boolean flipX,
|
||||
boolean flipY) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.rotation = rotation;
|
||||
@ -39,11 +40,11 @@ public class DrawableObject implements IDrawableObject {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param texture The texture to use for drawing the element
|
||||
*/
|
||||
public DrawableObject(int xPos, int yPos, GameTexture texture) {
|
||||
public DrawableObject(GameTexture texture, int xPos, int yPos) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.texture = texture;
|
||||
|
@ -8,98 +8,109 @@ import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DrawableObjectTest {
|
||||
|
||||
private DrawableObject testMinArg;
|
||||
private DrawableObject testMaxArg;
|
||||
public static final GameTexture TEXTURE_MIN_ARG = GameTexture.TILE;
|
||||
public static final GameTexture TEXTURE_MAX_ARG = GameTexture.ROBOT;
|
||||
public static final int X_POSITION_MIN_ARG = 5;
|
||||
public static final int Y_POSITION_MIN_ARG = 8;
|
||||
public static final int X_POSITION_MAX_ARG = 6;
|
||||
public static final int Y_POSITION_MAX_ARG = 7;
|
||||
private final int WIDTH_MAX_ARG = 50;
|
||||
private final int HEIGHT_MAX_ARG = 60;
|
||||
private final int ROTATION_MAX_ARG = 90;
|
||||
private final boolean FLIP_X_MAX_ARG = true;
|
||||
private final boolean FLIP_Y_MAX_ARG = true;
|
||||
private DrawableObject drawableObjectMinimumArguments;
|
||||
private DrawableObject drawableObjectMaximumArguments;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
testMinArg = new DrawableObject(5,5, GameTexture.SLOW_TRANSPORT_BAND);
|
||||
testMaxArg = new DrawableObject(6, 6, GameTexture.ROBOT, 90, 50, 50, true, true);
|
||||
drawableObjectMinimumArguments = new DrawableObject(TEXTURE_MIN_ARG, X_POSITION_MIN_ARG, Y_POSITION_MIN_ARG);
|
||||
drawableObjectMaximumArguments = new DrawableObject(TEXTURE_MAX_ARG, X_POSITION_MAX_ARG, Y_POSITION_MAX_ARG,
|
||||
WIDTH_MAX_ARG, HEIGHT_MAX_ARG, ROTATION_MAX_ARG, FLIP_X_MAX_ARG, FLIP_Y_MAX_ARG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTextureMinArg() {
|
||||
assertSame(GameTexture.SLOW_TRANSPORT_BAND, testMinArg.getTexture());
|
||||
assertSame(TEXTURE_MIN_ARG, drawableObjectMinimumArguments.getTexture());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTextureMaxArg() {
|
||||
assertSame(GameTexture.ROBOT, testMaxArg.getTexture());
|
||||
assertSame(TEXTURE_MAX_ARG, drawableObjectMaximumArguments.getTexture());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getXPositionMinArg() {
|
||||
assertEquals(5, testMinArg.getXPosition());
|
||||
assertEquals(X_POSITION_MIN_ARG, drawableObjectMinimumArguments.getXPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getXPositionMaxArg() {
|
||||
assertEquals(6, testMaxArg.getXPosition());
|
||||
assertEquals(X_POSITION_MAX_ARG, drawableObjectMaximumArguments.getXPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getYPositionMinArg() {
|
||||
assertEquals(5, testMinArg.getYPosition());
|
||||
assertEquals(Y_POSITION_MIN_ARG, drawableObjectMinimumArguments.getYPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getYPositionMaxArg() {
|
||||
assertEquals(6, testMaxArg.getYPosition());
|
||||
assertEquals(Y_POSITION_MAX_ARG, drawableObjectMaximumArguments.getYPosition());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getWidthMinArg() {
|
||||
assertEquals(64, testMinArg.getWidth());
|
||||
assertEquals(64, drawableObjectMinimumArguments.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWidthMaxArg() {
|
||||
assertEquals(50, testMaxArg.getWidth());
|
||||
assertEquals(WIDTH_MAX_ARG, drawableObjectMaximumArguments.getWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHeightMinArg() {
|
||||
assertEquals(64, testMinArg.getHeight());
|
||||
assertEquals(64, drawableObjectMinimumArguments.getHeight());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHeightMaxArg() {
|
||||
assertEquals(50, testMaxArg.getHeight());
|
||||
assertEquals(HEIGHT_MAX_ARG, drawableObjectMaximumArguments.getHeight());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getRotationMinArg() {
|
||||
assertEquals(0, testMinArg.getRotation());
|
||||
assertEquals(0, drawableObjectMinimumArguments.getRotation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRotationMaxArg() {
|
||||
assertEquals(90, testMaxArg.getRotation());
|
||||
assertEquals(ROTATION_MAX_ARG, drawableObjectMaximumArguments.getRotation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flipXMinArg() {
|
||||
assertFalse(testMinArg.flipX());
|
||||
assertFalse(drawableObjectMinimumArguments.flipX());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flipXMaxArg() {
|
||||
assertTrue(testMaxArg.flipX());
|
||||
assertEquals(FLIP_X_MAX_ARG, drawableObjectMaximumArguments.flipX());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flipYMinArg() {
|
||||
assertFalse(testMinArg.flipY());
|
||||
assertFalse(drawableObjectMinimumArguments.flipY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flipYMaxArg() {
|
||||
assertTrue(testMaxArg.flipY());
|
||||
assertEquals(FLIP_Y_MAX_ARG, drawableObjectMaximumArguments.flipY());
|
||||
}
|
||||
}
|
@ -17,27 +17,27 @@ public class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gameWidthPositiveTest() {
|
||||
public void gameWidthIsPositive() {
|
||||
assertTrue(game.getWidth() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gameWidthMaximumFullHDTest() {
|
||||
public void gameWidthIsMaximumFullHD() {
|
||||
assertTrue(game.getWidth() <= 1920);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gameHeightPositiveTest() {
|
||||
public void gameHeightIsPositive() {
|
||||
assertTrue(game.getWidth() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gameHeightMaximumFullHDTest() {
|
||||
public void gameHeightIsMaximumFullHD() {
|
||||
assertTrue(game.getWidth() <= 1080);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getObjectsToRenderTest() {
|
||||
assertFalse(game.objectsToRender().isEmpty());
|
||||
public void getObjectsToDrawReturnsNonemptyList() {
|
||||
assertFalse(game.getObjectsToDraw().isEmpty());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user