Fikser kodestil

This commit is contained in:
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());
}
}
}