Skip to content

Commit

Permalink
Add checkstyle to GameSetupScene
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed May 25, 2026
1 parent bd3591d commit 38d0471
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/main/java/View/GameSetupScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@


/**
* GameSetupScene class.
* Displays the game setup scene where players configure their game parameters.
*
* Allows players to enter their name, starting capital, and select a stock data file
* before starting the main game. Notifies listeners when the game starts.
*/
public class GameSetupScene {

Expand All @@ -26,11 +29,21 @@ public class GameSetupScene {
private File selectedFile;
private Label fileLabel;

/**
* Constructs a GameSetupScene with a callback for when the game starts.
*
* @param onGameStart callback invoked when the player starts the game. Cannot be null
*/
public GameSetupScene(Consumer<StartGameData> onGameStart) {
this.onGameStart = onGameStart;
this.scene = createScene();
}

/**
* Creates the UI layout for the setup scene.
*
* @return the constructed Scene
*/
private Scene createScene() {

// Card (centered cream box)
Expand Down Expand Up @@ -142,6 +155,12 @@ private Scene createScene() {
return scene;
}

/**
* Validates inputs and starts the game when the Start button is clicked.
*
* @param nameField the text field containing the player name
* @param capitalField the text field containing the starting capital
*/
private void handleStart(TextField nameField, TextField capitalField) {
String name = nameField.getText().trim();
String capitalStr = capitalField.getText().trim();
Expand Down Expand Up @@ -187,6 +206,9 @@ private void handleStart(TextField nameField, TextField capitalField) {
}
}

/**
* Opens a file chooser dialog to select a stock data file.
*/
private void selectFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Select Stock Data File");
Expand All @@ -203,6 +225,12 @@ private void selectFile() {
}
}

/**
* Displays an alert dialog with the given title and message.
*
* @param title the dialog title
* @param message the alert message
*/
private void showAlert(String title, String message) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle(title);
Expand All @@ -211,12 +239,19 @@ private void showAlert(String title, String message) {
alert.showAndWait();
}

/**
* Returns the Scene for display in the application window.
*
* @return the setup scene
*/
public Scene getScene() {
return scene;
}

/**
* StartGameData method.
* Data class encapsulating game setup parameters.
*
* Contains the exchange configured with stocks, player name, and starting capital.
*/
public static class StartGameData {
public final String playerName;
Expand Down

0 comments on commit 38d0471

Please sign in to comment.