Skip to content
Snippets Groups Projects
Commit 63228cf7 authored by ayazb7's avatar ayazb7
Browse files

Adding UI Changes

parent 6f1d9e77
No related branches found
No related tags found
No related merge requests found
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;
}
}
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);
}
......
......@@ -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);
......
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment