Skip to content

add startScreen with username textbox and radio buttons on difficulty #67

Merged
merged 1 commit into from
Apr 10, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package edu.ntnu.idi.idatt2003.gruppe42.Controller;

import edu.ntnu.idi.idatt2003.gruppe42.Model.Player;
import edu.ntnu.idi.idatt2003.gruppe42.View.StartScreen;
import java.math.BigDecimal;
import javafx.scene.control.RadioButton;

public class StartScreenController {

private String username = "";
private final StartScreen startScreen;

public StartScreenController(StartScreen startScreen) {

this.startScreen = startScreen;

startScreen.getUsernameField().textProperty().addListener((obs, old, newValue) -> {
if (isValidName(newValue)) {
username = newValue;
}
});

startScreen.getLoginButton().setOnAction(e -> handleStart());
}

private void handleStart() {
BigDecimal money = getStartingMoney();

Player player = new Player(username, money);
System.out.println(player.getMoney());
}

private boolean isValidName(String value) {
return value != null && value.matches("[a-zA-Z0-9]+");
}

private BigDecimal getStartingMoney() {
String selected = startScreen.getSelectedMode();

return switch (selected.charAt(0)) {
case 'E' -> new BigDecimal("1000");
case 'M' -> new BigDecimal("100");
case 'H' -> new BigDecimal("0");
default -> new BigDecimal("1000");
};
}

}
6 changes: 4 additions & 2 deletions src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Millions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.ntnu.idi.idatt2003.gruppe42;

import edu.ntnu.idi.idatt2003.gruppe42.Controller.StartScreenController;
import edu.ntnu.idi.idatt2003.gruppe42.View.StartScreen;
import javafx.application.Application;
import javafx.scene.Scene;
Expand All @@ -11,8 +12,9 @@ public class Millions extends Application {
@Override
public void start(Stage stage) throws Exception {
StartScreen startScreen = new StartScreen();
StackPane root = startScreen.getRoot();
Scene scene = new Scene(root, 900, 700);

StartScreenController controller = new StartScreenController(startScreen);
Scene scene = new Scene(startScreen.getRoot(), 900, 700);

stage.setTitle("Millions");
stage.setScene(scene);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package edu.ntnu.idi.idatt2003.gruppe42.Model;

public enum Difficulty {
EASY,
MEDIUM,
HARD
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@

import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

import java.util.Objects;

public class StartScreen {

private final TextField usernameField = new TextField();
private final Button loginButton = new Button("Login");
private final ToggleGroup startingMoneyGroup = new ToggleGroup();


public StackPane getRoot() {
// Root

StackPane root = new StackPane();

// Main content
Expand All @@ -33,16 +42,35 @@ public StackPane getRoot() {
inputContent.setMaxWidth(400);

Label usernameLabel = new Label("State your name, G");
TextField usernameField = new TextField();
usernameField.setPromptText("e.g. TateMindset99");
Label startingMoneyLabel = new Label("How much matrix money?");
TextField startingMoneyField = new TextField();
Button loginButton = new Button("Login");
VBox startingMoneyOptions = new VBox();
startingMoneyOptions.setAlignment(Pos.CENTER);

RadioButton easyCheck = new RadioButton("Easy (1K$ - Stone hard cash!)");
RadioButton mediumCheck = new RadioButton("Medium (100$ - cold bucks)");
RadioButton hardCheck = new RadioButton("Hard (0$ - im no nepo-baby)");

easyCheck.setToggleGroup(startingMoneyGroup);
mediumCheck.setToggleGroup(startingMoneyGroup);
hardCheck.setToggleGroup(startingMoneyGroup);
startingMoneyOptions.getChildren().addAll(easyCheck, mediumCheck, hardCheck);

// Set children
inputContent.getChildren().addAll(usernameLabel, usernameField, startingMoneyLabel, startingMoneyField);
inputContent.getChildren().addAll(usernameLabel, usernameField, startingMoneyLabel, startingMoneyOptions);
content.getChildren().addAll(logoView, inputContent, loginButton);
root.getChildren().add(content);

return root;
}
public TextField getUsernameField() {
return usernameField;
}
public String getSelectedMode() {
RadioButton selectedMode = (RadioButton) startingMoneyGroup.getSelectedToggle();
return selectedMode.getText();
}
public Button getLoginButton() {
return loginButton;
}
}