Fikser kodestil

This commit is contained in:
Kristian Knarvik 2020-03-16 20:06:35 +01:00
parent 49ee7dc896
commit b520178686
7 changed files with 74 additions and 68 deletions

View File

@ -16,8 +16,8 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
private final RoboRallyWrapper roboRallyWrapper;
private final OrthographicCamera camera;
private CardRectangle cardRectangle;
private ShapeRenderer shapeRenderer;
private final CardRectangle cardRectangle;
private final ShapeRenderer shapeRenderer;
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
this.roboRallyWrapper = roboRallyWrapper;
@ -28,7 +28,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
card1.y = 1200/2;
card1.width = 100;
card1.height = 100;
cardRectangle = new CardRectangle(card1, false);
cardRectangle = new CardRectangle(card1);
shapeRenderer = new ShapeRenderer();
shapeRenderer.setAutoShapeType(true);
Gdx.input.setInputProcessor(this);
@ -36,7 +36,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
@Override
public void show() {
//Nothing to do
}
@Override
@ -61,27 +61,27 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
@Override
public void resize(int i, int i1) {
//Nothing to do
}
@Override
public void pause() {
//Nothing to do
}
@Override
public void resume() {
//Nothing to do
}
@Override
public void hide() {
//Nothing to do
}
@Override
public void dispose() {
//Nothing to do
}
@Override
@ -99,11 +99,10 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
}
class CardRectangle {
Rectangle rectangle;
boolean selected;
protected final Rectangle rectangle;
protected boolean selected = false;
CardRectangle(Rectangle rectangle, boolean selected) {
CardRectangle(Rectangle rectangle) {
this.rectangle = rectangle;
this.selected = selected;
}
}

View File

@ -1,6 +1,11 @@
package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.element_properties.*;
import inf112.fiasko.roborally.element_properties.Direction;
import inf112.fiasko.roborally.element_properties.Position;
import inf112.fiasko.roborally.element_properties.RobotID;
import inf112.fiasko.roborally.element_properties.TileType;
import inf112.fiasko.roborally.element_properties.WallType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -166,6 +171,21 @@ public class Board {
deadRobots = new ArrayList<>();
}
/**
* Returns a robot id for a robot on a specific position if such a robot exists
* @param position The position to check
* @return The robot id of the robot on the position or null if there is no robot there
*/
public RobotID getRobotOnPosition(Position position) {
for (RobotID robotID : robots.keySet()) {
Robot robot = robots.get(robotID);
if (position.equals(robot.getPosition())) {
return robotID;
}
}
return null;
}
/**
* Checks if a specific robot is currently alive on the board
* @param robot the ID of the robot you want to check
@ -256,27 +276,12 @@ public class Board {
deadRobots.add(robot);
}
/**
* Returns a robot id for a robot on a specific position if such a robot exists
* @param position The position to check
* @return The robot id of the robot on the position or null if there is no robot there
*/
RobotID getRobotOnPosition(Position position) {
for (RobotID robotID : robots.keySet()) {
Robot robot = robots.get(robotID);
if (position.equals(robot.getPosition())) {
return robotID;
}
}
return null;
}
/**
* Checks whether there exists a robot on a specific position
* @param position The position to check
* @return True if there is a robot on the specified position
*/
boolean hasRobotOnPosition(Position position) {
public boolean hasRobotOnPosition(Position position) {
return getRobotOnPosition(position) != null;
}
@ -362,7 +367,7 @@ public class Board {
* @param walls The walls you want all positions for
* @return A list of BoardElementContainers
*/
public List<BoardElementContainer<Wall>> getPositionsOfWallOnBoard(WallType ... walls) {
public List<BoardElementContainer<Wall>> getPositionsOfWallOnBoard(WallType... walls) {
List<BoardElementContainer<Wall>> combinedList = new ArrayList<>();
for (WallType wall : walls) {
combinedList.addAll(makeTileList(wall, this.walls));

View File

@ -3,36 +3,36 @@ 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
* This class represents a board element and its position
* @param <K> The type of element
*/
public class BoardElementContainer <K>{
K obj;
private Position pos;
public class BoardElementContainer <K> {
private final K element;
private final Position position;
/**
* Initializes the BoardElementContainer
* @param obj The object
* @param pos The position
* @param element The element
* @param position The position
*/
BoardElementContainer(K obj, Position pos) {
this.obj = obj;
this.pos = pos;
BoardElementContainer(K element, Position position) {
this.element = element;
this.position = position;
}
/**
* Gets the object
* @return object
* Gets the element
* @return The element
*/
public K getObject() {
return obj;
public K getElement() {
return element;
}
/**
* Gets the position
* @return position
* @return The position
*/
public Position getPosition() {
return pos;
return position;
}
}

View File

@ -211,7 +211,7 @@ public class RoboRallyGame implements IDrawableGame {
continue;
}
sleep();
if (cogwheel.obj.getTileType() == TileType.COGWHEEL_RIGHT) {
if (cogwheel.getElement().getTileType() == TileType.COGWHEEL_RIGHT) {
gameBoard.rotateRobotRight(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
} else {
gameBoard.rotateRobotLeft(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
@ -258,7 +258,7 @@ public class RoboRallyGame implements IDrawableGame {
continue;
}
Position conveyorBeltPosition = conveyorBelt.getPosition();
Tile conveyorBeltTile = conveyorBelt.getObject();
Tile conveyorBeltTile = conveyorBelt.getElement();
Position newPosition = gameBoard.getNewPosition(conveyorBeltPosition, conveyorBeltTile.getDirection());
Tile nextTile = gameBoard.getTileOnPosition(newPosition);
@ -283,7 +283,7 @@ public class RoboRallyGame implements IDrawableGame {
Direction nextDirection = nextTile.getDirection();
sleep();
gameBoard.moveRobot(robot, currentDirection);
if (testPredicate(conveyorBelts, (container) -> container.getObject() == nextTile)) {
if (testPredicate(conveyorBelts, (container) -> container.getElement() == nextTile)) {
if (Direction.getRightRotatedDirection(nextDirection) == currentDirection) {
sleep();
gameBoard.rotateRobotLeft(robot);
@ -304,7 +304,7 @@ public class RoboRallyGame implements IDrawableGame {
Position flagPosition = flag.getPosition();
if (gameBoard.hasRobotOnPosition(flagPosition)) {
RobotID robot = gameBoard.getRobotOnPosition(flagPosition);
gameBoard.updateFlagOnRobot(robot, flag.getObject().getTileType());
gameBoard.updateFlagOnRobot(robot, flag.getElement().getTileType());
}
}
}

View File

@ -14,7 +14,7 @@ public class BoardElementContainerTest {
Position pos = new Position(1,2);
Tile tile = new Tile(TileType.TILE, Direction.NORTH);
BoardElementContainer<Tile> element = new BoardElementContainer<>(tile, pos);
assertEquals(tile, element.getObject());
assertEquals(tile, element.getElement());
}
@Test

View File

@ -35,8 +35,8 @@ public class BoardTest {
private List<Robot> robotList;
private Board board;
private Board boardWithDifferentAmountOfAllTypes;
private Map<WallType,Integer> wallTypeNumberMap = new HashMap<>();
private Map<TileType,Integer> tileTypeNumberMap = new HashMap<>();
private final Map<WallType,Integer> wallTypeNumberMap = new HashMap<>();
private final Map<TileType,Integer> tileTypeNumberMap = new HashMap<>();
@BeforeClass
public static void globalSetUp() {
@ -223,7 +223,7 @@ public class BoardTest {
List<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT);
for (BoardElementContainer<Tile> elem : boardElemList) {
assertEquals(elem.getObject().getTileType(), TileType.COGWHEEL_LEFT);
assertEquals(elem.getElement().getTileType(), TileType.COGWHEEL_LEFT);
}
}
@ -238,7 +238,7 @@ public class BoardTest {
List<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE);
for (BoardElementContainer<Tile> elem : boardElemList) {
assertEquals(elem.getObject().getTileType(), TileType.TILE);
assertEquals(elem.getElement().getTileType(), TileType.TILE);
}
}
@ -253,7 +253,7 @@ public class BoardTest {
List<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL);
for (BoardElementContainer<Wall> elem : boardElemList) {
assertEquals(elem.getObject().getWallType(), WallType.WALL_NORMAL);
assertEquals(elem.getElement().getWallType(), WallType.WALL_NORMAL);
}
}
@ -268,14 +268,14 @@ public class BoardTest {
List<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER);
for (BoardElementContainer<Wall> elem : boardElemList) {
assertEquals(elem.getObject().getWallType(), WallType.WALL_CORNER);
assertEquals(elem.getElement().getWallType(), WallType.WALL_CORNER);
}
}
@Test
public void getPositionsOfWallOnBoardHasCorrect() {
List<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER);
Predicate<BoardElementContainer<Wall>> pred = (element) -> element.getObject().getWallType() == WallType.WALL_CORNER;
Predicate<BoardElementContainer<Wall>> pred = (element) -> element.getElement().getWallType() == WallType.WALL_CORNER;
boardElemList.removeIf(pred);
assertEquals(0, boardElemList.size());
}

View File

@ -8,12 +8,14 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class PlayerTest {
private Player playerTest;
private List<ProgrammingCard> cards = new ArrayList();
private final List<ProgrammingCard> cards = new ArrayList<>();
@Before
public void setUp() {
@ -22,7 +24,6 @@ public class PlayerTest {
cards.add(new ProgrammingCard(30, Action.MOVE_3));
cards.add(new ProgrammingCard(40, Action.BACK_UP));
cards.add(new ProgrammingCard(50, Action.ROTATE_LEFT));
ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards);
playerTest = new Player(RobotID.ROBOT_1, "TestPlayer" );
}
@ -37,8 +38,9 @@ public class PlayerTest {
playerTest.setPowerDownNextRound(false);
assertFalse(playerTest.getPowerDownNextRound());
}
@Test
public void testSetInProgram(){
public void testSetInProgram() {
playerTest.setInProgram(cards);
assertEquals(Action.MOVE_1, playerTest.getProgramFromPlayer().get(0).getAction());
assertEquals(Action.MOVE_2, playerTest.getProgramFromPlayer().get(1).getAction());
@ -47,13 +49,13 @@ public class PlayerTest {
}
@Test (expected = IllegalArgumentException.class)
public void testSetInProgramWithToManyCards(){
public void testSetInProgramWithToManyCards() {
cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT));
playerTest.setInProgram(cards);
}
@Test
public void testSetInDeck(){
public void testSetInDeck() {
cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT));
ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards);
playerTest.setPlayerDeck(playerDeck);
@ -61,17 +63,17 @@ public class PlayerTest {
}
@Test
public void GetPlayerRobotId(){
public void getPlayerRobotId() {
assertEquals(RobotID.ROBOT_1, playerTest.getRobotID());
}
@Test
public void GetPlayerName(){
public void getPlayerName() {
assertEquals("TestPlayer", playerTest.getName());
}
@Test
public void GetProgramFromPlayer(){
public void getProgramFromPlayer() {
playerTest.setInProgram(cards);
assertEquals(cards,playerTest.getProgram());
}