[TIDY] Remove redundancies
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
package uk.mgrove.ac.soton.comp1206.component;
|
package uk.mgrove.ac.soton.comp1206.component;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.event.Event;
|
import javafx.event.Event;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
@@ -43,15 +41,10 @@ public class Chat extends VBox {
|
|||||||
*/
|
*/
|
||||||
private final Text sendMessage = new Text("Send");
|
private final Text sendMessage = new Text("Send");
|
||||||
|
|
||||||
/**
|
|
||||||
* User's current nickname
|
|
||||||
*/
|
|
||||||
private String nickname = "";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The communicator to use
|
* The communicator to use
|
||||||
*/
|
*/
|
||||||
private Communicator communicator;
|
private final Communicator communicator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether chat should scroll to bottom next time layout updates
|
* Whether chat should scroll to bottom next time layout updates
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import javafx.util.Pair;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component to display online leaderboard in multiplayer games
|
* Component to display online leaderboard in multiplayer games
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import javafx.application.Platform;
|
|||||||
import javafx.beans.property.SimpleListProperty;
|
import javafx.beans.property.SimpleListProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package uk.mgrove.ac.soton.comp1206.event;
|
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
|
* Listener for when multiplayer games fail - e.g. due to network errors
|
||||||
*/
|
*/
|
||||||
@@ -10,6 +8,6 @@ public interface GameFailureListener {
|
|||||||
/**
|
/**
|
||||||
* Handle a game failure
|
* Handle a game failure
|
||||||
*/
|
*/
|
||||||
public void gameFail();
|
void gameFail();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import javafx.beans.property.IntegerProperty;
|
|||||||
import javafx.beans.property.SimpleIntegerProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
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
|
* 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 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 {
|
public class Grid {
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,8 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import uk.mgrove.ac.soton.comp1206.event.GameFailureListener;
|
import uk.mgrove.ac.soton.comp1206.event.GameFailureListener;
|
||||||
import uk.mgrove.ac.soton.comp1206.network.Communicator;
|
import uk.mgrove.ac.soton.comp1206.network.Communicator;
|
||||||
import uk.mgrove.ac.soton.comp1206.util.Multimedia;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.PriorityQueue;
|
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
@@ -33,7 +30,7 @@ public class MultiplayerGame extends Game {
|
|||||||
/**
|
/**
|
||||||
* Queue of pieces to be played in the 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
|
* Scores for the leaderboard
|
||||||
@@ -77,8 +74,9 @@ public class MultiplayerGame extends Game {
|
|||||||
}
|
}
|
||||||
nextPiece = pieceQueue.poll();
|
nextPiece = pieceQueue.poll();
|
||||||
}
|
}
|
||||||
|
logger.info("Picking next piece: {}", nextPiece.toString());
|
||||||
} catch (InterruptedException e) {
|
} 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(() -> {
|
Platform.runLater(() -> {
|
||||||
endGame();
|
endGame();
|
||||||
if (gameFailureListener != null) gameFailureListener.gameFail();
|
if (gameFailureListener != null) gameFailureListener.gameFail();
|
||||||
@@ -87,7 +85,6 @@ public class MultiplayerGame extends Game {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Picking next piece: {}", nextPiece.toString());
|
|
||||||
return nextPiece;
|
return nextPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +101,7 @@ public class MultiplayerGame extends Game {
|
|||||||
}
|
}
|
||||||
logger.info("Generated piece from server: {}", newPiece.toString());
|
logger.info("Generated piece from server: {}", newPiece.toString());
|
||||||
} catch (NumberFormatException ex) {
|
} 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 ")) {
|
} else if (message.startsWith("SCORES ")) {
|
||||||
logger.info("Setting scores from server");
|
logger.info("Setting scores from server");
|
||||||
@@ -146,7 +143,7 @@ public class MultiplayerGame extends Game {
|
|||||||
var line = scanner.nextLine();
|
var line = scanner.nextLine();
|
||||||
if (line.matches("^.+:[0-9]+:([0-9]+|DEAD)$")) {
|
if (line.matches("^.+:[0-9]+:([0-9]+|DEAD)$")) {
|
||||||
var info = line.split(":");
|
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)));
|
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);
|
var canPlayPiece = grid.canPlayPiece(currentPiece,x,y);
|
||||||
super.dropPiece(x,y);
|
super.dropPiece(x,y);
|
||||||
if (canPlayPiece) {
|
if (canPlayPiece) {
|
||||||
var communicatorMessage = "BOARD";
|
StringBuilder communicatorMessage = new StringBuilder("BOARD");
|
||||||
for (var i=0; i<grid.getRows(); i++) {
|
for (var i=0; i<grid.getRows(); i++) {
|
||||||
for (var j=0; j<grid.getCols(); j++) {
|
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");
|
logger.info("Sending current board to server");
|
||||||
communicator.send(communicatorMessage);
|
communicator.send(communicatorMessage.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import javafx.beans.property.IntegerProperty;
|
|||||||
import javafx.beans.property.SimpleIntegerProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.input.KeyCode;
|
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package uk.mgrove.ac.soton.comp1206.scene;
|
package uk.mgrove.ac.soton.comp1206.scene;
|
||||||
|
|
||||||
import javafx.geometry.Insets;
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class LoadingScene extends BaseScene {
|
|||||||
TimerTask loadMenuTimerTask = new TimerTask() {
|
TimerTask loadMenuTimerTask = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Platform.runLater(() -> gameWindow.startMenu());
|
Platform.runLater(gameWindow::startMenu);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var loadMenuTimer = new Timer("Timer");
|
var loadMenuTimer = new Timer("Timer");
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package uk.mgrove.ac.soton.comp1206.scene;
|
package uk.mgrove.ac.soton.comp1206.scene;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.event.Event;
|
import javafx.event.Event;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Node;
|
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
@@ -21,7 +19,6 @@ import uk.mgrove.ac.soton.comp1206.ui.GameWindow;
|
|||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public class LobbyScene extends BaseScene {
|
public class LobbyScene extends BaseScene {
|
||||||
|
|
||||||
@@ -235,9 +232,7 @@ public class LobbyScene extends BaseScene {
|
|||||||
logger.info("Current channel host status: {}", isChannelHost);
|
logger.info("Current channel host status: {}", isChannelHost);
|
||||||
var startGame = new Text("Start game");
|
var startGame = new Text("Start game");
|
||||||
startGame.getStyleClass().add("channelItem");
|
startGame.getStyleClass().add("channelItem");
|
||||||
startGame.setOnMouseClicked((event) -> {
|
startGame.setOnMouseClicked((event) -> gameWindow.getCommunicator().send("START"));
|
||||||
gameWindow.getCommunicator().send("START");
|
|
||||||
});
|
|
||||||
channelFunctionButtons.getChildren().add(0, startGame);
|
channelFunctionButtons.getChildren().add(0, startGame);
|
||||||
});
|
});
|
||||||
} else if (message.matches("^NICK .+:.+$")) {
|
} else if (message.matches("^NICK .+:.+$")) {
|
||||||
@@ -287,9 +282,7 @@ public class LobbyScene extends BaseScene {
|
|||||||
logger.info("Joined channel: {}", channelName);
|
logger.info("Joined channel: {}", channelName);
|
||||||
var leaveChannel = new Text("Leave channel");
|
var leaveChannel = new Text("Leave channel");
|
||||||
leaveChannel.getStyleClass().add("channelItem");
|
leaveChannel.getStyleClass().add("channelItem");
|
||||||
leaveChannel.setOnMouseClicked((event) -> {
|
leaveChannel.setOnMouseClicked((event) -> gameWindow.getCommunicator().send("PART"));
|
||||||
gameWindow.getCommunicator().send("PART");
|
|
||||||
});
|
|
||||||
channelFunctionButtons.getChildren().add(leaveChannel);
|
channelFunctionButtons.getChildren().add(leaveChannel);
|
||||||
|
|
||||||
var channelTitle = new Text(channelName);
|
var channelTitle = new Text(channelName);
|
||||||
|
|||||||
@@ -2,15 +2,11 @@ package uk.mgrove.ac.soton.comp1206.scene;
|
|||||||
|
|
||||||
import javafx.animation.Animation;
|
import javafx.animation.Animation;
|
||||||
import javafx.animation.RotateTransition;
|
import javafx.animation.RotateTransition;
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.geometry.Insets;
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import javafx.scene.text.TextAlignment;
|
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|||||||
@@ -1,22 +1,14 @@
|
|||||||
package uk.mgrove.ac.soton.comp1206.scene;
|
package uk.mgrove.ac.soton.comp1206.scene;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.value.ChangeListener;
|
|
||||||
import javafx.geometry.Pos;
|
|
||||||
import javafx.scene.control.Separator;
|
import javafx.scene.control.Separator;
|
||||||
import javafx.scene.layout.BorderPane;
|
|
||||||
import javafx.scene.layout.StackPane;
|
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.shape.Rectangle;
|
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import uk.mgrove.ac.soton.comp1206.component.*;
|
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.game.MultiplayerGame;
|
||||||
import uk.mgrove.ac.soton.comp1206.ui.GamePane;
|
|
||||||
import uk.mgrove.ac.soton.comp1206.ui.GameWindow;
|
import uk.mgrove.ac.soton.comp1206.ui.GameWindow;
|
||||||
import uk.mgrove.ac.soton.comp1206.util.Multimedia;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for multiplayer game scene
|
* Class for multiplayer game scene
|
||||||
@@ -56,7 +48,7 @@ public class MultiplayerScene extends ChallengeScene {
|
|||||||
|
|
||||||
//Start new game
|
//Start new game
|
||||||
game = new MultiplayerGame(5, 5, gameWindow.getCommunicator());
|
game = new MultiplayerGame(5, 5, gameWindow.getCommunicator());
|
||||||
game.setOnGameFail(() -> Platform.runLater(() -> gameWindow.startMenu()));
|
game.setOnGameFail(() -> Platform.runLater(gameWindow::startMenu));
|
||||||
|
|
||||||
gameWindow.getCommunicator().send("SCORES");
|
gameWindow.getCommunicator().send("SCORES");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import javafx.animation.FadeTransition;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.SimpleListProperty;
|
import javafx.beans.property.SimpleListProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.event.EventHandler;
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.MouseEvent;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user