[TIDY] Some more help from IntelliJ
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
module uk.mgrove.ac.soton.comp1206 {
|
module uk.mgrove.ac.soton.comp1206 {
|
||||||
requires java.scripting;
|
|
||||||
requires javafx.controls;
|
requires javafx.controls;
|
||||||
requires javafx.fxml;
|
|
||||||
requires javafx.media;
|
requires javafx.media;
|
||||||
requires org.apache.logging.log4j;
|
requires org.apache.logging.log4j;
|
||||||
requires nv.websocket.client;
|
requires nv.websocket.client;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package uk.mgrove.ac.soton.comp1206.component;
|
package uk.mgrove.ac.soton.comp1206.component;
|
||||||
|
|
||||||
import javafx.beans.property.IntegerProperty;
|
import javafx.beans.property.IntegerProperty;
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
|
||||||
import javafx.scene.input.MouseButton;
|
import javafx.scene.input.MouseButton;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package uk.mgrove.ac.soton.comp1206.event;
|
package uk.mgrove.ac.soton.comp1206.event;
|
||||||
|
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
import uk.mgrove.ac.soton.comp1206.component.GameBoard;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for player game boards
|
* Listener for player game boards
|
||||||
|
|||||||
@@ -59,19 +59,19 @@ public class Game {
|
|||||||
/**
|
/**
|
||||||
* Player's current score
|
* Player's current score
|
||||||
*/
|
*/
|
||||||
protected IntegerProperty score = new SimpleIntegerProperty(0);
|
protected final IntegerProperty score = new SimpleIntegerProperty(0);
|
||||||
/**
|
/**
|
||||||
* Player's current level
|
* Player's current level
|
||||||
*/
|
*/
|
||||||
protected IntegerProperty level = new SimpleIntegerProperty(0);
|
protected final IntegerProperty level = new SimpleIntegerProperty(0);
|
||||||
/**
|
/**
|
||||||
* Player's number of remaining lives
|
* Player's number of remaining lives
|
||||||
*/
|
*/
|
||||||
protected IntegerProperty lives = new SimpleIntegerProperty(3);
|
protected final IntegerProperty lives = new SimpleIntegerProperty(3);
|
||||||
/**
|
/**
|
||||||
* Player's current multiplier
|
* Player's current multiplier
|
||||||
*/
|
*/
|
||||||
protected IntegerProperty multiplier = new SimpleIntegerProperty(1);
|
protected final IntegerProperty multiplier = new SimpleIntegerProperty(1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for when new piece is received by the game
|
* Listener for when new piece is received by the game
|
||||||
@@ -370,22 +370,6 @@ public class Game {
|
|||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the number of columns in this game
|
|
||||||
* @return number of columns
|
|
||||||
*/
|
|
||||||
public int getCols() {
|
|
||||||
return cols;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the number of rows in this game
|
|
||||||
* @return number of rows
|
|
||||||
*/
|
|
||||||
public int getRows() {
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the player's current level
|
* Get the player's current level
|
||||||
* @return current level
|
* @return current level
|
||||||
@@ -394,13 +378,6 @@ public class Game {
|
|||||||
return level.get();
|
return level.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the player's current level
|
|
||||||
*/
|
|
||||||
public void setLevel(int level) {
|
|
||||||
this.level.set(level);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the player's current level property
|
* Get the player's current level property
|
||||||
* @return player's current level property
|
* @return player's current level property
|
||||||
@@ -432,14 +409,6 @@ public class Game {
|
|||||||
return lives;
|
return lives;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the player's current multiplier
|
|
||||||
* @return current multiplier
|
|
||||||
*/
|
|
||||||
public int getMultiplier() {
|
|
||||||
return multiplier.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the player's current multiplier
|
* Set the player's current multiplier
|
||||||
*/
|
*/
|
||||||
@@ -463,13 +432,6 @@ public class Game {
|
|||||||
return score.get();
|
return score.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the player's current score
|
|
||||||
*/
|
|
||||||
public void setScore(int score) {
|
|
||||||
this.score.set(score);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the player's current score property
|
* Get the player's current score property
|
||||||
* @return player's current score property
|
* @return player's current score property
|
||||||
@@ -518,17 +480,9 @@ public class Game {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the player boards property - always null in this class
|
|
||||||
* @return property for player boards
|
|
||||||
*/
|
|
||||||
public SimpleMapProperty<String, SimpleIntegerProperty[][]> playerBoardsProperty() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set listener for when new player board is added
|
* Set listener for when new player board is added
|
||||||
* @param listener
|
* @param listener listener to set
|
||||||
*/
|
*/
|
||||||
public void setOnPlayerBoardAdded(PlayerGameBoardListener listener) {
|
public void setOnPlayerBoardAdded(PlayerGameBoardListener listener) {
|
||||||
this.playerBoardAddedListener = listener;
|
this.playerBoardAddedListener = listener;
|
||||||
|
|||||||
@@ -226,9 +226,9 @@ public class Grid {
|
|||||||
* Clear previewed blocks from the grid
|
* Clear previewed blocks from the grid
|
||||||
*/
|
*/
|
||||||
public void clearPreview() {
|
public void clearPreview() {
|
||||||
for (var resetX = 0; resetX < previewGrid.length; resetX++) {
|
for (SimpleIntegerProperty[] simpleIntegerProperties : previewGrid) {
|
||||||
for (var resetY = 0; resetY < previewGrid[0].length; resetY++) {
|
for (SimpleIntegerProperty simpleIntegerProperty : simpleIntegerProperties) {
|
||||||
previewGrid[resetX][resetY].set(0);
|
simpleIntegerProperty.set(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,7 @@ import javafx.beans.property.SimpleIntegerProperty;
|
|||||||
import javafx.beans.property.SimpleListProperty;
|
import javafx.beans.property.SimpleListProperty;
|
||||||
import javafx.beans.property.SimpleMapProperty;
|
import javafx.beans.property.SimpleMapProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.geometry.Pos;
|
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.layout.VBox;
|
|
||||||
import javafx.scene.text.Text;
|
|
||||||
import javafx.scene.text.TextAlignment;
|
|
||||||
import javafx.util.Pair;
|
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;
|
||||||
@@ -17,9 +13,6 @@ 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 uk.mgrove.ac.soton.comp1206.util.Multimedia;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
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;
|
||||||
|
|||||||
@@ -27,16 +27,6 @@ public class MultiplayerScene extends ChallengeScene {
|
|||||||
*/
|
*/
|
||||||
private static final Logger logger = LogManager.getLogger(MultiplayerScene.class);
|
private static final Logger logger = LogManager.getLogger(MultiplayerScene.class);
|
||||||
|
|
||||||
/**
|
|
||||||
* Chat container
|
|
||||||
*/
|
|
||||||
private Chat chat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Live leaderboard
|
|
||||||
*/
|
|
||||||
private Leaderboard leaderboard;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Other players' live boards
|
* Other players' live boards
|
||||||
*/
|
*/
|
||||||
@@ -67,35 +57,33 @@ public class MultiplayerScene extends ChallengeScene {
|
|||||||
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));
|
||||||
|
|
||||||
game.setOnPlayerBoardAdded((username, gridProperties) -> {
|
game.setOnPlayerBoardAdded((username, gridProperties) -> Platform.runLater(() -> {
|
||||||
Platform.runLater(() -> {
|
var newGameBoard = new GameBoard(gridProperties.length, gridProperties[0].length, 100, 100);
|
||||||
var newGameBoard = new GameBoard(gridProperties.length, gridProperties[0].length, 100, 100);
|
newGameBoard.enableFocus(false);
|
||||||
newGameBoard.enableFocus(false);
|
for (var x = 0; x < gridProperties.length; x++) {
|
||||||
for (var x = 0; x < gridProperties.length; x++) {
|
for (var y = 0; y < gridProperties[0].length; y++) {
|
||||||
for (var y = 0; y < gridProperties[0].length; y++) {
|
newGameBoard.getGridProperty(x,y).bindBidirectional(gridProperties[x][y]);
|
||||||
newGameBoard.getGridProperty(x,y).bindBidirectional(gridProperties[x][y]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var leaderboardScores = game.leaderboardScoresProperty();
|
}
|
||||||
|
var leaderboardScores = game.leaderboardScoresProperty();
|
||||||
|
|
||||||
var boardGridDimensions = (int) Math.sqrt(leaderboardScores.size());
|
var boardGridDimensions = (int) Math.sqrt(leaderboardScores.size());
|
||||||
var playerIndex = -1;
|
var playerIndex = -1;
|
||||||
for (var player : leaderboardScores) {
|
for (var player : leaderboardScores) {
|
||||||
playerIndex++;
|
playerIndex++;
|
||||||
if (player.getKey().equals(username)) break;
|
if (player.getKey().equals(username)) break;
|
||||||
}
|
}
|
||||||
var rowIndex = playerIndex / boardGridDimensions;
|
var rowIndex = playerIndex / boardGridDimensions;
|
||||||
var columnIndex = playerIndex - rowIndex * boardGridDimensions;
|
var columnIndex = playerIndex - rowIndex * boardGridDimensions;
|
||||||
var newBoardTitle = new Text(username);
|
var newBoardTitle = new Text(username);
|
||||||
newBoardTitle.setTextAlignment(TextAlignment.CENTER);
|
newBoardTitle.setTextAlignment(TextAlignment.CENTER);
|
||||||
newBoardTitle.getStyleClass().add("heading");
|
newBoardTitle.getStyleClass().add("heading");
|
||||||
logger.debug("Creating board for: {} at row index: {}, column index: {}", username, rowIndex, columnIndex);
|
logger.debug("Creating board for: {} at row index: {}, column index: {}", username, rowIndex, columnIndex);
|
||||||
var newBoardContainer = new VBox(newBoardTitle, newGameBoard);
|
var newBoardContainer = new VBox(newBoardTitle, newGameBoard);
|
||||||
newBoardContainer.setAlignment(Pos.CENTER);
|
newBoardContainer.setAlignment(Pos.CENTER);
|
||||||
newBoardContainer.setSpacing(4);
|
newBoardContainer.setSpacing(4);
|
||||||
playerBoardGrid.add(newBoardContainer, 1, 1);
|
playerBoardGrid.add(newBoardContainer, 1, 1);
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
gameWindow.getCommunicator().send("SCORES");
|
gameWindow.getCommunicator().send("SCORES");
|
||||||
}
|
}
|
||||||
@@ -112,27 +100,26 @@ public class MultiplayerScene extends ChallengeScene {
|
|||||||
leftMenu.setPrefWidth(200);
|
leftMenu.setPrefWidth(200);
|
||||||
var viewOtherBoards = new Text("See others");
|
var viewOtherBoards = new Text("See others");
|
||||||
viewOtherBoards.getStyleClass().add("channelItem");
|
viewOtherBoards.getStyleClass().add("channelItem");
|
||||||
viewOtherBoards.setOnMouseClicked((event) -> {
|
viewOtherBoards.setOnMouseClicked((event) -> Platform.runLater(() -> {
|
||||||
Platform.runLater(() -> {
|
var returnButton = new Text("Back");
|
||||||
var returnButton = new Text("Back");
|
returnButton.getStyleClass().add("channelItem");
|
||||||
returnButton.getStyleClass().add("channelItem");
|
var playerBoardTitle = new Text("All Boards");
|
||||||
var playerBoardTitle = new Text("All Boards");
|
playerBoardTitle.getStyleClass().add("title");
|
||||||
playerBoardTitle.getStyleClass().add("title");
|
playerBoardTitle.setTextAlignment(TextAlignment.CENTER);
|
||||||
playerBoardTitle.setTextAlignment(TextAlignment.CENTER);
|
var playerBoardGridContainer = new VBox(returnButton, playerBoardTitle, playerBoardGrid);
|
||||||
var playerBoardGridContainer = new VBox(returnButton, playerBoardTitle, playerBoardGrid);
|
playerBoardGridContainer.setAlignment(Pos.CENTER);
|
||||||
playerBoardGridContainer.setAlignment(Pos.CENTER);
|
playerBoardGridContainer.setFillWidth(true);
|
||||||
playerBoardGridContainer.setFillWidth(true);
|
playerBoardGridContainer.setPrefHeight(Double.MAX_VALUE);
|
||||||
playerBoardGridContainer.setPrefHeight(Double.MAX_VALUE);
|
playerBoardGridContainer.setSpacing(12);
|
||||||
playerBoardGridContainer.setSpacing(12);
|
playerBoardGridContainer.getStyleClass().add("overlay");
|
||||||
playerBoardGridContainer.getStyleClass().add("overlay");
|
returnButton.setOnMouseClicked((returnEvent) -> Platform.runLater(() -> challengePane.getChildren().remove(playerBoardGridContainer)));
|
||||||
returnButton.setOnMouseClicked((returnEvent) -> Platform.runLater(() -> challengePane.getChildren().remove(playerBoardGridContainer)));
|
playerBoardGrid.setAlignment(Pos.CENTER);
|
||||||
playerBoardGrid.setAlignment(Pos.CENTER);
|
challengePane.getChildren().add(playerBoardGridContainer);
|
||||||
challengePane.getChildren().add(playerBoardGridContainer);
|
}));
|
||||||
});
|
|
||||||
});
|
Chat chat = new Chat(gameWindow.getCommunicator(), true);
|
||||||
chat = new Chat(gameWindow.getCommunicator(), true);
|
|
||||||
chat.setChatFocusTraversable(false);
|
chat.setChatFocusTraversable(false);
|
||||||
leaderboard = new Leaderboard("Leaderboard");
|
Leaderboard leaderboard = new Leaderboard("Leaderboard");
|
||||||
var chatTitle = new Text("Chat");
|
var chatTitle = new Text("Chat");
|
||||||
chatTitle.getStyleClass().add("heading");
|
chatTitle.getStyleClass().add("heading");
|
||||||
leftMenu.getChildren().addAll(viewOtherBoards, leaderboard, new Separator(), chatTitle, chat);
|
leftMenu.getChildren().addAll(viewOtherBoards, leaderboard, new Separator(), chatTitle, chat);
|
||||||
|
|||||||
@@ -67,11 +67,7 @@ public class GamePane extends StackPane {
|
|||||||
var scaleFactorWidth = getWidth() / width;
|
var scaleFactorWidth = getWidth() / width;
|
||||||
|
|
||||||
//Work out whether to scale by width or height
|
//Work out whether to scale by width or height
|
||||||
if (scaleFactorHeight > scaleFactorWidth) {
|
setScalar(Math.min(scaleFactorHeight, scaleFactorWidth));
|
||||||
setScalar(scaleFactorWidth);
|
|
||||||
} else {
|
|
||||||
setScalar(scaleFactorHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set up the scale
|
//Set up the scale
|
||||||
Scale scale = new Scale(scalar,scalar);
|
Scale scale = new Scale(scalar,scalar);
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ import uk.mgrove.ac.soton.comp1206.App;
|
|||||||
import uk.mgrove.ac.soton.comp1206.game.Game;
|
import uk.mgrove.ac.soton.comp1206.game.Game;
|
||||||
import uk.mgrove.ac.soton.comp1206.network.Communicator;
|
import uk.mgrove.ac.soton.comp1206.network.Communicator;
|
||||||
import uk.mgrove.ac.soton.comp1206.scene.*;
|
import uk.mgrove.ac.soton.comp1206.scene.*;
|
||||||
import uk.mgrove.ac.soton.comp1206.scene.BaseScene;
|
|
||||||
import uk.mgrove.ac.soton.comp1206.scene.ChallengeScene;
|
|
||||||
import uk.mgrove.ac.soton.comp1206.scene.MenuScene;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The GameWindow is the single window for the game where everything takes place. To move between screens in the game,
|
* The GameWindow is the single window for the game where everything takes place. To move between screens in the game,
|
||||||
|
|||||||
Reference in New Issue
Block a user