Skip to content

Commit

Permalink
Solved checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
juturbo committed Jul 8, 2024
1 parent ef89040 commit 544eb0e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/it/unibo/bombardero/core/KeyboardInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class KeyboardInput implements KeyListener {
private final Controller controller;

// The index of the player
private int playerIndex;
private final int playerIndex;

// Directions for checks
private boolean up;
Expand Down
11 changes: 5 additions & 6 deletions src/test/java/it/bombardero/ControllerForTesting.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.bombardero;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -15,8 +16,6 @@
import it.unibo.bombardero.view.BombarderoViewMessages;
import it.unibo.bombardero.view.api.GraphicsEngine.EndGameState;

import java.util.Arrays;

/**
* A simulation of an implementation of the {@link #Controller} interface
* for testing purposes only.
Expand Down Expand Up @@ -47,20 +46,20 @@ public void endGuide() {
throw new UnsupportedOperationException("Unimplemented method 'endGuide'");
}

@Override
public void displayEndScreen(EndGameState endGameState) {
@Override
public void displayEndScreen(final EndGameState endGameState) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'displayEndScreen'");
}

@Override
public void updateGame(long elapsed) {
public void updateGame(final long elapsed) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'updateGame'");
}

@Override
public void updateGraphics(long elapsed) {
public void updateGraphics(final long elapsed) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'updateGraphics'");
}
Expand Down
29 changes: 17 additions & 12 deletions src/test/java/it/bombardero/TestPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
/**
* Unit tests for the {@link Player} class.
* <p>
* This class contains tests to verify the behavior of the Player character, including
* direction facing and movement mechanics.
* This class contains tests to verify the behavior of the Player character,
* including direction facing and movement mechanics.
* </p>
*/
class TestPlayer {
Expand All @@ -40,7 +40,7 @@ class TestPlayer {
void setUp() {
this.manager = new MyGameManager();
this.playerIndex = 0;
this.spawnCoord = new GenPair<>(STARTING_COORD, STARTING_COORD);
this.spawnCoord = new GenPair<>(STARTING_COORD, STARTING_COORD);
this.expectedCoord = new GenPair<>(STARTING_COORD, STARTING_COORD);
this.manager.getPlayers().get(playerIndex).setCharacterPosition(spawnCoord);
}
Expand Down Expand Up @@ -72,26 +72,30 @@ void testPlayerMovingDirections() {

// Setting the number of update and calling them
final int updateNumeber = FPS; // Number of updates done
IntStream.range(0, updateNumeber).forEach(n -> this.manager.getPlayers().get(playerIndex).update(manager, STANDARD_ELAPSED_TIME));
IntStream.range(0, updateNumeber)
.forEach(n -> this.manager.getPlayers().get(playerIndex).update(manager, STANDARD_ELAPSED_TIME));

roundPlayerCoordinateToThreeDecimal();
// Sums the spawn coordinates with the movement done
expectedCoord = expectedCoord.apply(Functions.sumFloat(calculateExpectedDeltaMovement(updateNumeber)));

assertEquals(expectedCoord, manager.getPlayers().get(playerIndex).getCharacterPosition());
}
}

/**
* Calculates the expected delta movement of the player based on the number of updates.
* Calculates the expected delta movement of the player based on the number of
* updates.
*
* @param updateNumeber the number of updates
* @return the expected delta movement as a {@link GenPair<Float, Float>}
*/
private GenPair<Float, Float> calculateExpectedDeltaMovement(final int updateNumeber) {
return new GenPair<Float, Float>(
this.manager.getPlayers().get(playerIndex).getSpeed() * this.manager.getPlayers().get(playerIndex).getFacingDirection().x()
this.manager.getPlayers().get(playerIndex).getSpeed()
* this.manager.getPlayers().get(playerIndex).getFacingDirection().x()
* updateNumeber,
this.manager.getPlayers().get(playerIndex).getSpeed() * this.manager.getPlayers().get(playerIndex).getFacingDirection().y()
this.manager.getPlayers().get(playerIndex).getSpeed()
* this.manager.getPlayers().get(playerIndex).getFacingDirection().y()
* updateNumeber);
}

Expand All @@ -100,9 +104,10 @@ private GenPair<Float, Float> calculateExpectedDeltaMovement(final int updateNum
*/
private void roundPlayerCoordinateToThreeDecimal() {
this.manager.getPlayers().get(playerIndex).setCharacterPosition(
new GenPair<Float, Float>(
Math.round(this.manager.getPlayers().get(playerIndex).getCharacterPosition().x() * 1000.0f) / 1000.0f,
Math.round(this.manager.getPlayers().get(playerIndex).getCharacterPosition().y() * 1000.0f) / 1000.0f
));
new GenPair<Float, Float>(
Math.round(this.manager.getPlayers().get(playerIndex).getCharacterPosition().x() * 1000.0f)
/ 1000.0f,
Math.round(this.manager.getPlayers().get(playerIndex).getCharacterPosition().y() * 1000.0f)
/ 1000.0f));
}
}

0 comments on commit 544eb0e

Please sign in to comment.