diff --git a/tetrecs/src/main/java/uk/ac/soton/comp1206/game/Game.java b/tetrecs/src/main/java/uk/ac/soton/comp1206/game/Game.java index 21b1fb6ea412bdc595549daac0ea208bf428c3a2..62c8b794106a9c0031bd45667889002c45ee7ba4 100644 --- a/tetrecs/src/main/java/uk/ac/soton/comp1206/game/Game.java +++ b/tetrecs/src/main/java/uk/ac/soton/comp1206/game/Game.java @@ -1,5 +1,6 @@ package uk.ac.soton.comp1206.game; +import javafx.beans.property.SimpleIntegerProperty; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import uk.ac.soton.comp1206.component.GameBlock; @@ -32,6 +33,14 @@ public class Game { private GamePiece currentPiece; + private SimpleIntegerProperty score; + + private SimpleIntegerProperty level; + + private SimpleIntegerProperty lives; + + private SimpleIntegerProperty multiplier; + /** * Create a new game with the specified rows and columns. Creates a corresponding grid model. * @param cols number of columns @@ -41,6 +50,12 @@ public class Game { this.cols = cols; this.rows = rows; + this.score = new SimpleIntegerProperty(0); + this.level = new SimpleIntegerProperty(0); + this.lives = new SimpleIntegerProperty(3); + this.multiplier = new SimpleIntegerProperty(1); + + //Create a new grid model to represent the game state this.grid = new Grid(cols,rows); } @@ -128,12 +143,17 @@ public class Game { logger.info("Removing rows/columns"); } + int numGridBlocks = 0; + /** * Removes all columns which are full */ for (int x : fullCols) { for (int y = 0; y < grid.getCols(); y++) { - grid.set(x,y,0); + if (grid.get(x,y) != 0) { + grid.set(x,y,0); + numGridBlocks++; + } } } @@ -142,9 +162,15 @@ public class Game { */ for (int y : fullRows) { for (int x = 0; x < grid.getCols(); x++) { - grid.set(x,y,0); + if (grid.get(x,y) != 0) { + grid.set(x,y,0); + numGridBlocks++; + } } } + + score = new SimpleIntegerProperty(score.get() + (fullCols.size() + fullRows.size()) * numGridBlocks * 10 * multiplier.get()); + System.out.println(score.get()); } /** @@ -171,5 +197,19 @@ public class Game { return rows; } + public SimpleIntegerProperty getLevel() { + return level; + } + + public SimpleIntegerProperty getLives() { + return lives; + } + + public SimpleIntegerProperty getScore() { + return score; + } + public SimpleIntegerProperty getMultiplier() { + return multiplier; + } } diff --git a/tetrecs/src/main/java/uk/ac/soton/comp1206/scene/ChallengeScene.java b/tetrecs/src/main/java/uk/ac/soton/comp1206/scene/ChallengeScene.java index fd6c21bcc9360de01762f70b5a1c8dc91a1f90e4..3e3951f4ef7d584c344f24ecdc3d12138630241c 100644 --- a/tetrecs/src/main/java/uk/ac/soton/comp1206/scene/ChallengeScene.java +++ b/tetrecs/src/main/java/uk/ac/soton/comp1206/scene/ChallengeScene.java @@ -1,6 +1,9 @@ package uk.ac.soton.comp1206.scene; +import javafx.beans.property.Property; +import javafx.geometry.Pos; import javafx.scene.layout.*; +import javafx.scene.text.Text; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import uk.ac.soton.comp1206.component.GameBlock; @@ -49,6 +52,49 @@ public class ChallengeScene extends BaseScene { var board = new GameBoard(game.getGrid(),gameWindow.getWidth()/2,gameWindow.getWidth()/2); mainPane.setCenter(board); + HBox header = new HBox(); + + VBox scoreBox = new VBox(); + var scoreTitle = new Text("Score"); + scoreTitle.getStyleClass().add("heading"); + var scoreValue = new Text(); + scoreValue.textProperty().bind(game.getScore().asString()); + scoreValue.getStyleClass().add("score"); + scoreBox.getChildren().addAll(scoreTitle,scoreValue); + scoreBox.setAlignment(Pos.BASELINE_CENTER); + + header.getChildren().add(scoreBox); + + Region space = new Region(); + space.setPrefHeight(100); + space.setPrefWidth(100); + HBox.setHgrow(space,Priority.ALWAYS); + header.getChildren().add(space); + + var challengeTitle = new Text("Challenge Scene"); + challengeTitle.getStyleClass().add("title"); + header.getChildren().add(challengeTitle); + + Region space2 = new Region(); + space2.setPrefHeight(100); + space2.setPrefWidth(100); + HBox.setHgrow(space2,Priority.ALWAYS); + header.getChildren().add(space2); + + VBox livesBox = new VBox(); + var livesTitle = new Text("Lives"); + livesTitle.getStyleClass().add("heading"); + var livesValue = new Text(); + livesValue.textProperty().bind(game.getLives().asString()); + livesValue.getStyleClass().add("lives"); + livesBox.getChildren().addAll(livesTitle,livesValue); + livesBox.setAlignment(Pos.BASELINE_CENTER); + + header.getChildren().add(livesBox); + header.setAlignment(Pos.CENTER); + + mainPane.setTop(header); + //Handle block on gameboard grid being clicked board.setOnBlockClick(this::blockClicked); } diff --git a/tetrecs/src/main/java/uk/ac/soton/comp1206/scene/MenuScene.java b/tetrecs/src/main/java/uk/ac/soton/comp1206/scene/MenuScene.java index 433d719adf0aa9ad885e8a9abbff05daa204bdb9..79c3ae119fc966d27272e18d386deead328abea2 100644 --- a/tetrecs/src/main/java/uk/ac/soton/comp1206/scene/MenuScene.java +++ b/tetrecs/src/main/java/uk/ac/soton/comp1206/scene/MenuScene.java @@ -48,7 +48,7 @@ public class MenuScene extends BaseScene { //Awful title var title = new Text("TetrECS"); - title.getStyleClass().add("title"); + title.getStyleClass().add("bigtitle"); menuWidgets.getChildren().add(title); VBox menuButtons = new VBox(); @@ -58,7 +58,6 @@ public class MenuScene extends BaseScene { singlePlay.setOnMouseClicked(this::startGame); menuButtons.getChildren().add(singlePlay); - menuButtons.setAlignment(Pos.CENTER); menuWidgets.setAlignment(Pos.TOP_CENTER); diff --git a/tetrecs/target/classes/uk/ac/soton/comp1206/game/Game.class b/tetrecs/target/classes/uk/ac/soton/comp1206/game/Game.class index be32772624ed05d9eb70fad41f3f0732615e7bea..cecf78d96f50f7fea2ff6433c5031c891306b191 100644 Binary files a/tetrecs/target/classes/uk/ac/soton/comp1206/game/Game.class and b/tetrecs/target/classes/uk/ac/soton/comp1206/game/Game.class differ diff --git a/tetrecs/target/classes/uk/ac/soton/comp1206/scene/MenuScene.class b/tetrecs/target/classes/uk/ac/soton/comp1206/scene/MenuScene.class index b58df00055fca0f690452354818862658dbb1c86..afc0c298de62f7b0ad2e34a37ff7f6c67d34139b 100644 Binary files a/tetrecs/target/classes/uk/ac/soton/comp1206/scene/MenuScene.class and b/tetrecs/target/classes/uk/ac/soton/comp1206/scene/MenuScene.class differ