Fikser noen feil rapportert av IntelliJ

Gjør privat det som kan gjøres privat
Legger til final der mulig
Endrer kode slik at interfaces blir brukt der mulig
This commit is contained in:
Kristian Knarvik 2020-05-05 15:30:16 +02:00
parent 979703bcf9
commit 3c0806bcdb
8 changed files with 45 additions and 22 deletions

View File

@ -463,7 +463,7 @@ public class Board {
*
* @param robot The robot to re-spawn
*/
public void respawnRobot(Robot robot) {
private void respawnRobot(Robot robot) {
Position backupPosition = robot.getBackupPosition();
int startX = backupPosition.getXCoordinate();
int startY = backupPosition.getYCoordinate();
@ -499,7 +499,7 @@ public class Board {
* @param direction The direction of the face of the square to check
* @return Whether the robot was re-spawned
*/
public boolean tryRobotRespawn(Robot robot, int size, int startX, int startY, Direction direction) {
private boolean tryRobotRespawn(Robot robot, int size, int startX, int startY, Direction direction) {
int axis;
for (int i = 1; i <= size; i++) {
if (direction == Direction.NORTH || direction == Direction.SOUTH) {

View File

@ -102,4 +102,15 @@ public interface InteractableGame {
*/
void setProgram(List<ProgrammingCard> program);
/**
* Starts a turn in the game
*/
void runTurn();
/**
* Gets the power down status of the client playing this instance of the game
*
* @return Whether this player's robot is in power down
*/
boolean getRobotPowerDown();
}

View File

@ -62,10 +62,13 @@ public class Phase {
fireAllLasers();
checkAllFlags();
updateRobotRespawn();
updateRobotBackups();
}
public void updateRobotRespawn() {
/**
* Updates backups for all robots standing on a repair tile
*/
private void updateRobotBackups() {
gameBoard.updateRobotBackups();
}

View File

@ -34,7 +34,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
private List<ProgrammingCard> program;
private ProgrammingCardDeck playerHand;
private ProgrammingCardDeck extraCards;
private Boolean testingMode;
private final Boolean testingMode;
/**
* Instantiates a new Robo Rally game
@ -55,12 +55,8 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
initializeGame(boardName);
}
/**
* Gets the power down status of the client playing this instance of the game
*
* @return Whether this player's robot is in power down
*/
public Boolean getRobotPowerDown() {
@Override
public boolean getRobotPowerDown() {
Player player = getPlayerFromName(this.playerName);
if (player != null) {
return gameBoard.getPowerDown(player.getRobotID());
@ -279,9 +275,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
}
}
/**
* Starts a turn in the game
*/
@Override
public void runTurn() {
// Sets the power down status to true on robots that have players who planned one this turn.
// Resets players power down for next turn to false.

View File

@ -1,6 +1,7 @@
package inf112.fiasko.roborally.ui;
import inf112.fiasko.roborally.networking.RoboRallyServer;
import inf112.fiasko.roborally.objects.InteractableGame;
import inf112.fiasko.roborally.objects.RoboRallyGame;
/**
@ -12,7 +13,7 @@ public interface RoboRallyUI {
*
* @return The game used by the UI
*/
RoboRallyGame getGame();
InteractableGame getGame();
/**
* Sets the robo rally game being rendered by the UI

View File

@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import inf112.fiasko.roborally.networking.RoboRallyClient;
import inf112.fiasko.roborally.networking.RoboRallyServer;
import inf112.fiasko.roborally.objects.InteractableGame;
import inf112.fiasko.roborally.objects.RoboRallyGame;
/**
@ -37,7 +38,7 @@ public class RoboRallyWrapper extends Game implements RoboRallyUI {
}
@Override
public RoboRallyGame getGame() {
public InteractableGame getGame() {
return roboRallyGame;
}

View File

@ -13,6 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
import inf112.fiasko.roborally.objects.InteractableGame;
import inf112.fiasko.roborally.objects.ProgrammingCard;
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
import inf112.fiasko.roborally.objects.properties.GameState;
@ -39,6 +40,7 @@ public class CardChoiceScreen extends InteractiveScreen {
private final List<CardRectangle> chosenCards;
private final int maxCards;
private long timerStarted;
private final InteractableGame game;
/**
* Instantiates a new card choice screen
@ -46,9 +48,10 @@ public class CardChoiceScreen extends InteractiveScreen {
* @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen
*/
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
ProgrammingCardDeck deck = roboRallyWrapper.roboRallyGame.getPlayerHand();
game = roboRallyWrapper.getGame();
ProgrammingCardDeck deck = game.getPlayerHand();
this.roboRallyWrapper = roboRallyWrapper;
maxCards = roboRallyWrapper.roboRallyGame.getProgramSize();
maxCards = game.getProgramSize();
if (maxCards == -1) {
throw new IllegalArgumentException("This player should not be able to choose any cards at this point in " +
"time.");
@ -125,8 +128,8 @@ public class CardChoiceScreen extends InteractiveScreen {
roboRallyWrapper.shouldHurry = false;
List<ProgrammingCard> newProgram = getChosenAndLockedCards();
//Save the program to get locked cards later
roboRallyWrapper.roboRallyGame.setProgram(newProgram);
roboRallyWrapper.roboRallyGame.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS);
game.setProgram(newProgram);
game.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(requestPowerDown, newProgram));
} else {
@ -182,9 +185,9 @@ public class CardChoiceScreen extends InteractiveScreen {
* @return The player's old program
*/
private List<ProgrammingCard> getOldProgram() {
List<ProgrammingCard> oldProgram = roboRallyWrapper.roboRallyGame.getProgram();
List<ProgrammingCard> oldProgram = game.getProgram();
if (oldProgram != null && oldProgram.size() == 0) {
oldProgram = roboRallyWrapper.roboRallyGame.getExtraCards().getCards();
oldProgram = game.getExtraCards().getCards();
int nulls = 5 - oldProgram.size();
for (int i = 0; i < nulls; i++) {
oldProgram.add(0, null);

View File

@ -76,4 +76,14 @@ public class FakeGame implements InteractableGame {
public void setProgram(List<ProgrammingCard> program) {
//Not needed for testing
}
@Override
public void runTurn() {
//Not needed for testing
}
@Override
public boolean getRobotPowerDown() {
return false;
}
}