-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from einaskoi/per/investorController
add startScreen with username textbox and radio buttons on difficulty
- Loading branch information
Showing
4 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/StartScreenController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| }; | ||
| } | ||
|
|
||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Difficulty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters