-
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.
- Loading branch information
martin
committed
Apr 22, 2026
1 parent
b5adc64
commit 2c0a768
Showing
4 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
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
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,25 @@ | ||
| package millions; | ||
|
|
||
| import javafx.application.Application; | ||
| import javafx.scene.Scene; | ||
| import javafx.stage.Stage; | ||
| import millions.controller.GameController; | ||
| import millions.view.StartView; | ||
|
|
||
| public class App extends Application { | ||
|
|
||
| @Override | ||
| public void start(Stage stage) { | ||
| GameController controller = new GameController(); | ||
| StartView startView = new StartView(stage); | ||
|
|
||
| Scene scene = new Scene(startView, 400, 350); | ||
| stage.setTitle("Millions"); | ||
| stage.setScene(scene); | ||
| stage.show(); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| launch(args); | ||
| } | ||
| } |
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,33 @@ | ||
| package millions.controller; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.nio.file.Path; | ||
| import java.util.List; | ||
| import millions.controller.fileIO.CSVStockFileParser; | ||
| import millions.controller.fileIO.StockFileReader; | ||
| import millions.model.Exchange; | ||
| import millions.model.Player; | ||
| import millions.model.Stock; | ||
|
|
||
| public class GameController { | ||
| private Player player; | ||
| private Exchange exchange; | ||
|
|
||
| public void startGame(String name, BigDecimal startingMoney, Path stockFilePath) { | ||
| StockFileReader reader = new StockFileReader(stockFilePath); | ||
| List<String> lines = reader.readFile(); | ||
| CSVStockFileParser parser = new CSVStockFileParser(lines); | ||
| List<Stock> stocks = parser.parse(); | ||
|
|
||
| player = new Player(name, startingMoney); | ||
| exchange = new Exchange("Exchange", stocks); | ||
| } | ||
|
|
||
| public Player getPlayer() { | ||
| return player; | ||
| } | ||
|
|
||
| public Exchange getExchange() { | ||
| return exchange; | ||
| } | ||
| } |
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,94 @@ | ||
| package millions.view; | ||
|
|
||
| import java.io.File; | ||
| import javafx.geometry.Insets; | ||
| import javafx.geometry.Pos; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.control.TextField; | ||
| import javafx.scene.layout.VBox; | ||
| import javafx.stage.FileChooser; | ||
| import javafx.stage.Stage; | ||
|
|
||
| public class StartView extends VBox { | ||
|
|
||
| private TextField nameField; | ||
| private TextField startingAmountField; | ||
| private File selectedFile; | ||
| private Button filepickerButton; | ||
| private Button startButton; | ||
|
|
||
| public StartView(Stage stage) { | ||
| setAlignment(Pos.CENTER); | ||
| setSpacing(12); | ||
| setPadding(new Insets(40)); | ||
|
|
||
| nameField = new TextField(); | ||
| nameField.setPromptText("Player name:"); | ||
| nameField.setMaxWidth(250); | ||
| nameField.textProperty().addListener((obs, oldVal, newVal) -> checkStartButtonValid()); | ||
|
|
||
| startingAmountField = new TextField(); | ||
| startingAmountField.setPromptText("Starting amount:"); | ||
| startingAmountField.setMaxWidth(250); | ||
| startingAmountField | ||
| .textProperty() | ||
| .addListener((obs, oldVal, newVal) -> checkStartButtonValid()); | ||
|
|
||
| filepickerButton = new Button(); | ||
| filepickerButton.setText("Pick file"); | ||
| filepickerButton.setMaxWidth(250); | ||
| filepickerButton.setOnAction( | ||
| e -> { | ||
| FileChooser chooser = new FileChooser(); | ||
| chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("CSV files", "*.csv")); | ||
| chooser.setTitle("Select stock CSV file"); | ||
| File file = chooser.showOpenDialog(stage); | ||
|
|
||
| if (file != null) { | ||
| selectedFile = file; | ||
| filepickerButton.setText(file.getName()); | ||
| } | ||
| }); | ||
|
|
||
| startButton = new Button("Start game"); | ||
| startButton.setDisable(true); | ||
|
|
||
| Label title = new Label("Millions"); | ||
| title.setStyle("-fx-font-size: 32px; -fx-font-weight: bold;"); | ||
|
|
||
| getChildren().addAll(title, nameField, startingAmountField, filepickerButton, startButton); | ||
| } | ||
|
|
||
| private void checkStartButtonValid() { | ||
| boolean valid = true; | ||
|
|
||
| if (nameField.getText().isBlank()) { | ||
| valid = false; | ||
| } | ||
|
|
||
| try { | ||
| Integer.valueOf(startingAmountField.getText()); | ||
| } catch (NumberFormatException e) { | ||
| valid = false; | ||
| } | ||
|
|
||
| startButton.setDisable(!valid); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return nameField.getText(); | ||
| } | ||
|
|
||
| public String getStartingAmount() { | ||
| return startingAmountField.getText(); | ||
| } | ||
|
|
||
| public File getSelectedFile() { | ||
| return selectedFile; | ||
| } | ||
|
|
||
| public Button getStartButton() { | ||
| return startButton; | ||
| } | ||
| } |