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:
Kristian Knarvik 2020-02-05 05:14:35 +01:00
parent e4784246bf
commit 4eb5b42755
5 changed files with 54 additions and 43 deletions

View File

@ -27,17 +27,16 @@ public class Game implements IDrawableGame {
} }
@Override @Override
public List<IDrawableObject> objectsToRender() { public List<IDrawableObject> getObjectsToDraw() {
List<IDrawableObject> list = new ArrayList<>(); List<IDrawableObject> list = new ArrayList<>();
for (int i = 0; i < 12; i++) { for (int i = 0; i < TILE_NUMBER; i++) {
for (int j = 0; j < 12; j++) { for (int j = 0; j < TILE_NUMBER; j++) {
DrawableObject tileObj = new DrawableObject(i * 64, j * 64, GameTexture.TILE); DrawableObject tile = new DrawableObject(GameTexture.TILE, i * TILE_SIZE, j * TILE_SIZE);
list.add(tileObj); list.add(tile);
} }
} }
DrawableObject roboObj = new DrawableObject(128,128, GameTexture.ROBOT); DrawableObject robot = new DrawableObject(GameTexture.ROBOT, TILE_SIZE, TILE_SIZE);
list.add(roboObj); list.add(robot);
return list; return list;
} }
} }

View File

@ -22,9 +22,9 @@ public interface IDrawableGame {
int getHeight(); 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 * @return A list of drawable objects in the order they are to be drawn
*/ */
List<IDrawableObject> objectsToRender(); List<IDrawableObject> getObjectsToDraw();
} }

View File

@ -6,27 +6,28 @@ import inf112.fiasko.roborally.abstractions.GameTexture;
* This class represents an object that can be drawn using libgdx * This class represents an object that can be drawn using libgdx
*/ */
public class DrawableObject implements IDrawableObject { public class DrawableObject implements IDrawableObject {
private GameTexture texture;
private int xPos; private int xPos;
private int yPos; private int yPos;
private int width = 64; private int width = 64;
private int height = 64; private int height = 64;
private int rotation = 0; private int rotation = 0;
private GameTexture texture;
private boolean flipX = false; private boolean flipX = false;
private boolean flipY = false; private boolean flipY = false;
/** /**
* Initializes a drawable object * 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 xPos The pixel to start drawing on for the x axis
* @param yPos The pixel to start drawing on for the y 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 width The width of the element
* @param height The height 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 flipX Whether to flip/mirror the element over the x axis
* @param flipY Whether to flip/mirror the element over the y 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.xPos = xPos;
this.yPos = yPos; this.yPos = yPos;
this.rotation = rotation; this.rotation = rotation;
@ -39,11 +40,11 @@ public class DrawableObject implements IDrawableObject {
/** /**
* Initializes a new drawable object * 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 xPos The pixel to start drawing on for the x axis
* @param yPos The pixel to start drawing on for the y 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.xPos = xPos;
this.yPos = yPos; this.yPos = yPos;
this.texture = texture; this.texture = texture;

View File

@ -8,98 +8,109 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class DrawableObjectTest { public class DrawableObjectTest {
private DrawableObject testMinArg; public static final GameTexture TEXTURE_MIN_ARG = GameTexture.TILE;
private DrawableObject testMaxArg; 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 @Before
public void setUp() { public void setUp() {
testMinArg = new DrawableObject(5,5, GameTexture.SLOW_TRANSPORT_BAND); drawableObjectMinimumArguments = new DrawableObject(TEXTURE_MIN_ARG, X_POSITION_MIN_ARG, Y_POSITION_MIN_ARG);
testMaxArg = new DrawableObject(6, 6, GameTexture.ROBOT, 90, 50, 50, true, true); 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 @Test
public void getTextureMinArg() { public void getTextureMinArg() {
assertSame(GameTexture.SLOW_TRANSPORT_BAND, testMinArg.getTexture()); assertSame(TEXTURE_MIN_ARG, drawableObjectMinimumArguments.getTexture());
} }
@Test @Test
public void getTextureMaxArg() { public void getTextureMaxArg() {
assertSame(GameTexture.ROBOT, testMaxArg.getTexture()); assertSame(TEXTURE_MAX_ARG, drawableObjectMaximumArguments.getTexture());
} }
@Test @Test
public void getXPositionMinArg() { public void getXPositionMinArg() {
assertEquals(5, testMinArg.getXPosition()); assertEquals(X_POSITION_MIN_ARG, drawableObjectMinimumArguments.getXPosition());
} }
@Test @Test
public void getXPositionMaxArg() { public void getXPositionMaxArg() {
assertEquals(6, testMaxArg.getXPosition()); assertEquals(X_POSITION_MAX_ARG, drawableObjectMaximumArguments.getXPosition());
} }
@Test @Test
public void getYPositionMinArg() { public void getYPositionMinArg() {
assertEquals(5, testMinArg.getYPosition()); assertEquals(Y_POSITION_MIN_ARG, drawableObjectMinimumArguments.getYPosition());
} }
@Test @Test
public void getYPositionMaxArg() { public void getYPositionMaxArg() {
assertEquals(6, testMaxArg.getYPosition()); assertEquals(Y_POSITION_MAX_ARG, drawableObjectMaximumArguments.getYPosition());
} }
@Test @Test
public void getWidthMinArg() { public void getWidthMinArg() {
assertEquals(64, testMinArg.getWidth()); assertEquals(64, drawableObjectMinimumArguments.getWidth());
} }
@Test @Test
public void getWidthMaxArg() { public void getWidthMaxArg() {
assertEquals(50, testMaxArg.getWidth()); assertEquals(WIDTH_MAX_ARG, drawableObjectMaximumArguments.getWidth());
} }
@Test @Test
public void getHeightMinArg() { public void getHeightMinArg() {
assertEquals(64, testMinArg.getHeight()); assertEquals(64, drawableObjectMinimumArguments.getHeight());
} }
@Test @Test
public void getHeightMaxArg() { public void getHeightMaxArg() {
assertEquals(50, testMaxArg.getHeight()); assertEquals(HEIGHT_MAX_ARG, drawableObjectMaximumArguments.getHeight());
} }
@Test @Test
public void getRotationMinArg() { public void getRotationMinArg() {
assertEquals(0, testMinArg.getRotation()); assertEquals(0, drawableObjectMinimumArguments.getRotation());
} }
@Test @Test
public void getRotationMaxArg() { public void getRotationMaxArg() {
assertEquals(90, testMaxArg.getRotation()); assertEquals(ROTATION_MAX_ARG, drawableObjectMaximumArguments.getRotation());
} }
@Test @Test
public void flipXMinArg() { public void flipXMinArg() {
assertFalse(testMinArg.flipX()); assertFalse(drawableObjectMinimumArguments.flipX());
} }
@Test @Test
public void flipXMaxArg() { public void flipXMaxArg() {
assertTrue(testMaxArg.flipX()); assertEquals(FLIP_X_MAX_ARG, drawableObjectMaximumArguments.flipX());
} }
@Test @Test
public void flipYMinArg() { public void flipYMinArg() {
assertFalse(testMinArg.flipY()); assertFalse(drawableObjectMinimumArguments.flipY());
} }
@Test @Test
public void flipYMaxArg() { public void flipYMaxArg() {
assertTrue(testMaxArg.flipY()); assertEquals(FLIP_Y_MAX_ARG, drawableObjectMaximumArguments.flipY());
} }
} }

View File

@ -17,27 +17,27 @@ public class GameTest {
} }
@Test @Test
public void gameWidthPositiveTest() { public void gameWidthIsPositive() {
assertTrue(game.getWidth() > 0); assertTrue(game.getWidth() > 0);
} }
@Test @Test
public void gameWidthMaximumFullHDTest() { public void gameWidthIsMaximumFullHD() {
assertTrue(game.getWidth() <= 1920); assertTrue(game.getWidth() <= 1920);
} }
@Test @Test
public void gameHeightPositiveTest() { public void gameHeightIsPositive() {
assertTrue(game.getWidth() > 0); assertTrue(game.getWidth() > 0);
} }
@Test @Test
public void gameHeightMaximumFullHDTest() { public void gameHeightIsMaximumFullHD() {
assertTrue(game.getWidth() <= 1080); assertTrue(game.getWidth() <= 1080);
} }
@Test @Test
public void getObjectsToRenderTest() { public void getObjectsToDrawReturnsNonemptyList() {
assertFalse(game.objectsToRender().isEmpty()); assertFalse(game.getObjectsToDraw().isEmpty());
} }
} }