Method additions
parent
46d5f6ec4a
commit
e5ea5fb2ba
|
|
@ -1,33 +1,32 @@
|
||||||
package GUI;
|
package GUI;
|
||||||
|
|
||||||
import domain.*;
|
import domain.*;
|
||||||
import GUI.HitoriDialogManager;
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class GameUIController {
|
public class GameUIController {
|
||||||
private final HitoriGameMoves gameMoves;
|
private final HitoriGameMoves gameMoves;
|
||||||
private final GameSolver gameSolver;
|
private final GameSolver gameSolver;
|
||||||
private final domain.HitoriGameTimer gameTimer;
|
private final HitoriGameTimer gameTimer;
|
||||||
private final HitoriGameScores gameScores;
|
private final HitoriGameScores gameScores;
|
||||||
private final GUI.HitoriDialogManager dialogManager;
|
private final HitoriDialogManager dialogManager;
|
||||||
private final GUI.HitoriBoardPanel boardPanel;
|
private final HitoriBoardPanel boardPanel;
|
||||||
private final GUI.HitoriControlPanel controlPanel;
|
private final HitoriControlPanel controlPanel;
|
||||||
private final GUI.HitoriScorePanel scorePanel;
|
private final HitoriScorePanel scorePanel;
|
||||||
private Timer guiTimer;
|
private Timer guiTimer;
|
||||||
private boolean isPaused;
|
private boolean isPaused;
|
||||||
|
|
||||||
public GameUIController(int[][] initialBoard, HitoriDialogManager dialogManager) {
|
public GameUIController(int[][] initialBoard, HitoriDialogManager dialogManager) {
|
||||||
this.gameMoves = new HitoriGameMoves(initialBoard);
|
this.gameMoves = new HitoriGameMoves(initialBoard);
|
||||||
this.gameSolver = new GameSolver(initialBoard);
|
this.gameSolver = new GameSolver(initialBoard);
|
||||||
this.gameTimer = new domain.HitoriGameTimer();
|
this.gameTimer = new HitoriGameTimer();
|
||||||
this.gameScores = new HitoriGameScores();
|
this.gameScores = new HitoriGameScores();
|
||||||
this.dialogManager = dialogManager;
|
this.dialogManager = dialogManager;
|
||||||
this.isPaused = false;
|
this.isPaused = false;
|
||||||
|
|
||||||
this.boardPanel = new GUI.HitoriBoardPanel(gameMoves, gameSolver, this);
|
this.boardPanel = new HitoriBoardPanel(gameMoves, gameSolver, this);
|
||||||
this.controlPanel = new GUI.HitoriControlPanel(this);
|
this.controlPanel = new HitoriControlPanel(this);
|
||||||
this.scorePanel = new GUI.HitoriScorePanel(this);
|
this.scorePanel = new HitoriScorePanel(this);
|
||||||
|
|
||||||
startTimer();
|
startTimer();
|
||||||
loadHighScores();
|
loadHighScores();
|
||||||
|
|
@ -36,15 +35,19 @@ public class GameUIController {
|
||||||
public void handleLeftClick(int row, int col) {
|
public void handleLeftClick(int row, int col) {
|
||||||
gameMoves.markCellAsBlack(row, col);
|
gameMoves.markCellAsBlack(row, col);
|
||||||
updateUI();
|
updateUI();
|
||||||
|
checkWin();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleRightClick(int row, int col) {
|
public void handleRightClick(int row, int col) {
|
||||||
gameMoves.markCellAsWhite(row, col);
|
gameMoves.markCellAsWhite(row, col);
|
||||||
updateUI();
|
updateUI();
|
||||||
|
checkWin();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkWin() {
|
||||||
|
if (gameSolver.isSolved()) {
|
||||||
|
handleWin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void togglePause() {
|
public void togglePause() {
|
||||||
|
|
@ -81,7 +84,7 @@ public class GameUIController {
|
||||||
|
|
||||||
public void newGame() {
|
public void newGame() {
|
||||||
stopTimer();
|
stopTimer();
|
||||||
// Notify main application to show board selection
|
// Main application will handle board selection
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkSolution() {
|
public void checkSolution() {
|
||||||
|
|
@ -108,7 +111,8 @@ public class GameUIController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveGame() {
|
public void saveGame() {
|
||||||
// Implementation for saving game state
|
HitoriGameMain gameState = new HitoriGameMain(gameMoves.getBoard());
|
||||||
|
gameState.saveGameState();
|
||||||
dialogManager.showAlert("Game Saved", "Your game has been saved successfully.");
|
dialogManager.showAlert("Game Saved", "Your game has been saved successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,6 +175,7 @@ public class GameUIController {
|
||||||
private void updateUI() {
|
private void updateUI() {
|
||||||
boardPanel.updateBoard();
|
boardPanel.updateBoard();
|
||||||
updateMistakeLabel();
|
updateMistakeLabel();
|
||||||
|
checkWin();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTimerLabel() {
|
private void updateTimerLabel() {
|
||||||
|
|
@ -218,4 +223,4 @@ public class GameUIController {
|
||||||
public HitoriScorePanel getScorePanel() {
|
public HitoriScorePanel getScorePanel() {
|
||||||
return scorePanel;
|
return scorePanel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -90,5 +90,4 @@ public class HitoriBoardPanel extends GridPane {
|
||||||
button.setStyle("-fx-background-color: lightgray; -fx-text-fill: black;");
|
button.setStyle("-fx-background-color: lightgray; -fx-text-fill: black;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package GUI;
|
package GUI;
|
||||||
|
|
||||||
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package GUI;
|
package GUI;
|
||||||
|
|
||||||
import GUI.GameUIController;
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
package Main;
|
package Main;
|
||||||
|
|
||||||
|
|
||||||
import domain.HitoriGameMain;
|
|
||||||
import domain.HitoriBoardLoader;
|
|
||||||
import GUI.GameUIController;
|
|
||||||
import GUI.HitoriDialogManager;
|
import GUI.HitoriDialogManager;
|
||||||
|
import domain.HitoriBoardLoader;
|
||||||
|
import domain.HitoriGameMain;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import GUI.GameUIController;
|
||||||
|
|
||||||
public class MainMethod extends Application {
|
public class MainMethod extends Application {
|
||||||
private HitoriBoardLoader boardLoader;
|
private HitoriBoardLoader boardLoader;
|
||||||
|
|
@ -93,4 +92,4 @@ public class MainMethod extends Application {
|
||||||
controller.cleanup();
|
controller.cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class HitoriGameBaseTest {
|
class GameBaseTest {
|
||||||
private domain.GameBase game;
|
private domain.GameBase game;
|
||||||
private static final int[][] TEST_BOARD = {
|
private static final int[][] TEST_BOARD = {
|
||||||
{1, 2, 1, 3},
|
{1, 2, 1, 3},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue