From 6e3f95e5a61a1a7ff104a8a51f6a271199debc36 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 22 Apr 2020 12:45:22 +0200 Subject: [PATCH] =?UTF-8?q?Gj=C3=B8r=20det=20mulig=20=C3=A5=20finne=20rett?= =?UTF-8?q?=20tekstur=20gitt=20en=20robot=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utility/TextureConverterUtil.java | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java b/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java index 9eb1b78..0732e60 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java @@ -135,24 +135,36 @@ public final class TextureConverterUtil { * @return The texture to draw */ public static TextureRegion convertElement(Robot robot) { - if (robot.getRobotId() == RobotID.ROBOT_1) { - return new TextureRegion(robotsTexture, 0, 0, 64, 64); - } else if (robot.getRobotId() == RobotID.ROBOT_2) { - return new TextureRegion(robotsTexture, 64, 0, 64, 64); - } else if (robot.getRobotId() == RobotID.ROBOT_3) { - return new TextureRegion(robotsTexture, 2 * 64, 0, 64, 64); - } else if (robot.getRobotId() == RobotID.ROBOT_4) { - return new TextureRegion(robotsTexture, 3 * 64, 0, 64, 64); - } else if (robot.getRobotId() == RobotID.ROBOT_5) { - return new TextureRegion(robotsTexture, 4 * 64, 0, 64, 64); - } else if (robot.getRobotId() == RobotID.ROBOT_6) { - return new TextureRegion(robotsTexture, 5 * 64, 0, 64, 64); - } else if (robot.getRobotId() == RobotID.ROBOT_7) { - return new TextureRegion(robotsTexture, 6 * 64, 0, 64, 64); - } else if (robot.getRobotId() == RobotID.ROBOT_8) { - return new TextureRegion(robotsTexture, 7 * 64, 0, 64, 64); + return convertElement(robot.getRobotId()); + } + + /** + * Gets the texture representing the robot id + * + * @param robotID The id of the robot to draw + * @return The texture to draw + */ + public static TextureRegion convertElement(RobotID robotID) { + switch (robotID) { + case ROBOT_1: + return new TextureRegion(robotsTexture, 0, 0, 64, 64); + case ROBOT_2: + return new TextureRegion(robotsTexture, 64, 0, 64, 64); + case ROBOT_3: + return new TextureRegion(robotsTexture, 2 * 64, 0, 64, 64); + case ROBOT_4: + return new TextureRegion(robotsTexture, 3 * 64, 0, 64, 64); + case ROBOT_5: + return new TextureRegion(robotsTexture, 4 * 64, 0, 64, 64); + case ROBOT_6: + return new TextureRegion(robotsTexture, 5 * 64, 0, 64, 64); + case ROBOT_7: + return new TextureRegion(robotsTexture, 6 * 64, 0, 64, 64); + case ROBOT_8: + return new TextureRegion(robotsTexture, 7 * 64, 0, 64, 64); + default: + throw new IllegalArgumentException("Robot has no drawable texture."); } - throw new IllegalArgumentException("Robot has no drawable texture."); } /**