Skip to content

Commit

Permalink
Fix to Level Slider and Game Speed (#80)
Browse files Browse the repository at this point in the history
* Fix to level slider and initial game speed

* Additional fix to game speed
  • Loading branch information
quaidsage authored Aug 22, 2024
1 parent 8735e91 commit 7868736
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/main/java/com/stackedsuccess/GameBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class GameBoard {

private int score = 0;
private int level = 1;
private int baseLevel = 1;
private int totalLinesCleared = 0;
private int gameSpeed;

Expand Down Expand Up @@ -122,6 +123,11 @@ public boolean isSpawnLocationOccupied() {
return checkCollision(Tetrimino.DEFAULT_SPAWN_X, Tetrimino.DEFAULT_SPAWN_Y);
}

public void setBaseLevel(int baseLevel) {
this.baseLevel = baseLevel;
updateLevel();
}

/** Forces the game loop to update once, primarily used to place tetrimino pieces instantly. */
public void forceUpdate() {
forceUpdate = true;
Expand Down Expand Up @@ -225,8 +231,9 @@ private void clearFullRows() {

/** Updates the level based on the number of lines cleared. */
private void updateLevel() {
level = (totalLinesCleared / 10) + 1;
level = (totalLinesCleared / 10) + baseLevel;
controller.updateLevel(level);
changeGameSpeed();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void onKeyPressed(KeyEvent event) {
gameInstance.handleInput(event);
}

// TODO: JAVADOCS
private void togglePauseScreen(){
if(gameInstance.isPaused()){
basePane.requestFocus();
Expand All @@ -163,11 +164,13 @@ public void onClickPauseButton() {
gameInstance.togglePause();
}

// TODO: JAVADOCS
@FXML
void onClickExit(ActionEvent event) {
System.exit(0);
}

// TODO: JAVADOCS
@FXML
void onClickRestart(ActionEvent event) throws IOException {
SceneManager.addScene(AppUI.MAIN_MENU, loadFxml("HomeScreen"));
Expand Down Expand Up @@ -201,6 +204,7 @@ public void updateLevel(int level) {
Platform.runLater(() -> levelLabel.setText(String.valueOf(level)));
}

public void setBaseLevel(int baseLevel) { Platform.runLater(() -> gameInstance.getGameBoard().setBaseLevel(baseLevel));}
/**
* Sets the view of the next tetromino to be loaded.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class HomeScreenController {
@FXML private Button pastScoresButton;
@FXML private ListView<String> pastScores;

// TODO: JAVADOCS
@FXML
public void initialize() {
difficultySlider.requestFocus();
Expand All @@ -49,21 +50,24 @@ private List<String> loadScoresFromFile(String filePath) {
return scores;
}

/** Handles exiting of window on game exit. */
public void exitGame() {
System.exit(0);
}

// TODO: JAVADOCS
@FXML
public void startGame() throws IOException {
int initialLevel = (int) difficultySlider.getValue(); // Get the level from the slider
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/fxml/GameBoard.fxml"));
Parent root = loader.load();
GameBoardController controller = loader.getController();
controller.updateLevel(initialLevel); // Set the initial level
controller.setBaseLevel(initialLevel);
SceneManager.addScene(AppUI.GAME, root);
Main.setUi(AppUI.GAME);
}

// TODO: JAVADOCS
public void onKeyPressed(KeyEvent event) {
difficultySlider.requestFocus();
if (event.getCode() == KeyCode.SPACE) {
Expand All @@ -75,6 +79,7 @@ public void onKeyPressed(KeyEvent event) {
}
}

// TODO: JAVADOCS
@FXML
public void showPastScores() {
if (pastScores.isVisible()) {
Expand Down

0 comments on commit 7868736

Please sign in to comment.