[TIDY] Remove redundancies

This commit is contained in:
2023-04-21 23:34:26 +01:00
parent 839c7ee5c8
commit 0b3dfa5817
13 changed files with 15 additions and 62 deletions

View File

@@ -1,10 +1,8 @@
package uk.mgrove.ac.soton.comp1206.component;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
@@ -43,15 +41,10 @@ public class Chat extends VBox {
*/
private final Text sendMessage = new Text("Send");
/**
* User's current nickname
*/
private String nickname = "";
/**
* The communicator to use
*/
private Communicator communicator;
private final Communicator communicator;
/**
* Whether chat should scroll to bottom next time layout updates

View File

@@ -10,8 +10,6 @@ import javafx.util.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Map;
/**
* Component to display online leaderboard in multiplayer games
*/

View File

@@ -5,7 +5,6 @@ import javafx.application.Platform;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;

View File

@@ -1,7 +1,5 @@
package uk.mgrove.ac.soton.comp1206.event;
import uk.mgrove.ac.soton.comp1206.component.GameBlock;
/**
* Listener for when multiplayer games fail - e.g. due to network errors
*/
@@ -10,6 +8,6 @@ public interface GameFailureListener {
/**
* Handle a game failure
*/
public void gameFail();
void gameFail();
}

View File

@@ -4,7 +4,6 @@ import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import uk.mgrove.ac.soton.comp1206.ui.GameWindow;
/**
* The Grid is a model which holds the state of a game board. It is made up of a set of Integer values arranged in a 2D
@@ -15,7 +14,7 @@ import uk.mgrove.ac.soton.comp1206.ui.GameWindow;
*
* The Grid contains functions related to modifying the model, for example, placing a piece inside the grid.
*
* The Grid should be linked to a GameBoard for it's display.
* The Grid should be linked to a GameBoard for its display.
*/
public class Grid {

View File

@@ -9,11 +9,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import uk.mgrove.ac.soton.comp1206.event.GameFailureListener;
import uk.mgrove.ac.soton.comp1206.network.Communicator;
import uk.mgrove.ac.soton.comp1206.util.Multimedia;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -33,7 +30,7 @@ public class MultiplayerGame extends Game {
/**
* Queue of pieces to be played in the game
*/
private BlockingQueue<GamePiece> pieceQueue = new LinkedBlockingQueue<>();
private final BlockingQueue<GamePiece> pieceQueue = new LinkedBlockingQueue<>();
/**
* Scores for the leaderboard
@@ -77,8 +74,9 @@ public class MultiplayerGame extends Game {
}
nextPiece = pieceQueue.poll();
}
logger.info("Picking next piece: {}", nextPiece.toString());
} catch (InterruptedException e) {
logger.error("Unable to retrieve piece from queue - waiting interrupted: {}", e);
logger.error("Unable to retrieve piece from queue - waiting interrupted: " + e);
Platform.runLater(() -> {
endGame();
if (gameFailureListener != null) gameFailureListener.gameFail();
@@ -87,7 +85,6 @@ public class MultiplayerGame extends Game {
});
}
logger.info("Picking next piece: {}", nextPiece.toString());
return nextPiece;
}
@@ -104,7 +101,7 @@ public class MultiplayerGame extends Game {
}
logger.info("Generated piece from server: {}", newPiece.toString());
} catch (NumberFormatException ex) {
logger.error("Unable to generate piece from server - piece value not a number: {}", ex);
logger.error("Unable to generate piece from server - piece value not a number: " + ex);
}
} else if (message.startsWith("SCORES ")) {
logger.info("Setting scores from server");
@@ -146,7 +143,7 @@ public class MultiplayerGame extends Game {
var line = scanner.nextLine();
if (line.matches("^.+:[0-9]+:([0-9]+|DEAD)$")) {
var info = line.split(":");
var lives = info[2].equals("DEAD") ? -1 : Integer.valueOf(info[2]);
var lives = info[2].equals("DEAD") ? -1 : Integer.parseInt(info[2]);
scores.add(new Pair<>(info[0], new Pair<>(Integer.valueOf(info[1]), lives)));
}
}
@@ -208,14 +205,14 @@ public class MultiplayerGame extends Game {
var canPlayPiece = grid.canPlayPiece(currentPiece,x,y);
super.dropPiece(x,y);
if (canPlayPiece) {
var communicatorMessage = "BOARD";
StringBuilder communicatorMessage = new StringBuilder("BOARD");
for (var i=0; i<grid.getRows(); i++) {
for (var j=0; j<grid.getCols(); j++) {
communicatorMessage += " " + grid.get(i,j);
communicatorMessage.append(" ").append(grid.get(i, j));
}
}
logger.info("Sending current board to server");
communicator.send(communicatorMessage);
communicator.send(communicatorMessage.toString());
}
}

View File

@@ -5,7 +5,6 @@ import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.geometry.Pos;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;

View File

@@ -1,6 +1,5 @@
package uk.mgrove.ac.soton.comp1206.scene;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;

View File

@@ -71,7 +71,7 @@ public class LoadingScene extends BaseScene {
TimerTask loadMenuTimerTask = new TimerTask() {
@Override
public void run() {
Platform.runLater(() -> gameWindow.startMenu());
Platform.runLater(gameWindow::startMenu);
}
};
var loadMenuTimer = new Timer("Timer");

View File

@@ -1,11 +1,9 @@
package uk.mgrove.ac.soton.comp1206.scene;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.BorderPane;
@@ -21,7 +19,6 @@ import uk.mgrove.ac.soton.comp1206.ui.GameWindow;
import java.util.Timer;
import java.util.TimerTask;
import java.util.function.Predicate;
public class LobbyScene extends BaseScene {
@@ -235,9 +232,7 @@ public class LobbyScene extends BaseScene {
logger.info("Current channel host status: {}", isChannelHost);
var startGame = new Text("Start game");
startGame.getStyleClass().add("channelItem");
startGame.setOnMouseClicked((event) -> {
gameWindow.getCommunicator().send("START");
});
startGame.setOnMouseClicked((event) -> gameWindow.getCommunicator().send("START"));
channelFunctionButtons.getChildren().add(0, startGame);
});
} else if (message.matches("^NICK .+:.+$")) {
@@ -287,9 +282,7 @@ public class LobbyScene extends BaseScene {
logger.info("Joined channel: {}", channelName);
var leaveChannel = new Text("Leave channel");
leaveChannel.getStyleClass().add("channelItem");
leaveChannel.setOnMouseClicked((event) -> {
gameWindow.getCommunicator().send("PART");
});
leaveChannel.setOnMouseClicked((event) -> gameWindow.getCommunicator().send("PART"));
channelFunctionButtons.getChildren().add(leaveChannel);
var channelTitle = new Text(channelName);

View File

@@ -2,15 +2,11 @@ package uk.mgrove.ac.soton.comp1206.scene;
import javafx.animation.Animation;
import javafx.animation.RotateTransition;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.util.Duration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@@ -1,22 +1,14 @@
package uk.mgrove.ac.soton.comp1206.scene;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.geometry.Pos;
import javafx.scene.control.Separator;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import uk.mgrove.ac.soton.comp1206.component.*;
import uk.mgrove.ac.soton.comp1206.game.Game;
import uk.mgrove.ac.soton.comp1206.game.MultiplayerGame;
import uk.mgrove.ac.soton.comp1206.ui.GamePane;
import uk.mgrove.ac.soton.comp1206.ui.GameWindow;
import uk.mgrove.ac.soton.comp1206.util.Multimedia;
/**
* Class for multiplayer game scene
@@ -56,7 +48,7 @@ public class MultiplayerScene extends ChallengeScene {
//Start new game
game = new MultiplayerGame(5, 5, gameWindow.getCommunicator());
game.setOnGameFail(() -> Platform.runLater(() -> gameWindow.startMenu()));
game.setOnGameFail(() -> Platform.runLater(gameWindow::startMenu));
gameWindow.getCommunicator().send("SCORES");
}

View File

@@ -4,10 +4,7 @@ import javafx.animation.FadeTransition;
import javafx.application.Platform;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseEvent;
@@ -367,11 +364,4 @@ public class ScoresScene extends BaseScene {
}
}
/**
* Get local scores property
* @return local scores property
*/
public SimpleListProperty<Pair<String, Integer>> localScoresProperty() {
return localScores;
}
}